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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started