Question

write a program that defines two different structu
write a program that defines two different structu
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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],'\n');
    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],'\n');
    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<<"\n"<<clist[i];
   }
   cout<<"*******************************MLIST DATA****************************";
   for(int i=0;i<mlist.size();i++){
       cout<<"\n"<<mlist[i];
   }
   struct cStructure c;
   struct mStructure m;
   cout<<"\nWhat speed of CPU would you like?";
   cin>>c.cSpeed;
   cout<<"\nWhat is the manufacture ID of motherboard you like?";
   cin>>m.MId;
   cout<<"\nPlease 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<<"\nThe CPU is "<<clist[i-2]<<" Model "<<clist[i-1]<<" and has a speed of "<<clist[i]<<" GHz";
       }
   }

}

Add a comment
Know the answer?
Add Answer to:
write a program that defines two different structures as follows: 1) A cPu structure that contains...
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
  • PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program...

    PROGRAMMING LANGUAGE OOP'S WITH C++ Functional Requirements: A jewelry designer friend of mine requires a program to hold information about the gemstones he has in his safe. Offer the jewelry designer the following menu that loops until he chooses option 4. 1. Input a gemstone 2. Search for a gemstone by ID number 3. Display all gemstone information with total value 4. Exit ------------------------------------- Gemstone data: ID number (int > 0, must be unique) Gem Name (string, length < 15)...

  • C++ Implement Random Access Binary Files. Do Not use Arrays instead write the data directly to...

    C++ Implement Random Access Binary Files. Do Not use Arrays instead write the data directly to Random Access Binary File. New program should be modified to display a menu for the user to do the following: 1. Replace Employee and Department classes with Employee and Department Structures. 2. Inside each structure, replace all string variables with array of characters. 3. Make Employee and Department editable. That means, the user should be able to edit a given Employee and Department. 4....

  • C++ Implement Random Access Binary Files. Do Not use Arrays instead write the data directly to...

    C++ Implement Random Access Binary Files. Do Not use Arrays instead write the data directly to Random Access Binary File. New program should be modified to display a menu for the user to do the following: 1. Replace Employee and Department classes with Employee and Department Structures. 2. Inside each structure, replace all string variables with array of characters. 3. Make Employee and Department editable. That means, the user should be able to edit a given Employee and Department. 4....

  • Structures in C++ :- 1. Write a program that declares a structure to store the code...

    Structures in C++ :- 1. Write a program that declares a structure to store the code number, salary and grade of an employee. The program defines two structure variables, inputs record of two employees and then displays the record of the employee with more salary. 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then...

  • Write a program that defines a Print Job structure as follows: 1) An integer job Id...

    Write a program that defines a Print Job structure as follows: 1) An integer job Id 2) A string user name (maximum 25 characters) 3) An integer tray (tray will hold the tray number 1 for 8 1/2 by 11 paper, number 2 for 8 1/2 by 11 paper, and number 3 for 8 1/2 by 14 paper) 4) An integer for paper size (this will hold a percentage: 100% is normal, 150% is 1.5 times the size) 5) A...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • Structures in C++ :- 2. Write a program that declares a structure to store the distance...

    Structures in C++ :- 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then display the record of the winner. 3. Write a program that declares a structure to store income, tax rate and tax of a person. The program defines an array of structure to store the records of five person. It inputs income...

  • Write a C program that does/has the following: 1) Create a structure named “employee” that contains...

    Write a C program that does/has the following: 1) Create a structure named “employee” that contains the following fields: name (string), id (int), salary (float) and a pointer to the next list item. 2) Create a structure that extends the “employee” structure named “manager” that will contain an additional field for an array of pointers that will point to the employees that they manage, each manager will manage 3 employees. 3) Read the text file provided with this assignment to...

  • Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a...

    Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...

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