Write a C++ program ticketSales to do the following. In your main() function, yo
ID: 3683637 • Letter: W
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
o takes no parameter
o returns an integer
o when called, ask the user for the number of tickets sold and return it
• calculateTotal
o takes numbers of tickets sold as input parameter
o returns the total sales amount (ticket price is $10.99)
• calculateTax
o It is a void function
o takes total sales amount as the value parameter, tax as the reference parameter
o If sales is greater than or equal to $200, tax rate is 6%, if it is less than $200, tax rate is 5%.
• displayResult
o takes three input parameters: number of tickets, total sales, tax
o returns no value
o 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>
using namespace std;
class ticketsales
{
int number;
float total;
float tax;
public:
int getdata()
{
cout<<"How many tickets are sold";
cin>>number;
cout<<"ticket sold"<<number<<endl;
}
float calculatetotal(int n)
{
number=n;
total=number*10.99;
cout<<"Total sales $"<<total<<endl;
}
float calculatetax(float t1,float t2)
{
total=t1;
tax=t2;
tax=total*.06;
cout<<"Total tax $"<<tax<<endl;
}
void displayresult(int n, float t1, float t2)
{
number=n;
total=t1;
tax=t2;
cout<<"total number is "<<number<<endl;
cout<<"total sales $"<<total<<endl;
cout<<"total tax $"<<tax<<endl;
}
};
int main()
{
ticketsales s;
int number_tickets;
float total, tax;
number_tickets = s.getdata();
total = s.calculatetotal(number_tickets);
s.calculatetax(total, tax);
s.displayresult(number_tickets, total, tax);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.