Question

Program in C Language : Define a struct computerType to store the following data about a...

Program in C Language :

Define a struct computerType to store the following data about a computer: Manufacturer (50 character string), model type (50 character string), processor type (10 character string), ram (int) in GB, hard drive size (int) in GB, year when the computer was built (int), and the price (double).

Write a program that declares a variable of type computerType, prompts the user to the input data for the struct, and then outputs all the computer's data from the struct.

For Example:

Enter the name of the manufacturer: Dell
Enter the model of the computer: Inspiron
Enter processor type: I7 387
Enter the size of RAM (in GB): 32
Enter the size of hard drive (in GB): 512
Enter the year the computer was built: 1990
Enter the price: 1345.67

--------------------
Manufacturer: Dell
Model: Inspiron
Processor: I7 387
Ram: 32
Hard Drive Size: 512
Year Built: 1990
Price: $1345.67
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program screenshots:

// Declare the necessary header files. #include <stdio.h> // Declare the structure struct computerType { // Declare variables

printf(Enter the size of hard drive (in GB): ); scanf(%d, &(computer_Type.harddrive)); printf(Enter the year the compute

Sample Output:

Enter the name of the manufacturer: Dell Enter the model of the computer: Inspiron Enter processor type: 17 387 Enter the siz

Code to copy:

// Declare the necessary header files.

#include <stdio.h>

// Declare the structure

struct computerType {

// Declare variables.

char manufacturer[50];

char model[50];

char processor[10];

int ram;

int hardDrive;

int year;

double price;

};

// Start the main function.

int main() {

struct computerType computer_Type;

// Prompt the user to enter details.

printf("Enter the name of the manufacturer: ");

fgets(computer_Type.manufacturer, 50, stdin);

printf("Enter the model of the computer: ");

fgets(computer_Type.model, 50, stdin);

printf("Enter processor type: ");

fgets(computer_Type.processor, 10, stdin);

printf("Enter the size of RAM (in GB): ");

scanf("%d", &(computer_Type.ram));

printf("Enter the size of hard drive (in GB): ");

scanf("%d", &(computer_Type.hardDrive));

printf("Enter the year the computer was built: ");

scanf("%d", &(computer_Type.year));

printf("Enter the price: ");

scanf("%lf", &(computer_Type.price));

printf("\n--------------------\n");

// Display the result on console.

printf("Manufacturer: %s", computer_Type.manufacturer);

printf("Model: %s", computer_Type.model);

printf("Processor: %s", computer_Type.processor);

printf("Ram: %d\n", computer_Type.ram);

printf("Hard Drive Size: %d\n", computer_Type.hardDrive);

printf("Year Built: %d\n", computer_Type.year);

printf("Price: $%.2lf\n", computer_Type.price);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Program in C Language : Define a struct computerType to store the following data about a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a C++ program using classes, friend functions and overloaded operators. Computer class: Design a computer...

    write a C++ program using classes, friend functions and overloaded operators. Computer class: Design a computer class (Computer) that describes a computer object. A computer has the following properties: Amount of Ram in GB (examples: 8, 16), defaults to 8. Hard drive size in GB (examples: 500, 1000), defaults to 500. Speed in GHz (examples: 1.6, 2.4), defaults to 1.6. Type (laptop, desktop), defaults to "desktop" Provide the following functions for the class: A default constructor (constructor with no parameters)...

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are two parts for one code (one question) the two parts branch off, one part has 2 sheets of code, the other has 3 sheets of code, all are small code segments for one question. Pt.1 - 2 sheets of code: public class Computer { private String make; private String type; private String modelNumber; private double cpuSpeed_GHz; private int ramSize_GB; private int hardDriveSize_GB; private...

  • Write a program (C++) that shows Game sales. The program should use a structure to store...

    Write a program (C++) that shows Game sales. The program should use a structure to store the following data about the Game sale: Game company Type of Game (Action, Adventure, Sports etc.) Year of Sale Sale Price The program should use an array of at least 3 structures (3 variables of the same structure). It should let the user enter data into the array, change the contents of any element and display the data stored in the array. The program...

  • write a program that defines two different structures as follows: 1) A cPu structure that contains...

    write a program that defines two different structures as follows: 1) A cPu structure that contains a manufacturers Name (string), a model number (int), a speed (float), and a price (float). a model number (int), 2) A Motherboard structure that contains a manufacturer's ID (int), and a price (float). Your program use arrays of each type of structure. All arrays wi contain a total of five will structures. Your program will also read in two separate files. You can obtain...

  • # No plagiarism #Decide on the type of motherboard to use in the computer system you...

    # No plagiarism #Decide on the type of motherboard to use in the computer system you are designing. Explain what it is and why you chose it. This from Lab 5.1 Using the information you recorded previously in Step 5, consult Table 5-1 to find out how to enter your system’s setup utility. (Alternatively, when you first turn on your PC, look for a message on your screen, which might read something like “Press F2 to access setup.” Table 5-1:...

  • [C++] Outline: The movie data is read from a file into an array of structs and...

    [C++] Outline: The movie data is read from a file into an array of structs and is sorted using the Selection Sort method and the search is done using the Binary Search algorithm with the year of release as key. This assignment upgrades to an array of pointers to the database elements and converts the Selection Sort and Binary search procedure on the database to selection sort and binary search on the array of pointers to the database.   Requirements: Your...

  • Please help we are suppose to explain what the C code does. This is the electronics database (6 pts) This problem is...

    Please help we are suppose to explain what the C code does. This is the electronics database (6 pts) This problem is based on Electronics database. Add some annotations to the following table to explain what the C program is doing in detail. Note that "void" is how C declares a function that does not return anything. You are expected to generalize or research svntaxes not mentioned in the lecture C Program Annotation void newPCproduct EXEC SQL BEGIN DECLARE SECTION;...

  • Write a C++ program that asks for the following information about a book order from the...

    Write a C++ program that asks for the following information about a book order from the console: • Title • Author • ISBN (hint: careful about what data type to use - validate 9 or 13 characters) • Price (validate number < 400) • Quantity (number of books to purchase – validate > 0 and < 100) • Fiction/Non-Fiction (‘N’ or ‘F’ - validate) • Genre (‘R’ romance, ‘D’ drama, ‘M’ mystery – validate) Make use of the following data...

  • In C++ Programming Write a program in Restaurant.cpp to help a local restaurant automate its breakfast...

    In C++ Programming Write a program in Restaurant.cpp to help a local restaurant automate its breakfast billing system. The program should do the following: Show the customer the different breakfast items offered by the restaurant. Allow the customer to select more than one item from the menu. Calculate and print the bill. Assume that the restaurant offers the following breakfast items (the price of each item is shown to the right of the item): Name Price Egg (cooked to order)...

  • I need to complete the C++ program for hotel reservation. In the main cpp you have...

    I need to complete the C++ program for hotel reservation. In the main cpp you have to display the hotel information from the hotel.txt based on customer preferences(which can be taken from the User.txt) For example, if the customer's budget is 200$, then only the hotels with prices below that amount should be displayed. Then the user has an option to choose which one to reserve for the particular time(which also can be found in the user.txt) The last two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT