Assume the definition of Exercise 2, which defines the struct computerType. Write a program that declares a variable of type computerType, prompts the user to input data about a computer, and outputs the computer’s data.
Example input and output is shown below:
Enter the name of the manufacturer: McPC
Enter the model of the computer: 1000
Enter processor type: Intel GFX
Enter the size of RAM (in GB): 8
Enter the size of hard drive (in GB): 1000
Enter the year the computer was built: 2016
Enter the price: 1200
Manufacturer: McPC
Model: 1000
Processor: Intel GFX
Ram: 8
Hard Drive Size: 1000
Year Built: 2016
Price: $1200.00
Instructions from Exercise 2 have been posted below for your convenience.
Define a struct computerType to store the following data about a computer: Manufacturer (string), model type (string), processor type (string), ram (int) in GB, hard drive size (int) in GB, year when the computer was built (int), and the price (double).
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct computerType
{
  string manufacturer;
  string modelType;
  string processorType;
  int RAM;
  int hardDriveSize;
  int year;
  double price;
};
int main()
{
  computerType computer;
  cout << "Enter the name of the manufacturer: ";
  getline(cin, computer.manufacturer);
  cout << "Enter the model of the computer: ";
  getline(cin, computer.modelType);
  cout << "Enter processor type: ";
  getline(cin, computer.processorType);
  cout << "Enter the size of RAM (in GB): ";
  cin >> computer.RAM;
  cout << "Enter the size of hard drive (in GB): ";
  cin >> computer.hardDriveSize;
  cout << "Enter the year the computer was built: ";
  cin >> computer.year;
  cout << "Enter the price: ";
  cin >> computer.price;
  cout << endl;
  cout << "Manufacturer: " << computer.manufacturer << endl << endl;
  cout << "Model: " << computer.modelType << endl << endl;
  cout << "Processor: " << computer.processorType << endl << endl;
  cout << "Ram: " << computer.RAM << endl << endl;
  cout << "Hard Drive Size: " << computer.hardDriveSize << endl << endl;
  cout << "Year Built: " << computer.year << endl << endl;
  cout << "Price: $" << setprecision(2) << fixed << computer.price << endl << endl;
  return 0;
}
Comments
Leave a comment