Question

In: Computer Science

C Assign Barbecue's data member caloriesInSlice with a value read from input. Then, assign Ham and...

C

Assign Barbecue's data member caloriesInSlice with a value read from input. Then, assign Ham and Cheese's data member caloriesInSlice with another value read from input. Input will contain two integer numbers.

#include <stdio.h>
#include <string.h>

typedef struct Pizza_struct {
char pizzaName[75];
int caloriesPerSlice;
} Pizza;

int main(void) {
Pizza pizzasList[2];

strcpy(pizzasList[0].pizzaName, "Barbecue");
strcpy(pizzasList[1].pizzaName, "Ham and Cheese");

/* Your code goes here */

printf("A %s slice contains %d calories.\n", pizzasList[0].pizzaName, pizzasList[0].caloriesPerSlice);
printf("A %s slice contains %d calories.\n", pizzasList[1].pizzaName, pizzasList[1].caloriesPerSlice);

return 0;
}

Solutions

Expert Solution

As per the given question, we are required to get two integers number which are pizzaList structure caloriesPerSlice values and assign appropriately.

Scan both the integers values and assign it to it's appropriate structure array values.

Scan the first integer value and store it in the pizzaList array of structure at it's caloriesPerSlice as shown below:

scanf("%d", &pizzaList[0].caloriesPerSlice);

Scan the second integer value and store it in the pizzaList array of structure at it's caloriesPerSlice as shown below:

scanf("%d", &pizzaList[1].caloriesPerSlice);

/* Final code*/

include <stdio.h>

#include <string.h>

typedef struct Pizza_struct {

char pizzaName[75];

int caloriesPerSlice;

} Pizza;

int main(void) {

Pizza pizzasList[2];

strcpy(pizzasList[0].pizzaName, "Barbecue");

strcpy(pizzasList[1].pizzaName, "Ham and Cheese");

scanf("%d", &pizzaList[0].caloriesPerSlice);

scanf("%d", &pizzaList[1].caloriesPerSlice);

printf("A %s slice contains %d calories.\n", pizzasList[0].pizzaName, pizzasList[0].caloriesPerSlice);

printf("A %s slice contains %d calories.\n", pizzasList[1].pizzaName, pizzasList[1].caloriesPerSlice);

return 0;

}


Related Solutions

Implement an application that will read data from an input file, interpret the data, and generate...
Implement an application that will read data from an input file, interpret the data, and generate the output to the screen. - The application will have two classes, Rectangle and Lab2ADriver. - Name your Eclipse project, Lab2A. Implement the Rectangle class with the following description. Rectangle Data fields -numRows: int -numCols: int -filled: Boolean Store the number of rows in the Rectangle Store the number of columns in the Rectangle Will define either a filled or unfilled rectangle True =...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the...
Write a C++ program that takes two sets ’A’ and ’B’ as input read from the file prog1 input.txt. The first line of the file corresponds to the set ’A’ and the second line is the set ’B’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The output should be written in the...
Program this using C please The program will read from standard input two things - a...
Program this using C please The program will read from standard input two things - a string str1 on the first line of stdin (this string may be an empty string) - a string str2 on the second line of stdin (this string may be an empty string) Note that stdin does not end with '\n'. The program will output a string that is the concatenation of string str1 and string str2 such that any lower-case alphabet character (a-z) will...
in c++ QUESTION 4: Write the code to do the following: -read input from the keyboard...
in c++ QUESTION 4: Write the code to do the following: -read input from the keyboard by displaying the message on the screen to ask and read the following information: * customer ID (string) * customer name (string)                                                        * balance (float) -open output file customer .txt to write -Write to the output file customer.txt the following information:                 Customer ID – customer name – balance For example: 1561175753 - James Smith – 1255.25 -close file QUESTION 5: -create one notepad...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file...
Write a program that takes three sets ’A’, ’B’, ’C’ as input read from the file prog2 input.txt. The first line of the file corresponds to the set ’A’, the second line is the set ’B’, and the third line is the set ’C’. Every element of each set is a character, and the characters are separated by space. Implement algorithms for the following operations on the sets. Each of these algorithms must be in separate methods or subroutines. The...
C++ Read first a user's given name followed by the user's age from standard input. Then...
C++ Read first a user's given name followed by the user's age from standard input. Then use an ofstream object named outdata (which you must declare) to write this information separated by a space into a file called outdata. Assume that this is the extent of the output that this program will do. Declare any variables that you need.
C++ Parse text (with delimiter) read from file. If a Text file has input formatted such...
C++ Parse text (with delimiter) read from file. If a Text file has input formatted such as: "name,23" on every line where a comma is the delimiter, how would I separate the string "name" and integer "23" and set them to separate variables for every input of the text file? I am trying to set a name and age to an object and insert it into a vector. #include <iostream> #include <vector> #include <fstream> using namespace std; class Student{    ...
C++ programming question Write a program that will read input from a text file called "theNumbers.txt"...
C++ programming question Write a program that will read input from a text file called "theNumbers.txt" (you will have to provide your own when debugging). The text file that is to be opened is formatted a certain way, namely, there is always one integer, one character (representing an operation), another integer, and then a new line character, with spaces between each item. A sample text file is provided below. theNumbers.txt 144 + 26 3 * 18 88 / 4 22...
Read three integers from user input.
Read three integers from user input.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT