* Write a C++ program ticketSales to do the following. In your main() function,
ID: 3684123 • Letter: #
Question
* Write a C++ program ticketSales to do the following.
In your main() function, you should do the following
• Call the function getNumber() to get the number of tickets sold
• Call the function calculateTotal() to get the total sales amount
• Call the function calculateTax() to get the tax amount (6% of the total sales)
• Call the function displayResult() to display the final calculation results
You should implement four functions:
• getNumber
takes no parameter
returns an integer
when called, ask the user for the number of tickets sold and return it
• calculateTotal
takes numbers of tickets sold as input parameter
returns the total sales amount (ticket price is $10.99)
• calculateTax
It is a void function
takes total sales amount as the value parameter, tax as the reference parameter
If sales is greater than or equal to $200, tax rate is 6%, if it is less than $200, tax rate is 5%.
• displayResult
takes three input parameters: number of tickets, total sales, tax
returns no value
display them in a nice format
Sample output
>./a.out
How many tickets are sold? 25
Tickets Sold: 25
Total Sales:$274.75
Tax:$16.49
>./a.out
How many tickets are sold? 15
Tickets Sold: 15
Total Sales:$164.85
Tax:$8.24
The implementation of the main() function:
int main()
{
int number_tickets;
float total, tax;
number_tickets = getNumber();
total = calculateTotal(number_tickets);
calculateTax(total, tax);
displayResult(number_tickets, total, tax);
return 0;
}
Explanation / Answer
#include <iostream>
#include<iomanip>
using namespace std;
int getNumber()
{
int ticketsSold;
cout<<"How many tickets are sold?";
cin>>ticketsSold;
return ticketsSold;
}
float calculateTotal(int ticketsSold)
{
return (10.99*ticketsSold);
}
void calculateTax(float total, float *tax)
{
if(total>200)
*tax=(total/100)*6;
else *tax=(total/100)*5;
}
void displayResult(int number_tickets, double total, float tax)
{
cout<<"Tickets Sold:"<<number_tickets<<endl;
cout<<"Total Sales: $"<<total<<endl;
cout<<"Tax:$"<<setprecision(3)<<tax<<endl;
}
int main()
{
int number_tickets;
float total,tax;
number_tickets=getNumber();
total = calculateTotal(number_tickets);
calculateTax(total, &tax);
displayResult(number_tickets, total, tax);
return 0;
}
OUTPUT:
How many tickets are sold?15
Tickets Sold:15
Total Sales: $164.85
Tax:$8.24
Process returned 0 (0x0) execution time : 4.148 s
Press any key to continue.
How many tickets are sold?25
Tickets Sold:25
Total Sales: $274.75
Tax:$16.5
Process returned 0 (0x0) execution time : 2.380 s
Press any key to continue.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.