Question: Write an exception class such that it can throw an exception when the input file is not found #include #include #include #include using namespace std;

Write an exception class such that it can throw an exception when the input file is not found

#include #include #include #include using namespace std;

const int NO_OF_COMPUTES = 2;

struct computerType { string cID; string manufacturer; string name; string cpuSpeed; int ramSize; double price; };

void getComputer(ifstream& infile);

/*void writeComputer(ofstream& outfile, computerType list[], int listSize);*/

int main() {

ifstream infile; //input file stream variable ofstream outfile; //output file stream variable

string inputFile; //variable to hold the input file name string outputFile; //variable to hold the output file name

computerType computerTypeList[NO_OF_COMPUTES];

cout << "Enter the input file name: "; cin >> inputFile; cout << endl;

infile.open(inputFile.c_str());

if (!infile) { cout << "Cannot open the input file." << endl; return 1; }

getComputer(infile);

infile.close(); outfile.close(); system("pause"); return 0; }

void getComputer(ifstream& infile) { int index; string cID; string manufacturer; string name; string cpuSpeed; int ramSize; double price;

infile >> cID; while (infile) { infile >> manufacturer >> name >> cpuSpeed >> price; cout << cID << " " << manufacturer << " " << name << " " << cpuSpeed << " " << price; infile >> cID; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!