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 22:00
What operating system is a smartphone most likely to use? 1.bsd 2.mac os x 3.symbian 4.linux
Answers: 1
question
Computers and Technology, 22.06.2019 08:40
1. the program must provide following functions to extract some statistics. note that the data_list parameter specified in these functions may be the same for all functions or different for different functions—that is your choice. a skeleton file is provided on mirmir. a) open_file()prompts the user to enter a year number for the data file. the program will check whether the year is between 1990 and 2015 (both inclusive). if year number is valid, the program will try to open data file with file name ‘year.txt’, where is the year. appropriate error message should be shown if the data file cannot be opened or if the year number is invalid. this function will loop until it receives proper input and successfully opens the file. it returns a file pointer and year. i. hint: use string concatenation to construct the file name b) read_file(fp)has one parameter, a file pointer read. this function returns a list of your choosing containing data you need for other parts of this project. c) find_average(data_list) takes a list of data (of some organization of your choosing) and returns the average salary. the function does not print anything. hints: i. this is not the average of the last column of data. it is not mathematically valid to find an average by finding the average of averages—for example, in this case there are many more in the lowest category than in the highest category. ii. how many wage earners are considered in finding the average (denominator)
Answers: 1
question
Computers and Technology, 22.06.2019 11:00
You receive an email from an impressive-sounding stranger, professor alexander rothschild renard iii, president of the american institute for scientific political statesmen. he urges you to vote for his presidential candidate choice. this social media red flag is known as
Answers: 1
question
Computers and Technology, 23.06.2019 02:00
For a typical middle-income family, what is the estimated cost of raising a child to the age of 18? $145,500 $245,340 $304,340 $455,500
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
Mathematics, 28.05.2020 01:03
Questions on the website: 13722362