I need help with the following c program:
(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt)

Examples of strings that can be accepted:
Jill, Allen
Jill , Allen
Jill,Allen

Ex:

Enter input string:
Jill, Allen


(2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts)

Ex:

Enter input string:
Jill Allen
Error: No comma in string.

Enter input string:
Jill, Allen


(3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. (2 pts)

Ex:

Enter input string:
Jill, Allen
First word: Jill
Second word: Allen


(4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. (2 pts)

Ex:

Enter input string:
Jill, Allen
First word: Jill
Second word: Allen

Enter input string:
Golden , Monkey
First word: Golden
Second word: Monkey

Enter input string:
Washington,DC
First word: Washington
Second word: DC

Enter input string:
q

Answers

Answer 1

The code for the following requirements is mentioned below.

Describe C programming?

C is a procedural programming language that was originally developed by Dennis Ritchie in the 1970s at Bell Labs. It is a general-purpose language that can be used for a wide range of applications, from low-level system programming to high-level application programming.

C is a compiled language, which means that source code is translated into machine code by a compiler before it is executed. This makes C programs fast and efficient, and allows them to run on a wide variety of platforms.

C provides a rich set of built-in data types and operators, including integers, floating-point numbers, characters, and arrays. It also supports control structures such as if-else statements, loops, and switch statements, which allow programmers to write complex logic and control the flow of their programs.

Here's the C program that fulfills the requirements:

#include <stdio.h>

#include <string.h>

int main() {

   char input[100], word1[50], word2[50];

   char *token;

   while (1) {

       printf("Enter input string:\n");

       fgets(input, sizeof(input), stdin);

       // Check if user wants to quit

       if (input[0] == 'q') {

           break;

       }

       // Check if input contains a comma

       if (strchr(input, ',') == NULL) {

           printf("Error: No comma in string.\n");

           continue;

       }

       // Extract words from input and remove spaces

       token = strtok(input, ",");

       strcpy(word1, token);

       token = strtok(NULL, ",");

       strcpy(word2, token);

       // Remove leading and trailing spaces from words

       int i, j;

       i = 0;

       while (word1[i] == ' ') {

           i++;

       }

       j = strlen(word1) - 1;

       while (word1[j] == ' ' || word1[j] == '\n') {

           j--;

       }

       word1[j + 1] = '\0';

       memmove(word1, word1 + i, j - i + 2);

       i = 0;

       while (word2[i] == ' ') {

           i++;

       }

       j = strlen(word2) - 1;

       while (word2[j] == ' ' || word2[j] == '\n') {

           j--;

       }

       word2[j + 1] = '\0';

       memmove(word2, word2 + i, j - i + 2);

       // Output words

       printf("First word: %s\n", word1);

       printf("Second word: %s\n", word2);

   }

   return 0;

}

Explanation:

We use the fgets() function to read input from the user, which allows us to handle input with spaces. We store the input in the input array.We use the strchr() function to check if the input contains a comma. If not, we output an error message and continue to the next iteration of the loop.We use the strtok() function to extract the two words from the input. We store each word in a separate variable (word1 and word2). We then use a loop to remove any leading or trailing spaces from each word.We use a while loop to prompt the user for input until they enter "q" to quit.

To know more about function visit:

https://brainly.com/question/13733551

#SPJ9


Related Questions

Homework 1 Computer Vision (Term 3 2022-23) The purpose of this homework is to write an image filtering function to apply on input images. Image filtering (or convolution) is a fundamental image processing tool to modify the image with some smoothing or sharpening affect. You will be writing your own function to implement image filtering from scratch. More specifically, you will implement filter( ) function should conform to the following: (1) support grayscale images, (2) support arbitrarily shaped filters where both dimensions are odd (e.g., 3 × 3 filters, 5 × 5 filters), (3) pad the input image with the same pixels as in the outer row and columns, and (4) return a filtered image which is the same resolution as the input image. You should read a color image and then convert it to grayscale. Then define different types of smoothing and sharpening filters such as box, sobel, etc. Before you apply the filter on the image matrix, apply padding operation on the image so that after filtering, the output filtered image resolution remains the same. (Please refer to the end the basic image processing notebook file that you used for first two labs to see how you can pad an image) Then you should use nested loops (two for loops for row and column) for filtering operation by matrix multiplication and addition (using image window and filter). Once filtering is completed, display the filtered image. Please use any image for experiment. Submission You should submit (using Blackboard link) the source file which includes the code (Jupiter notebook) and a report containing different filters and corresponding filtered images. Deadline: May 11th, Thursday, End of the day.

Answers

Here is information on image filtering in spatial and frequency domains.

Image filtering in the spatial domain involves applying a filter mask to an image in the time domain to obtain a filtered image. The filter mask or kernel is a small matrix used to modify the pixel values in the image. Common types of filters include the Box filter, Gaussian filter, and Sobel filter.

To apply image filtering in the spatial domain, one can follow the steps mentioned in the prompt, such as converting the image to grayscale, defining a filter, padding the image, and using nested loops to apply the filter.

Both spatial and frequency domain filtering can be used for various image processing tasks such as noise reduction, edge detection, and image enhancement.

Learn more about frequency domain at:

brainly.com/question/14680642

#SPJ1

Who can prevent unauthorized users from accessing data resources and how?
A
can prevent unauthorized users from accessing data resources with the help of
that filter traffic.

Answers

Answer: TRUE

Explanation:

The main goals of system security are to deny access to legitimate users of technology, to prevent legitimate users from gaining access to technology, and to allow legitimate users to use resources in a proper manner. As a result, the following assertion regarding access control system security is accurate.

In this lab, you use what you have learned about searching an array to find an exact match to complete a partially prewritten C++ program. The program uses an array that contains valid names for 10 cities in Michigan. You ask the user to enter a city name; your program then searches the array for that city name. If it is not found, the program should print a message that informs the user the city name is not found in the list of valid cities in Michigan.

The file provided for this lab includes the input statements and the necessary variable declarations. You need to use a loop to examine all the items in the array and test for a match. You also need to set a flag if there is a match and then test the flag variable to determine if you should print the the Not a city in Michigan. message. Comments in the code tell you where to write your statements. You can use the previous Mail Order program as a guide.

Instructions
Ensure the provided code file named MichiganCities.cpp is open.
Study the prewritten code to make sure you understand it.
Write a loop statement that examines the names of cities stored in the array.
Write code that tests for a match.
Write code that, when appropriate, prints the message Not a city in Michigan..
Execute the program by clicking the Run button at the bottom of the screen. Use the following as input:
Chicago
Brooklyn
Watervliet
Acme

Answers

Based on your instructions, I assume the array containing the valid names for 10 cities in Michigan is named michigan_cities, and the user input for the city name is stored in a string variable named city_name.

Here's the completed program:

#include <iostream>

#include <string>

int main() {

   std::string michigan_cities[10] = {"Ann Arbor", "Detroit", "Flint", "Grand Rapids", "Kalamazoo", "Lansing", "Muskegon", "Saginaw", "Traverse City", "Warren"};

   std::string city_name;

   bool found = false;  // flag variable to indicate if a match is found

   std::cout << "Enter a city name: ";

   std::getline(std::cin, city_name);

   for (int i = 0; i < 10; i++) {

       if (city_name == michigan_cities[i]) {

           found = true;

           break;

       }

   }

   if (found) {

       std::cout << city_name << " is a city in Michigan." << std::endl;

   } else {

       std::cout << city_name << " is not a city in Michigan." << std::endl;

   }

   return 0;

}

In the loop, we compare each element of the michigan_cities array with the user input city_name using the equality operator ==. If a match is found, we set the found flag to true and break out of the loop.

After the loop, we use the flag variable to determine whether the city name was found in the array. If it was found, we print a message saying so. If it was not found, we print a message saying it's not a city in Michigan.

When the program is executed with the given input, the output should be:

Enter a city name: Chicago

Chicago is not a city in Michigan.

Enter a city name: Brooklyn

Brooklyn is not a city in Michigan.

Enter a city name: Watervliet

Watervliet is a city in Michigan.

Enter a city name: Acme

Acme is not a city in Michigan.

Read more about programs here:

https://brainly.com/question/26134656

#SPJ1

Any one can drew for me case study for booking appointment system with all actor and system please

Answers

Answer:

Case Study: Booking Appointment System for a Medical Clinic

Background:

A medical clinic needs a booking appointment system to manage their patient appointments. They currently have a manual system where patients call to book their appointments, and staff manually enter the appointment details into a paper-based calendar. This process is time-consuming and prone to errors, leading to missed appointments and patient dissatisfaction.

Objectives:

The booking appointment system aims to provide an efficient and convenient way for patients to book appointments while reducing the workload of clinic staff. The system should allow patients to book appointments online, view available appointment slots, and receive confirmation and reminders of their appointments. It should also allow staff to manage appointments, view patient information, and generate reports on appointment history.

Actors:

Patient: a person who needs to book an appointment with the medical clinic.

Clinic Staff: a person who manages the appointments, views patient information, and generates reports.

Use Cases:

Book Appointment: The patient logs into the booking appointment system, selects a preferred date and time, and provides their personal and medical information. The system confirms the appointment and sends a confirmation email to the patient and staff.

View Available Slots: The patient can view available appointment slots on the system calendar and select a preferred date and time.

Cancel Appointment: The patient can cancel a booked appointment through the system, and the system sends a cancellation confirmation email to the patient and staff.

Modify Appointment: The patient can modify a booked appointment through the system by selecting a new date and time, and the system sends a modification confirmation email to the patient and staff.

View Patient Information: The staff can view the patient's personal and medical information, appointment history, and any notes added by other staff members.

Generate Reports: The staff can generate reports on appointment history, patient demographics, and revenue.

System:

The booking appointment system consists of a web application with a database to store patient information and appointment details. The system uses a calendar view to display available appointment slots and booked appointments. The system sends confirmation, reminder, cancellation, and modification emails to patients and staff using an email service provider. The system also integrates with the clinic's electronic health record system to retrieve and store patient information.

Conclusion:

Implementing a booking appointment system for a medical clinic can improve the patient experience, reduce staff workload, and increase efficiency. By providing a convenient online booking system, patients can book, modify, or cancel appointments at their convenience, reducing the workload of staff. The system can also generate reports to help staff analyze patient data, appointment history, and revenue.

Explanation:

Describe the use of one of the following protocols: FTP, HTTP, HTTPS ,SMTP and SFTP. Which one considers as a security protocol?

Answers

SMTP is a communication protocol used for sending and receiving email messages over the internet. While SMTP itself is not primarily a security protocol, it can be used in conjunction with other security protocols such as SSL/TLS encryption to provide secure email communication. When used with SSL/TLS encryption, SMTP is commonly referred to as SMTPS.

Python Yahtzee:


Yahtzee is a dice game that uses five die. There are multiple scoring abilities with the highest being a Yahtzee where all five die are the same. You will simulate rolling five die 777 times while looking for a yahtzee.


Program Specifications :


Create a list that holds the values of your five die.


Populate the list with five random numbers between 1 & 6, the values on a die.


Create a function to see if all five values in the list are the same and IF they are, print the phrase "You rolled ##### and its a Yahtzee!" (note: ##### will be replaced with the values in the list)


Create a loop that completes the process 777 times, simulating you rolling the 5 die 777 times, checking for Yahtzee, and printing the statement above when a Yahtzee is rolled.

Answers

The program to simulate rolling five dice 777 times and checking for a Yahtzee is given below.

How to write the program

import random

def check_yahtzee(dice):

   """Check if all five dice have the same value"""

   return all(dice[i] == dice[0] for i in range(1, 5))

for i in range(777):

   # Roll the dice

   dice = [random.randint(1, 6) for _ in range(5)]

   # Check for Yahtzee

   if check_yahtzee(dice):

       print("You rolled {} and it's a Yahtzee!".format(dice))

In conclusion, this is the program to simulate rolling five dice 777 times and checking for a Yahtzee.

Learn more about program on

https://brainly.com/question/26642771

#SPJ1

A blank provides power to a hydraulic system by pumping oil from a reservoir into the supply lines

Answers

In a hydraulic system a reservoir baffle prevents the hydraulic oil from moving directly from the system return line to the pump suction line.

It should be understood that a hydraulic system simply means a mechanical function that operates through the force of liquid pressure.

In this case, in a hydraulic system a reservoir baffle prevents the hydraulic oil from moving directly from the system return line to the pump suction line.

Learn more about hydraulic system on:

brainly.com/question/1176062

#SPJ1

which ine if these is a subtractive theory

Answers

Answer: b I think please correct me if I'm wrong

Explanation:

There is a limit of 15 slides that PowerPoint will allow you to have for any presentation:
O True
O False

Answers

False, on PowerPoint there is no limit of slides but there is a limit of storage before upgrading

Fill in the blank: Most vendors or computer hardware manufacturers will assign a special string of characters to their devices called a _____.

Answers

Answer:

hardware ID number

Explanation:

Other Questions
What is the amount of energy called from the reactants to the top of the curve?a. Total heat energyb. Catalyst energyc. Decomposition energyd. Activation energy Ben's Barbershop has a rectangular logo for their measuresb 7 1/5 feet long with an area that is exactly the maximum area allowed by thr building owner. Create an equation that could be used to determine M, the unknown side length of the logo 37% of 42 is equal to 74% of what number? Countercyclical discretionary fiscal policy calls for:. What is volume? a. How close particles are stuck together b. The amount of space occupied by matter c. The amount of particles in any given object d. The weight of an object Please select the best answer from the choices provided which value represents a percentage between 11% and 17% March 1, 2020, Dorchester Company's beginning work in process inventory had 6,000 units. This is its only production department. Beginning WIP units were 50% complete as to conversion costs. Dorchester introduces direct materials at the beginning of the production process. During March, all beginning WIP was completed and an additional 24,500 units were started and completed. Dorchester also started but did not complete 6,500 units. These units remained in ending WIP inventory and were 50% complete as to conversion costs. Dorchester uses the weighted-average method. Use this information to determine for March 2020 the equivalent units of production for conversion costs. Round to whole number (no cents) Same increased the amount of protein she eats every day 45g to 58. 5g. By what percentage did Sam increase the amount of protein she eats HELENA: How happy some o'er other some can be!Through Athens I am thought as fair as sheBut what of that? Demetrius thinks not so;He will not know what all but he do know.And as he errs, doting on Hermia's eyes,So I, admiring of his qualities:Things base and vile, folding no quantity,Love can transpose to form and dignity:Love looks not with the eyes, but with the mind;And therefore is wing'd Cupid painted blind:Nor hath Love's mind of any judgement taste,Wings and no eyes figure unheedy haste:And therefore is Love said to be a child,Because in choice he is so oft beguiled.As wagg ish boys in game themselves forswear,So the boy Love is perjured every where:For ere Demetrius look'd on Hermia's eyne,He hail'd down oaths that he was only mine;And when this hail some heat from Hermia felt,So he dissolved, and showers of oaths did melt (1,4, 232-251).Line 9 contains an example ofA.) Onomatopoeia B.) Metaphor C.) Simile D.) Personification Ms. Redmon gave her theater students an assignment to memorize a dramatic monologue to present to the rest of the class. The graph shows the times, rounded to the nearest half minute, of the first 10 monologues presented.A number line going from 0.5 to 5. 0 dots are above 0.5 0 dots are above 1. 2 dots area above 1.5. 1 dot is above 2. 3 dots are above 2.5. 1 dot is above 3. 2 dots are above 3.5. 1 dot is above 4. 0 dots are above 2.5. 0 dots are above 5. The next student presents a monologue that is about 0.5 minutes long. What effect will this have on the graph?The median will decrease.The mean will decrease.The median will increase.The mean will increase. Which is one reason scientists produce transgenic organisms?. PLEASE HELP I NEED TO PASS THIS Using the probability distribution represented by the graphbelow, find the probability that the random variable, X, fallsin the shaded region. Use the slope of a line formula to find the slope of the following points: (3, 9) and (8, 15) write a summary of the essay sleep aids are yet another examples of problematic OTC's. the inability to sleep or stay awake is a distressing for many People.nevertheless instead of studying their own habits to make efforts to solve the problem naturally There's a question I've been trying for 2 days to get solved but either I'm missing something or maybe I haven't been using the right method but I hope someone will help me here. ________________________________________Substitution, Manipulation, EliminationSolve Simultaneously. Use the method you find easiest. (title of the question)________________________________________4x-3y=115x-9y=-2 Why can the fashion industry potentially be viewed as an unreliable source of employment. HELP PLS 25 PTS GIVE EXPLANATION ON ANSWER PLSA 25-foot magazine rack begins 20 feet south of the checkout desk and continues south. What are the coordinates of the beginning and end of the magazine rack? Explain or show how you got your answer. ANSWER CORRECTLY WITH AN EXPLANATION The president of the student council wants to survey the student population about parking. She decides to use arandom number table to take a random sample of 100 of the 1,020 students at the school. What is the smallest numberof digits that should be used to label the population? Here is the income statement for Teal Mountain Inc. TEAL MOUNTAIN INC. Income StatementFor the Year Ended December 31, 2022Sales revenue$431,600Cost of goods sold234,300Gross profit197,300Expenses (including $16,200 interest and $22,500 income taxes)75,200Net income$ 122,100Additional information:1. Common stock outstanding January 1, 2022, was 26,700 shares, and 36,000 shares were outstanding at December 31, 2022. 2. The market price of Teal Mountain stock was $13 in 2022. 3. Cash dividends of $24,200 were paid, $6,600 of which were to preferred stockholders. Compute the following measures for 2022. (Round all answers to 2 decimal places, e. G. 1. 83 or 2. 51%)(a) Earnings per share $enter earnings per share in dollars (b) Price-earnings ratio enter price-earnings ratio in times times(c) Payout ratio enter payout ratio in percentages %(d) Times interest earned enter times interest earned times What is Isha planning to do