Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Lab Manual For Database Development

Authors: Rachelle Reese

1st Custom Edition

1256741736, 978-1256741732

More Books

Students also viewed these Databases questions

Question

x-3+1, x23 Let f(x) = -*+3, * Answered: 1 week ago

Answered: 1 week ago