Question

In: Computer Science

I'm having a very hard time getting this c++ code to work. I have attached my...

I'm having a very hard time getting this c++ code to work. I have attached my code and the instructions.

CODE:

#include
using namespace std;

void printWelcome(string movieName, string rating, int startHour, int startMinute, char ampm); //menu function
//constants
const double TICKET_PRICE = 9.95;
const double TAX_RATE = 0.095;
const bool AVAILABLE = true;
const bool UNAVAILABLE = false;
int subTotal,taxAdded, totalCost;
//
bool checkAvailability( int tickets, int& seatingLeft){ //checks ticket availability
while(tickets > 0 || tickets <= 200) //valid ticket entry
cout<< AVAILABLE< while(tickets < 0) //invalid number of tickets entered
cout<< UNAVAILABLE << "Invalid number of tickets: "< while(tickets > 200)//not enough tickets availible;
cout<< UNAVAILABLE<<"Could not process your request. There are only x tickets left.";
while(tickets == 0)
cout< }
void calcAndPrintReceipt(int tickets){ //does price claculations
subTotal = tickets * TICKET_PRICE;
taxAdded = subTotal * TAX_RATE;
totalCost = subTotal + taxAdded;
cout<<"SUBTOTAL: $"< cout<<"TAXES: $"< cout<<"TOTAL: $"< }

int main() {      
int seatingLeft = 300; // number of empty seats available for purchase
string movieName = "The best movie Ever"; //movie title
string rating = "Rated: PG-13"; // Motion Picture Assoc. of America rating
int startHour = 2; // start time in 12-hour clock
int startMinute = 30;
char ampm = 'P';
int tickets; // how mamy tickets user wants to buy
//
cout< cout << "How many tickets (0 to end)? ";
cin >> tickets;
while (tickets != 0 ) {
if (checkAvailability(tickets, seatingLeft ) ) {
calcAndPrintReceipt(tickets);
}
cout << "How many tickets (0 to end)? ";
cin >> tickets;
}
cout << "Enjoy the movie!\n";

return 0;
}

INSTRUCTIONS:

This application allows users to purchase movie tickets like a simplified version of Fandango™. Imagine you are creating a program to be used at a small movie theatre that only has one movie showing once a day. This program will be used at a kiosk to sell tickets to customers.

Detailed Information

Your program MUST use the variable and constant declarations below, Note the inline comments for the variables – these are examples of good inline comments. Use them, also. You may initialize the movie title, the rating, the start hour and minute and the ampm variable to different values if you like.

Declare and use the following global constants. Do not change the values of these constants.

const double TICKET_PRICE = 9.95;

const double TAX_RATE = 0.095;

const bool AVAILABLE = true;

const bool UNAVAILABLE = false;

Use the following main function. You may change the values of the movie name, the rating and the start time. DO NOT change anything else in the main function.

int main() {

   int seatingLeft = 300; // number of empty seats available for purchase

                          // movie title

   string movieName = "The Best Movie Ever";

   string rating = "PG-13";    // Motion Picture Assoc. of America rating

   int startHour = 4;          // start time in 12-hour clock

   int startMinute = 30;

   char ampm = 'P';

   int tickets;                // how mamy tickets user wants to buy

  

   printWelcome( movieName, rating, startHour, startMinute, ampm );

   cout << "How many tickets (0 to end)? ";

   cin >> tickets;

   while (tickets != 0 ) {

      if ( checkAvailability( tickets, seatingLeft ) ) {

         calcAndPrintReceipt( tickets );

      }

      cout << "How many tickets (0 to end)? ";

      cin >> tickets;

   }

   cout << "Enjoy the movie!\n";

   return 0;

}

Write the following functions that are called by the main function.

  • void printWelcome( string movieName, string rating, int startHour, int startMinute, char ampm ). Thus function prints the welcome message seen in the sample executions which include the movie name and start time.
  • bool checkAvailability( int tickets, int& seatingLeft ). This function checks seat availability. Its pre-condition is that the number of tickets is not zero. Its post-condition is if seats are available, then the actual parameter for seatingLeft is decremented by the number of tickets purchased. In this case, the function returns AVAILABLE. If the desired number of tickets is not available, the function prints one of three error messages shown below and in sample execution 2 and returns UNAVAILABLE.
    • Invalid number of tickets x (where x is the number of tickets requested by the user)
    • Could not process your request. There are only x tickets left. (where x is the number of tickets left)
    • I’m sorry. We’re SOLD OUT.
  • void calcAndPrintReceipt( int tickets ). Calculates and prints the receipt with all dollar amounts formatted with exactly 2 digits to the right of the decimal as shown in the sample executions.

Sample Executions

Sample Execution 1

Welcome to My Theater’s Ticketing Program.

Today we are showing: The Best Movie Ever rated PG-13 at 4:30 PM

How many tickets (0 to end)? 2    

Tickets purchased: 2

Subtotal: $19.90

Tax: $1.89

Total: $21.79

Today we are showing: The Best Movie Ever rated PG-13 at 4:30 PM

How many tickets (0 to end)? 5

Tickets purchased: 5

Subtotal: $49.75

Tax: $4.73

Total: $54.48

Today we are showing: The Best Movie Ever rated PG-13 at 4:30 PM

How many tickets (0 to end)? 0

Thank you for using My Theatre’s Ticketing Program.

Sample Execution 2

Welcome to My Theater’s Ticketing Program.

Today we are showing: The Best Movie Ever rated PG-13 at 4:30 PM

How many tickets (0 to end)? -1

Invalid number of tickets: -1

Today we are showing: The Best Movie Ever rated PG-13 at 4:30 PM

How many tickets (0 to end)? 400

Could not process your request. There are only 300 tickets left.

Today we are showing: The Best Movie Ever rated PG-13 at 4:30 PM

How many tickets (0 to end)? 300

Tickets purchased: 300

Subtotal: $2985.00

Tax: $283.57

Total: $3268.57

Today we are showing: The Best Movie Ever rated PG-13 at 4:30 PM

How many tickets (0 to end)? 1

I'm sorry. We're SOLD OUT.

Today we are showing: The Best Movie Ever rated PG-13 at 4:30 PM

How many tickets (0 to end)? 0

Thank you for using My Theatre’s Ticketing Program.

Relevance Questions

This lab requires the use of selection statements in order to decide whether to print one of the messages above. It also requires the use of loops to make it do something over and over again. Most programs of any significant size use loops because they need to do things more than once.

Rubric

  • (10 points) Program comments/style
  • (5 points) Relevance questions
  • Program Correctness (for a non-zero grade, the main function can not be altered with the exception of movie name, start time, and rating.
    • (5 points) Invalid number of tickets
    • (10 points) Not enough tickets left (but not sold out)
    • (10 points) Sold out
    • (10 points) Character output including formatting
    • (40 points) Tickets purchased and valid receipt values
    • (5 points) Use of constants in functions
    • (5 points) Miscellaneous

Solutions

Expert Solution

#include<iostream>
using namespace std;

//constants
const double TICKET_PRICE = 9.95;
const double TAX_RATE = 0.095;
const bool AVAILABLE = true;
const bool UNAVAILABLE = false;

void printWelcome( string movieName, string rating, int startHour, int startMinute, char ampm ){
        cout<<"Welcome to My Theater’s Ticketing Program.\n";
        cout<<"Today we are showing: "<<movieName<<" rated "<<rating<<" at "<<startHour<<":"<<startMinute<<" "<<ampm<<"M\n";
}

bool checkAvailability( int tickets, int& seatingLeft ){
        
        //handling invalid number of tickets
        if(tickets <= 0){
                cout<<"Invalid number of tickets "<<tickets<<"\n";
                return UNAVAILABLE;
        }

        //Checking SOLD OUT condition
        if(seatingLeft == 0){
                cout<<"I’m sorry. We’re SOLD OUT.\n";
                return UNAVAILABLE;     
        }

        //Checking if required amount of seats are left
        if(tickets <= seatingLeft){
                seatingLeft -= tickets;
                return AVAILABLE;
        }

        //if request cannot be statisfied
        cout<<"Could not process your request. There are only "<<seatingLeft<<" tickets left.\n";
        return UNAVAILABLE;
}

void calcAndPrintReceipt( int tickets ){
        float subTotal = tickets * TICKET_PRICE;        //calculating subtotal
        float taxAdded = subTotal * TAX_RATE;           //calculating total tax based on subtotal amount
        float totalCost = subTotal + taxAdded;          //calculating total cost including tax

        printf("Subtotal: $%.2f\n", subTotal);
        printf("Tax: $%.2f\n", taxAdded);
        printf("Total: $%.2f\n", totalCost);
}

int main() {

   int seatingLeft = 10; // number of empty seats available for purchase

   string movieName = "The Best Movie Ever";    // movie title

   string rating = "PG-13";    // Motion Picture Assoc. of America rating

   int startHour = 4;          // start time in 12-hour clock

   int startMinute = 30;

   char ampm = 'P';

   int tickets;                // how mamy tickets user wants to buy

  
   printWelcome( movieName, rating, startHour, startMinute, ampm );

   cout << "How many tickets (0 to end)? ";

   cin >> tickets;

   while (tickets != 0 ) {

      if ( checkAvailability( tickets, seatingLeft ) ) {

         calcAndPrintReceipt( tickets );

      }

      cout << "How many tickets (0 to end)? ";

      cin >> tickets;

   }

   cout << "Enjoy the movie!\n";

   return 0;

} 

To compile: g++ <filename>

To execute: ./a.out

Sample output is given below:

Note:

This print statement Thank you for using My Theatre’s Ticketing Program is missing in main method provided above and since modifying main method is not allowed. Please ask your instructor about this.

Also tickets > 0 || tickets <= 200 condition was present in your code where you are limiting the max number of tickets to 200 which is not mentioned in the problem, so I have not kept this in the code.

If you require any further help let me know.


Related Solutions

I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
I am having a hard time getting my an output after putting in the second set...
I am having a hard time getting my an output after putting in the second set of functions and I was hoping to be able to have the results from the functions be rounded to 2 decimal places. <html> <head> <title>Length Conversion</title> <script language='JavaScript' type='text/JavaScript'> <!-- function validate(type) { if(document.my_form.textinput.value=='') { alert('Fill the Input box before submitting'); return false; }else{ if(type=="to_feet"){ var res=3.2808*document.my_form.textinput.value; var unit=" feet"; }else{ var res=0.3048*document.my_form.textinput.value; var unit=" meter"; } document.getElementById("result").innerHTML=res.toFixed(2) + unit; return false; } }...
Hello, I'm having a hard time solving these problems because I have no idea on what...
Hello, I'm having a hard time solving these problems because I have no idea on what to do with accrued interest. Help is highly appreciated! On March 1, 2015, Bowan Corporation issued 6% bonds dated February 1, 2015, the face amount of $700,000. The bonds were sold for the present value of the bonds on March 1, 2015 plus one-month accrued interest. The bonds mature on January 31, 2018. Interest is paid semiannually on July 31 and January 31. Bowan's...
I’m having a very hard time. I have to do a poster pensebtation which I have...
I’m having a very hard time. I have to do a poster pensebtation which I have no clue how to do on Identify the key mental health disorders that affect the elderly. Determine how these key mental disorders differ across racial, ethic, gender, and socioeconomic lines. Thank you,
I am having a hard time getting started on how to do this assignment. I would...
I am having a hard time getting started on how to do this assignment. I would like some ideas on how to start the MEMO. and maybe some ideas on what you would include. But I don't necessarily need the assignment completed for me. just need ideas!!! One routine negative message in the form of an internal memo. 400-500 word message. Single-spaced, with 1-inch margins on all sides. Objective: To announce organizational restructuring, one routine negative message addressed to employees....
I'm having a problem getting my code to function correct, *num_stu keeps losing its value when...
I'm having a problem getting my code to function correct, *num_stu keeps losing its value when ever another function is called from the class. Can someone proof read this for me and let me know what'd up? Header.h file #include <iostream> using namespace std; class report {    private:        int* num_stu;         int xx;        int* id;        double* gpa;    public:                report(int x) {             num_stu = &x;             xx = x;            ...
I'm having trouble with validating this html code. Whenever I used my validator, it says I...
I'm having trouble with validating this html code. Whenever I used my validator, it says I have a stray end tag: (tbody) from line 122 to 123. It's the last few lines. Thanks and Ill thumbs up whoever can help solve my problem. Here's my code: <!DOCTYPE html> <html lang="en"> <head> <title>L7 Temperatures Fields</title> <!--    Name:    BlackBoard Username:    Filename: (items left blank for bb reasons    Class Section: (blank)    Purpose: Making a table to demonstrate my...
C# programming. Comment/Explain the below code line by line. I am having a hard time following...
C# programming. Comment/Explain the below code line by line. I am having a hard time following it. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Nth_prime {     class Program     {         public static bool isPrime(int number)         {             int counter = 0;             for (int j = 2; j < number; j++)             {                 if (number % j == 0)                 {                     counter = 1;                     break;                 }             }             if (counter == 0)             {                 return true;             }             else             {                 return false;             }         }...
For some reason I am having a hard time getting this program to compile properly. Could...
For some reason I am having a hard time getting this program to compile properly. Could you help me debug it? Write the prototypes and functions to overload the given operators in the code //main.cpp //This program shows how to use the class rectangleType. #include <iostream> #include "rectangleType.h" using namespace std; int main() {     rectangleType rectangle1(23, 45);                     //Line 1     rectangleType rectangle2(12, 10);                     //Line 2     rectangleType rectangle3;                             //Line 3     rectangleType rectangle4;                             //Line 4     cout << "Line...
I'm having difficulty trying to make my code work. Create a subclass of Phone called SmartPhone....
I'm having difficulty trying to make my code work. Create a subclass of Phone called SmartPhone. Make this subclass have a no-arg constructor and a constructor that takes a name, email, and phone. Override the toString method to return the required output. Given Files: public class Demo1 { public static void test(Phone p) { System.out.println("Getter test:"); System.out.println(p.getName()); System.out.println(p.getNumber()); } public static void main(String[] args) { Phone test1 = new SmartPhone(); Phone test2 = new SmartPhone("Alice", "8059226966", "[email protected]"); System.out.println(test1); System.out.println(test2); System.out.println(test1);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT