write a program that defines two different structures as follows: 1) A cPu struc
ID: 3577249 • Letter: W
Question
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 these two files off of the KA drive. They are motherboard.txt and cpu.txt. Your program will read each file into its appropriate structure. Please see the attached for information regarding the data files. Your program will utilize two functions. get the following specifications from the user: The speed of the cPU, the motherboards manufacturer id, and their full name. All of this information must be returned back to main. The second function will take in the two arrays and all of the data that the user typed in and will calculate and return the total cost of the components (CPU, Motherboard). The second function will also display the specifications as follows: The CPU is AMD Model 280 and has a speed of 2.8 GHz The Motherboard is Model 3345 The bolded items represent the variable data regarding each component. Once the total has been returned to main, display the following: The total cost of the custom computer for Joe Baker is $689.98Explanation / Answer
#include <iostream>
#include <cstring>
#include<vector>
#include<fstream>
#include<algorithm>
#include <sstream>
using namespace std;
struct cStructure {
string cName;
int cModel;
float cSpeed;
float cPrice;
};
struct mStructure{
int MId;
int MModel;
float MPrice;
};
string CTS(string text)
{
int length = text.size();
int x = 0;
string fixed;
while (x != length) {
string letter = text.substr(x, 1);
if (letter == ",") {
letter = " ";
}
fixed = fixed + letter;
x = x + 1;
}
return fixed;
}
int main(int argc, const char * argv[]){
vector<string> clist;
vector<string> mlist;
string line1[30];
int choice;
ifstream myfile("computer.txt");
ifstream myfile1("motherboard.txt");
int a = 0;
if(!myfile)
{
cout<<"Error opening output file"<<endl;
return -1;
}
while(!myfile.eof())
{
getline(myfile,line1[a],' ');
line1[a]=CTS(line1[a]);
string str1(line1[a]);
istringstream iss(str1);
while (iss) {
string word;
iss >> word;
clist.push_back(word);
}
}
if(!myfile1)
{
cout<<"Error opening output file"<<endl;
return -1;
}
while(!myfile1.eof())
{
getline(myfile1,line1[a],' ');
line1[a]=CTS(line1[a]);
string str1(line1[a]);
istringstream iss(str1);
while (iss) {
string word;
iss >> word;
mlist.push_back(word);
}
}
cout<<"*******************************CLIST DATA****************************";
for(int i=0;i<clist.size();i++){
cout<<" "<<clist[i];
}
cout<<"*******************************MLIST DATA****************************";
for(int i=0;i<mlist.size();i++){
cout<<" "<<mlist[i];
}
struct cStructure c;
struct mStructure m;
cout<<" What speed of CPU would you like?";
cin>>c.cSpeed;
cout<<" What is the manufacture ID of motherboard you like?";
cin>>m.MId;
cout<<" Please enter your name:";
cin>>c.cName;
float t=c.cSpeed;
cout<<"t:"<<t;
// string temp =;
for(int i=0;i<clist.size();i++){
if(strcmp(clist[i],()c.cSpeed)==0){
cout<<" The CPU is "<<clist[i-2]<<" Model "<<clist[i-1]<<" and has a speed of "<<clist[i]<<" GHz";
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.