Thursday, August 15, 2013

Game Tickets Sold

#include <fstream>
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
 //named constants.

 ifstream inData;
    ofstream outData;

 double ticketPrice1,ticketPrice2,ticketPrice3,ticketPrice4;
 int numberOfTicketsSold1,numberOfTicketsSold2,numberOfTicketsSold3,numberOfTicketsSold4,totalTicketsSold;
    double boxTicketsSold,sidelineTicketsSold,premiumTicketsSold,generalAdmisionTicketsSold,totalAmount;

 //open the input and output data.
 inData.open("data.dat");
    outData.open("ticketsSold.txt");



 //import data.
 inData >>ticketPrice1;
    inData>>numberOfTicketsSold1;
 inData>>ticketPrice2;
    inData>>numberOfTicketsSold2;
    inData >> ticketPrice3;
    inData>>numberOfTicketsSold3;
 inData >> ticketPrice4;
    inData>>numberOfTicketsSold4;


 //export data.
 outData<<setw(5)<< ticketPrice1<<"  "<<numberOfTicketsSold1<<'\n';
 outData<<setw(5)<<ticketPrice2<<"  "<<numberOfTicketsSold2<<'\n';
    outData << setw(5)<<ticketPrice3<<"  "<<numberOfTicketsSold3<<'\n';
 outData << setw(5)<<ticketPrice4<<"  "<<numberOfTicketsSold4<<'\n';

 //set decimal places after comma.
   outData << fixed << showpoint;
   outData << setprecision(2);

   //calculate box tickets sold.
 boxTicketsSold= ticketPrice1 * numberOfTicketsSold1;

 //calculate sideline tickets sold.
 sidelineTicketsSold= ticketPrice2 * numberOfTicketsSold2;

 //calculate premium tickets sold.
 premiumTicketsSold= ticketPrice3 * numberOfTicketsSold3;

 //calculate general admision tickets sold
 generalAdmisionTicketsSold= ticketPrice4 * numberOfTicketsSold4;

 //calculate the total number of tickets sold.
 totalTicketsSold= numberOfTicketsSold1 + numberOfTicketsSold2 + numberOfTicketsSold3 + numberOfTicketsSold4;

 //calculate the total amount of tickets sold.
 totalAmount = boxTicketsSold + sidelineTicketsSold + premiumTicketsSold + generalAdmisionTicketsSold;

 //display output data
 outData << "The total number of tickets sold is:" <<setw(6) << totalTicketsSold<<'\n';
 outData<<"The total amount of tickets sold is $:"<<totalAmount<<endl;

 //close input and output data
   inData.close();
   outData.close();

 system("pause");
 return 0 ;
   

No comments:

Post a Comment