write a c++program that reads in the following data about 10PCs: vendor name, mo
ID: 652849 • Letter: W
Question
write a c++program that reads in the following data about 10PCs: vendor name, model, price, RAM(in megabytes), hard disk size(in gigabytes), monitor(y or n), and monitor size. The data is stored in a file defined below.
After storing the data in an array of structures, your program should prompt the user to look up data about the PCs. Provide menu similar to the following from which your user can make choices:
Enter 1) list all information about one PC
2) list all information about all PCs
3) list some information about one PC
4) list some information about all PCs
5) I am finished looking up information about PCs
Your program should prompt the user for addtional information depending on which choice is selected. For example, if user chooses 3 from the menu, your program should prompt the user for the name of the PC and which features to consider.
Data file
Micron
ClientPro 233
1499.00
32
y
15.0
Micron
NetFRAME MV5001
3799.00
64
4.0
n
0.0
Gateway
G6-233
1499.00
32
2.0
y
15.0
Gateway
G6-300
1999.00
32
4.0
y
17.0
Gateway
G6333
2499.00
64
6.4
y
17.0
NEC
Powremate 8000-300
1699.00
32
3.2
n
0.0
Dell
M200ST
2199.00
32
3.2
y
12.1
CompUSA
AP333L-SE
2299.00
32
6.4
y
17.0
Dell
XPSD300
2399.00
64
6.4
y
17.0
Gateway
G6-266
1799.00
32
4.0
y
1799.00
Explanation / Answer
#include <bits/stdc++.h>
using namespace std;
struct computer{
public:
string vendor_name;
string model;
float price;
float RAM;
float hard_disk;
char Monitor;
float mointor_size;
computer(string s,string m,float p,float r,float hd,bool moni,float moni_size){
vendor_name = s;
model = m;
price = p;
RAM = r;
hard_disk = hd;
Monitor = moni;
monitor_size = moni_size;
}
};
int main() {
ifstream infile;
infile.exceptions ( std::ifstream::failbit | std::ifstream::badbit );
try {
infile.open("Data file");
vector<computer*> vect;
for (int i = 0; i < 10; i++){
int j = 0;
string* l = new string[7];
string str;
while (j < 7){
getline(infile,str);
l[j] = str;
}
computer *c = new computer(l[0],l[1],atof(l[2].c_str()),atof(l[3].c_str()),atof(l[4].c_str()),l[5],atof(l[6].c_str()));
vect.push_beck(c);
}
while (true){
cout << "Choose any option " << endl;
cout << "1. list all information about one PC " << endl;
cout << "2. list all information about all PCs" << endl;
cout << "3. list some information about one PC" << endl;
cout << "4. list some information about all PCs" << endl;
cout << "5. I am finished looking up information about PCs" << endl;
int n;
cin >> n;
if (n == 1){
string ss;
cout << "Enter the name of a PC " << endl;
cin >> ss;
for (int i = 0; i < vect.size(); i++){
if (vect[i]->vendor_name == ss){
cout << "Vendor Name : " << vect[i]->vendor_name << endl;
cout << "Model : " << vect[i]->model << endl;
cout << "price : " << vect[i]->price << endl;
cout << "RAM : " << vect[i]->RAM << endl;
cout << "hard_disk : " << vect[i]->hard_disk << endl;
cout << "Monitor : " << vect[i]->monitor << endl;
cout << "Monitor Size : " << vect[i]->monitor_size << endl;
break;
}
}
}
else if (n == 2){
cout << "INFORMATION OF ALL COMPUTERS ";
for (int i = 0; i < vect.size(); i++){
cout << "Vendor Name : " << vect[i]->vendor_name << endl;
cout << "Model : " << vect[i]->model << endl;
cout << "price : " << vect[i]->price << endl;
cout << "RAM : " << vect[i]->RAM << endl;
cout << "hard_disk : " << vect[i]->hard_disk << endl;
cout << "Monitor : " << vect[i]->monitor << endl;
cout << "Monitor Size : " << vect[i]->monitor_size << endl;
cout << endl << endl;
}
}
else if (n == 3){
string ss;
cout << "Enter the name of a PC " << endl;
cin >> ss;
for (int i = 0; i < vect.size(); i++){
if (vect[i]->vendor_name == ss){
cout << "Vendor Name : " << vect[i]->vendor_name << endl;
cout << "Model : " << vect[i]->model << endl;
cout << "price : " << vect[i]->price << endl;
cout << "RAM : " << vect[i]->RAM << endl;
cout << "hard_disk : " << vect[i]->hard_disk << endl;
cout << "Monitor : " << vect[i]->monitor << endl;
cout << "Monitor Size : " << vect[i]->monitor_size << endl;
break;
}
}
}
else if (n == 4){
cout << "INFORMATION OF ALL COMPUTERS ";
for (int i = 0; i < vect.size(); i++){
cout << "Vendor Name : " << vect[i]->vendor_name << endl;
cout << "Model : " << vect[i]->model << endl;
cout << "price : " << vect[i]->price << endl;
cout << "RAM : " << vect[i]->RAM << endl;
cout << "hard_disk : " << vect[i]->hard_disk << endl;
cout << "Monitor : " << vect[i]->monitor << endl;
cout << "Monitor Size : " << vect[i]->monitor_size << endl;
cout << endl << endl;
}
}
else
break;
}
}
catch (std::ifstream::failure e) {
std::cerr << "The File ---- input.txt ---- is not Here ";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.