Please don\'t use while loop to answer. use cin.get and fstreams and stuff like
ID: 3672631 • Letter: P
Question
Please don't use while loop to answer. use cin.get and fstreams and stuff like that. HELP ASAP thank you ALSO IN C++ THANK YOU
The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets-box, sideline, premium, and general admission. After each game, data is stored in a file in the following form: ticketPrice numberOfTicketsSold Sample data are shown below: The first line indicates that the ticket price is $250 and that 5750 tickets were sold at that price. Output the number of tickets sold and the total sale amount. Format your output with two decimal places.
Explanation / Answer
main.cpp
//The manager of a football stadium wants you to write a program that calculates the
//total ticket sales after each game. There are four types of tickets:
//• Box $250
//• Sideline $100
//• Premium $50
//• General admission $25
//Create a class that contains string ticketType, int ticketID and double
//ticketCost. Instantiate an array[6] of these objects. Write a program that provides
//the user with a menu; asking what sort of tickets they would like to purchase. Ask
//the user to input the ticketID number.
//Open a file called ticketsSold.txt with the variable outFile and output the ticket
//information to this file. Then calculate the cost of all the tickets, and output this price
//to the screen.
#include <fstream>
#include <iomanip>
#include <string>
#include <iostream>
using namespace std;
const double BOX=250;
const double SIDE_LINE=100;
const double PREMIUM=50;
ofstream outFile("ticketsSold.txt", ios::app);
class Ticket
{
string ticketType;
int ticketID;
double ticketCost;
public:
Ticket::Ticket(string,int);
Ticket::Ticket(){};
void Ticket::setCost(double inCost){ticketCost=inCost;};
double getCost(){return ticketCost;};
string getType(){return ticketType;};
int getID(){return ticketID;};
};
Ticket::Ticket(string inType,int inID)
{
ticketType=inType;
ticketID=inID;
}
int main()
{
if(!outFile)
{
cout << "Cannot open file. ";
return 1;
}
Ticket tickets[2];
string inType;
int inID;
double cost;
cout<<"Ticket type and prices:"<<endl;
cout<<"**********************"<<endl;
cout<<"Box $250"<<endl;
cout<<"Sideline $100"<<endl;
cout<<"Premium $50"<<endl;
for (int i=0;i<2;i++)
{
cout<<"Please enter ticket type required"<<endl;
cin>>inType;
cout<<"Please enter ticket id"<<endl;
cin>>inID;
if (inType == "Box")
cost=BOX;
else
if (inType == "Sideline")
cost=SIDE_LINE;
else
cost=PREMIUM;
tickets[i]=Ticket(inType,inID);
tickets[i].setCost(cost);
cout<<tickets[i].getType()<<" "<<tickets[i].getID()<<" "<<tickets[i].getCost()<<endl;
outFile<<tickets[i].getType()<<" "<<tickets[i].getID()<<" "<<tickets[i].getCost()<<endl;
}
double totalCost=0;
for (int i=0;i<2;i++)
{
totalCost=totalCost+tickets[i].getCost();
}
cout<<"Cost of all tickets is $"<<totalCost<<endl;
return 0;
}