subject

Write a program that reads a sequence of scores from a file and outputs the highest score. File name is input by the user (using cin >>) The program uses a function getHighscore() to read the input from file and determine the highest score. This function may throw two exceptions (depending on the situations):

FileIOError, if the file can not be opened
EmptyFileError, if the file includes no scores
Both exceptions must be defined as separate classes. These two classes can be empty or inherit from existing exception class, like run_time error class.

You can assume that, if a file includes scores, they are all positive integers and separated by spaces.

input1.txt is empty

input4.txt: 30 23 14 28 41

main. cpp

#include
#include
#include

using namespace std;

//Add exception classes

//Define getHighscore function

int main()
{
string filename;
cin >> filename;

try
{
int highscore = getHighscore(filename);
cout << "The high score is " << highscore << endl;
}
catch(/*catch FileIOError*/)
{
cout << "Could not open the scores file.\n";
}
catch(/*catch EmptyFileError*/)
{
cout << "The file is empty.\n";
}
return 0;
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 19:00
Jill wants to become a network professional. which certification would be useful for her? a. mcse b. pmp c. comptia a+ d. ccie
Answers: 2
question
Computers and Technology, 21.06.2019 19:30
Asalesman at a high end computer security firm want to sell you a proactive cover for your passport, which contains an rfid tag inside storing your sensitive information. the salesperson's solution cost only $79.99 and protects your passport from being read via radio waves while it is in your pocket. explain how you can achieve the same thing under $3.00
Answers: 3
question
Computers and Technology, 22.06.2019 19:10
10. when you create a pivottable, you need to specify where to find the data for the pivottable. is it true
Answers: 2
question
Computers and Technology, 23.06.2019 12:20
When guido van rossum created python, he wanted to make a language that was more than other programming languages. a. code-based b. human-readable c. complex d. functional
Answers: 1
You know the right answer?
Write a program that reads a sequence of scores from a file and outputs the highest score. File name...
Questions
Questions on the website: 13722361