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, 23.06.2019 01:30
In deadlock avoidance using banker’s algorithm, what would be the consequence(s) of: (i) a process declaring its maximum need as maximum possible for each resource. in other words, if a resource a has 5 instances, then each process declares its maximum need as 5. (ii) a process declaring its minimum needs as maximum needs. for example, a process may need 2-5 instances of resource a. but it declares its maximum need as 2.
Answers: 3
question
Computers and Technology, 23.06.2019 09:30
Write an essay on online collaboration, how to do it, the challenges, resolving the challenges, and consider whether the risks are greater than rewards. ( need )
Answers: 1
question
Computers and Technology, 23.06.2019 09:50
Allison and her group have completed the data entry for their spreadsheet project. they are in the process of formatting the data to make it easier to read and understand. the title is located in cell a5. the group has decided to merge cells a3: a7 to attempt to center the title over the data. after the merge, allison points out that it is not centered and looks bad. where would the title appear if allison unmerged the cells in an attempt to fix the title problem?
Answers: 2
question
Computers and Technology, 24.06.2019 13:00
Which best describes the condition under which the unicode output is the same as plain text ?
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
question
History, 16.12.2021 17:50
question
Mathematics, 16.12.2021 17:50
question
Biology, 16.12.2021 17:50
Questions on the website: 13722361