Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include / public / read . h #include #include #include #include using namespace std; void die ( ) { cout < < You
#include publicreadh
#include
#include
#include
#include
using namespace std;
void die
cout "You dun goofed.
;
exit;
int main
This is equivalent to string filename; cout "Please enter a filename
; cin filename;
But on one line instead of three, because Im cool like that
string filename readPlease enter a filename:
;
ifstream Filefilename;
if File
die;
int k;
File k;
if Filefail k
die;
vector casesk;
for int i ; i k; i
File casesi;
if Filefail
die;
int value ;
for int i ; i k; i
value casesi;
while true
int b;
cout "Please enter a briefcase to open:
;
cin b;
cout"That briefcase held casesb dollars
;
value casesb;
casesb;
k;
cout I will offer you $ valuek dollars to walk away.
;
if b
cout You won value k dollars!
;
break;
if b b k casesb
die;
cout "That briefcase held casesb dollars
;
value casesb;
casesb;
k;
if k
for int i ; i cases.size; i
if casesi
cout "You won casesi dollars!
;
break;
cout I will offer you $ value k dollars to walk away.
;
return ;
For this assignment:
Prompt the user with: "Please enter a filename:
;
You will read a filename in from cin, which will be a single word.
You will open that file.
That file will contain:
The number of briefcases NN must be
Followed by N dollar amounts, one on each line. ALL ARE POSITIVE INTS.
You will read that into a vector of ints of size N
After that, you will go into an infinite loop:
Prompt the user with: "Please enter a briefcase to open:
;
The user will input a briefcase to open an integer which will range
from to N
Print "That briefcase held X dollars"
You will then calculate the average value left in the cases.
Use INTEGER DIVISION. Ie if the cases hold the average is
Output the average to the user: "I will offer you X dollars to walk
away.
The loop will terminate if the user ever types indicating that a
deal is made or if there is only one briefcase left.
In both cases, print to the screen how much money they won. This will either
be the last offer if they took the deal or the money in the last briefcase.
It will look like this: "You won X dollars!
If an error occurs, print out "You dun goofed.
and quit.
Possible error cases you have to handle:
If you are told to open a file that doesn't exist
An error reading from the file like if it has letters, or ends before N
dollar amounts are read.
The user trying to open the same briefcase twice
The user trying to open a negative briefcase other than or a briefcase
higher than N
If there are less than briefcases to begin with.
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