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...
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.
Read three integers from user input.
Read three integers from user input.
Write a program read in data from the standard input stream (cin) representing temperature in Fahrenheit....
Write a program read in data from the standard input stream (cin) representing temperature in Fahrenheit. The program will then convert the values into Kelvin (using 5/9 (Fº-32) to convert to Celsius and a difference of 273.15 between Celsius and Kelvin) and print out the new total value. Convert temperature in Fahrenheit to Kelvin : Enter temperature in Fahrenheit: 80.33 The temperature in Kelvin is: 300 Write a second program which then does the reverse conversion (using a difference of...
Write a C++ or Java program that reads an input graph data from a user. Then,...
Write a C++ or Java program that reads an input graph data from a user. Then, it should present a path for the travelling salesman problem (TSP). In the assignment, you can assume that the maximum number ofvertices in the input graph is less than or equal to 20. Input format: This is a sample input from a user. 4 12 0 1 2 0 3 7 0 2 5 1 0 2 1 2 8 1 3 3 2...
In Python Write a function to read a Sudoku board from an input string. The input...
In Python Write a function to read a Sudoku board from an input string. The input string must be exactly 81 characters long (plus the terminating null that marks the end of the string) and contains digits and dots (the `.` character represents an unmarked position). The input contains all 9 rows packed together. For example, a Sudoku board that looks like this: ``` ..7 ... ... 6.4 ... ..3 ... .54 ..2 ... .4. ... 9.. ... ..5 385...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT