Question

In: Computer Science

Define a struct computerType to store the following data about a computer: Manufacturer (50 character string),...

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

Solutions

Expert Solution

#include <stdio.h>

struct computerType {
    char manufacturer[50];
    char model[50];
    char processor[10];
    int ram;
    int hardDrive;
    int year;
    double price;
};

int main() {
    struct computerType ct;
    printf("Enter the name of the manufacturer: ");
    fgets(ct.manufacturer, 50, stdin);
    printf("Enter the model of the computer: ");
    fgets(ct.model, 50, stdin);
    printf("Enter processor type: ");
    fgets(ct.processor, 10, stdin);
    printf("Enter the size of RAM (in GB): ");
    scanf("%d", &(ct.ram));
    printf("Enter the size of hard drive (in GB): ");
    scanf("%d", &(ct.hardDrive));
    printf("Enter the year the computer was built: ");
    scanf("%d", &(ct.year));
    printf("Enter the price: ");
    scanf("%lf", &(ct.price));

    printf("\n--------------------\n");
    printf("Manufacturer: %s", ct.manufacturer);
    printf("Model: %s", ct.model);
    printf("Processor: %s", ct.processor);
    printf("Ram: %d\n", ct.ram);
    printf("Hard Drive Size: %d\n", ct.hardDrive);
    printf("Year Built: %d\n", ct.year);
    printf("Price: $%.2lf\n", ct.price);
    return 0;
}

Related Solutions

Create a typedef fruitType using the struct fruitType_struct to store the following data about a fruit:...
Create a typedef fruitType using the struct fruitType_struct to store the following data about a fruit: name (string, up to 50 characters long) color (string, up to 10 characters long) fat (integer) sugar (integer) carbohydrate (integer) Write a void function called printFruit that takes a fruitType parameter and prints the data (as shown in the example below). Declare a variable of type fruitType to store the following data: name: banana color: yellow fat: 1 sugar: 15 carbohydrate: 22 then use...
Write a program that declares a struct to store the data of a football player (player’s...
Write a program that declares a struct to store the data of a football player (player’s name, player’s position, number of touchdowns, number of catches, number of passing yards, number of receiving yards, and the number of rushing yards). Declare an array of 10 components to store the data of 10 football players. Your program must contain a function to input data and a function to output data. Add functions to search the array to find the index of a...
To store the information about a city and its weather forecast, create a struct that holds...
To store the information about a city and its weather forecast, create a struct that holds the city's name (string), population (int), and a forecast array storing 7 string elements representing the city's weather in the next 7 days. The program will then accept user input to enter the name and population of the city, then it accepts 7 string inputs to store into the forecast array. Then the program will output the city's name, population, and forecast data. Ex:...
A computer store compiled data about the accessories that 500 purchasers of new tablets bought at...
A computer store compiled data about the accessories that 500 purchasers of new tablets bought at the same time they bought the tablet. Here are the results: 411 bought cases 82 bought an extended warranty 100 bought a dock 57 bought both a dock and a warranty 65 both a case and a warranty 77 bought a case and a dock 48 bought all three accessories 58 bought none of the accessories Find the probability that a randomly selected customer...
C++ programming To store the information about a city and its weather forecast, create a struct...
C++ programming To store the information about a city and its weather forecast, create a struct that holds the city's name (string), population (int), and a forecast array storing 7 string elements representing the city's weather in the next 7 days. The program will then accept user input to enter the name and population of the city, then it accepts 7 string inputs to store into the forecast array. Then the program will output the city's name, population, and forecast...
Create a struct for the following groups of data: (a) Product Data with the following members...
Create a struct for the following groups of data: (a) Product Data with the following members • ID • Name • Price • Quantity (b) Customer Data with the following members • ID • Name • Address • E-mail (c) Sales Data with the following members • Customer ID • Product IDs • Sale amount • Choose the types that you think will work best for the above descriptions. • Names should have a maximum size of 50. • Physical...
convert this program that is for string into character input data #include "stdafx.h" #include <string.h> #include...
convert this program that is for string into character input data #include "stdafx.h" #include <string.h> #include <stdlib.h> unsigned int putIntoHashTable(char *ptrInputData, unsigned int bufferLength); // function to add to hash table unsigned int getFromHashTable(char *ptrOutputData, unsigned int bufferLength); // function to retrieve data from hash table #define INPUT_BUFFER_SIZE 200 // local buffer used for adding data to the hash table (there is no reason in this assignment to change this value) #define HASH_SIZE 100 // size of hash table to...
language c++(Data structure) You have to read a file and store a data in character array...
language c++(Data structure) You have to read a file and store a data in character array ( you cant initialize a character array, you have to code generically) code must be generic u must read a file onece u cant use built in function etc string, code in classes if u initialized a char array or ur code doesn't run i will dislike and report u you can use link list to store data
Using the following definitions for a binary tree, typedef struct bintreenode {     int data;     struct bintreenode*...
Using the following definitions for a binary tree, typedef struct bintreenode {     int data;     struct bintreenode* left;     struct bintreenode* right; } btreenode; // Used for a node in the queue. typedef struct node {     btreenode* nodePtr;     struct node* next; } node; // Used to represent the queue efficiently. typedef struct queue {     node* front;     node* back; } queue; Implement the following functions: void bfs(btreenode* root) // Prints a breadth first search traversal of the binary search tree rooted at root....
(C++ ONLY) You will define your own data type. It will be a struct called Fraction....
(C++ ONLY) You will define your own data type. It will be a struct called Fraction. The struct will have 2 integer fields: numerator and denominator. You will write a function called reduce that takes a Fraction as a parameter and returns that Fraction in its reduced form. For example, if the fraction 2/4 is passed to the function, the fraction 1/2 will be returned. Consider any fraction with a denominator of 1 to be in reduced form. You will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT