Rides to write a solution that can handle any number of rides (up to the MAX) and must handle completely different types of rides in waiting time

1926Question

In this program the user will enter the following information for attractions to

visit at Walt Disney World

** Name of Attraction

** Wait Time

The information the user enters must be stored in two parallel arrays (one array

for the attraction name and another for the wait time). The user is in control of

how many attractions to enter (up to a MAX of 25 rides).

In addition to displaying the attraction/wait time chart, the program also needs to:

– determine which attraction has the shortest wait and display the name and wait time for it

– calculate the average wait time per attraction

To complete this exam, it is necessary to write a program that matches the

Sample Output (shown at the bottom) using the proper techniques taught in this course.

Remember that each part of this exam is worth points, so be sure to complete everything

you know how to do as quickly as you can.

*/

#include<iostream>

#include<string>

#include<iomanip>

using namespace std;

//——————————————————————————

int main()

{

/* create a program that produces the Sample Output shown at the bottom.

You MUST:

– Write a solution that can handle any number of rides (up to the MAX) and must handle completely different types of ride

and wait time entries. A hard coded solution that only handles THIS Sample Output will have a substantial amount of points deducted

– Using parallel arrays is necessary and essential to a correct solution

– Items in the Sample Output on a line that come after a colon (:) are entered by the user

– Make sure the user is not allowed to go past the MAX size of the arrays (including not asking the user if they want to go

again if the MAX has been reached)

– Be sure to keep track of the index of the location of the ride with the shortest wait time so the details of that ride can

later be retrieved and reported on

– Use the most appropriate type of loop for each situation, there is ALWAYS a best choice

– Errors can occur when the user enters the wait time or whether to go again, NOT only where shown in the Sample

– Assume the user makes no errors while entering the attraction name

– Be sure to perform user input validation on the entries for wait time to make sure they are

in the range 0 to 600.

– Be sure to perform user input validation when the user enters ‘y’ or ‘n’ for whether to go again (capital letters

must also be accepted)

– Use constant(s) if/where appropriate

– At the end, report the details of the project the user worked on most

*/

// <write your solution code below this comment>

return 0;

}

/* Sample Output

Welcome to Walt Disney World!

Please enter the attractions you plan to visit and their wait times.

Ride #1 Info

Attraction Name: Rock and Roller Coaster

Wait time (in minutes): 80

Do you want to enter info for another attraction (y/n): x

Enter another ride (must be y/n): 7

Enter another ride (must be y/n): Y

Ride #2 Info

Attraction Name: 7 Dwarfs Mine Train

Wait time (in minutes): -1

STOP: Wait times must be 0 to 600 minutes. Try again: 130

Do you want to enter info for another attraction (y/n): y

Ride #3 Info

Attraction Name: Star Wars Rise of the Resistance

Wait time (in minutes): 5000

STOP: Wait times must be 0 to 600 minutes. Try again: 500

Do you want to enter info for another attraction (y/n): Y

Ride #4 Info

Attraction Name: It’s a Small World

Wait time (in minutes): 0

Do you want to enter info for another attraction (y/n): y

Ride #5 Info

Attraction Name: Expedition Everest

Wait time (in minutes): 22

Do you want to enter info for another attraction (y/n): N

Wait

Time

Ride                  (mins)

============================================

Rock and Roller Coaster          80

7 Dwarfs Mine Train           130

Star Wars Rise of the Resistance     500

It’s a Small World             0

Expedition Everest            2

Shortest wait time is: It’s a Small World (0 minutes).

Average Wait Time (per attraction): 146.40 minutes.

Press any key to continue . . .

*/

 

 

Summary

Once, the waiting time has arrived and attraction in the code or came to the entry then it has required many things in the code. Each and every entry is validated in the code after the waiting time has arrived. When the shortest waiting time arrives in the attraction rides the system gets the information and it gives the output. So, whenever the shortest waiting time arrives in the attraction after the average waiting time is also calculated by the system and gives the output to the user of the attraction rides.

Explanation

String type and int type arrive in the attraction rides and entry names are stored in the waiting time names, and it has validation. Again, after entering the names in the attraction when the waiting time arrives they entered by the user, it must be validated. Waiting time must have a range between 0-600. Now, the system must be identified or asked by the user to ‘yes’ or ‘no’ for the information to get for another information for the user.

All the information entered by the user must be validated and the information of the ride is entered correctly the smallest waiting time as printed output as well as average waiting time also printed.

Code

#include <iostream>
using namespace std;
#include <iomanip>
int main()
{
    /* to store the attraction names */
    string a[25];
    int w[25]; int cc=0;
    /* to get every attraction info */
    for(int k=0;k<25;k++){
        cc++;
        cout<<"Ride #"<<(k+1)<<" Info"<<endl;
        cin.ignore();
        cout<<"Attraction Name: ";
        getline(cin,a[k]);
        cout<<"Wait time (in minutes): ";
        /* to validate waiting time */
        while(true){
            cin>>w[k];
        if(w[k]>=0 && w[k]<=600){break;}
        else 
        cout<<"STOP: Wait time must be 0 to 600 minutes. Try again: ";
        }
        cout<<"Do you want to enter info for another attraction (y/n): ";
        char choice;
        cin>>choice;
        /* to avlidate the choice */
        if(choice=='n' || choice=='N')
        break;
        else if(choice=='y' || choice=='Y'){}
        else{
            while(true){
                cout<<"Enter another ride (must be y/n): ";
                cin>>choice;
                if(choice=='y' || choice=='Y' || choice=='n' || choice=='N')
                break;
            }
            if(choice=='n' || choice=='N')
        break;
        else if(choice=='y' || choice=='Y'){}
        }
    }
    /* to print the attractions info */
    cout<<left;
    cout<<setw(30)<<"Ride"<<setw(20)<<"Wait Time (mins)"<<endl;
    int small=9999; string att; int sum=0;
    for(int i=0;i<cc;i++){
        cout<<setw(30)<<a[i]<<setw(20)<<w[i]<<endl;
        /* to find the smallest waiting time */
        if(small>w[i]){
            small=w[i]; att=a[i];
        }
        /* to find the average waiting time */
        sum=sum+w[i];
    }
    cout<<endl<<endl<<endl;
    float avg=sum/static_cast<float>(cc);
    cout<<"Shortest wait time: "<<att<<" ("<<small<<" minutes)."<<endl;
    cout<<"Average Wait Time (per attraction): "<<avg<<" minutes."<<endl;
}

Output

handle any number of rides

 

Also, read our other blog which is Write a program for the customer who is willing to take the vehicles for rent.

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *