Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

On the basis of the given scenario create a file Expenses.txt, Openthe file and

ID: 3615211 • Letter: O

Question

On the basis of the given scenario create a file Expenses.txt, Openthe file and copy into another Expenses2.txt, Also show output onscreen
A college has announced the total budget of 50,000Rs.for each game.Games are done four times in a year. Take expenses as an input fromuser.

Calculate the average expenses for a game:
1. If the expenses greater than 80%show as” Very Expensive”.
2. If the expenses are greater than 60% and less than 80% than show“Expensive ”
3. If the expenses are greater than 50% and less than 60% than show“Less Expensive ”
4. If the expenses are greater than 40% and less than 50% than show“Not Costly”.
5. If the expenses are less than 40% than show“Best”.

Calculate the average expenses for a game:
1. If the expenses greater than 80%show as” Very Expensive”.
2. If the expenses are greater than 60% and less than 80% than show“Expensive ”
3. If the expenses are greater than 50% and less than 60% than show“Less Expensive ”
4. If the expenses are greater than 40% and less than 50% than show“Not Costly”.
5. If the expenses are less than 40% than show“Best”.


Explanation / Answer

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
int cost1,cost2,cost3,cost4,tot,percent,n,i;
string game;
ofstream output;
ifstream input;
output.open("Expenses.txt");        
if(output.fail())           
   { cout<<"Expenses file did not open for inputplease check it ";
   system("pause");
   return 1;
   }
cout<<"how many games are there? ";
cin>>n;
for(i=0;i<n;i++)
{  
cout<<"Enter the game name: ";
cin>>game;
cout<<"Enter cost for game 1: ";
cin>>cost1;
cout<<"Enter cost for game 2: ";
cin>>cost2;
cout<<"Enter cost for game 3: ";
cin>>cost3;
cout<<"Enter cost for game 4: ";
cin>>cost4;
tot=cost1+cost2+cost3+cost4;
percent=tot/50000.*100.;
output<<game<<" "<<cost1<<""<<cost2<<" "<<cost3<<""<<cost4<<" "<<percent<<" ";
if(percent>=80)
    output<<"Very Expesive ";
else if(percent>=60)
     output<<"Expesive ";
else if(percent>=50)
     output<<"Less Expesive ";
else if(percent>=40)
     output<<"Not Costly ";
else
     output<<"Best ";
}
output.close();
  input.open("Expenses.txt");         
  if(input.fail())          
       { cout<<"Expenses filedid not open for input please check it ";
        system("pause");
        return 1;
        }
output.open("Expenses2.txt");        
if(output.fail())           
   { cout<<"Expenses2 file did not open for outputplease check it ";
   system("pause");
   return 1;
   }
cout<<"The expensesare ";                  
for(i=0;i<n;i++)
{getline(input,game);
cout<<game<<endl;
output<<game<<endl;
}
output.close();
input.close();
system("pause");
return 0;
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote