Question

In: Computer Science

I NEED TO DEBUG THIS PSUEDOCODE // This pseudocode should determine and output the rental fees...

I NEED TO DEBUG THIS PSUEDOCODE

// This pseudocode should determine and output the rental fees for cars.
// Standard cars rent for $65 per day, compacts rent for $40 per day,
// and subcompacts rent for $30 per day. Rentals for at least 7 days
// receive a 20% discount. An error message is displayed if the car type
// is not valid.

start
Declarations
string carType
num days
num STD_RATE = 65
num COM_RATE = 40
num SUB_RATE = 30
num DAYS_FOR_DISCOUNT = 10
num DISCOUNT_RATE = 0.20
string QUIT = "ZZZZ"
getReady()
while carType <> QUIT
detailLoop()
endwhile
finish()
stop

getReady()
output Enter car type or , QUIT, to quit
input carType
return

detailLoop()
output "Enter days rented "
input days
if carType = "Standard" then
rate = STD_RATE
else
if car_Type = "Compact" then
rate = COMPACT_RATE
else
if carType = "Subcompact" then
rate = SUB_RATE
else
rate = 0
output "Invalid car type"
endif
endif
endif
if rate <> 0
if days >= DAYS_FOR_DISCOUNT then
rate = rate * DISCOUNT_RATE
endif
output carType, days
output "Enter car type or ", QUIT, " to quit "
input carType
return

finish()
output "End of program"
return

Solutions

Expert Solution

Pseudo-code for car rentals:

Start
   string carType;
   num days;
   num rate=0;
   num discount=0;

   num STD_RATE = 65;
   num COM_RATE = 40;
   num SUB_RATE = 30;
   num DAYS_FOR_DISCOUNT = 10;
   num DISCOUNT_RATE = 0.20;
   string QUIT = "ZZZZ";

   Call getReady() function and save return value in carType

   While carType is not QUIT Then
       output "Enter days rented "
       input days
       if carType is equal to "Standard" Then
           Set rate = STD_RATE;
       else if (carType is equal to "Compact" Then
           Set rate = COM_RATE
       else if (carType is equal to "Subcompact" Then
           Set rate = SUB_RATE
       Otherwise
           Set rate = 0
           output "Invalid car type"
       End if

       If rate is not equal to 0 Then
           output "Rental Fee: $"<<rate<<endl;
           If days >= DAYS_FOR_DISCOUNT Then
               Calculate discount = rate * DISCOUNT_RATE;
               output "Discount Fee: $",discount
               output "Net fee: $", (rate-discount)
           End if
       End if

       Call getReady() function and save return value in carType
   End While
  
Stop

getReady()
    string carType;
   output "Enter car type or , QUIT, to quit: ";
   input carType;
return carType;

---------------------------------------------------------------------------------------------------------------------

C++ code of above pseudo-code :
//main.cpp
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
string getReady();
int main()
{

   string carType;
   int days;
   float rate=0;
   float discount=0;

   int STD_RATE = 65;
   int COM_RATE = 40;
   int SUB_RATE = 30;
   int DAYS_FOR_DISCOUNT = 10;
   float DISCOUNT_RATE = 0.20;
   string QUIT = "ZZZZ";


   carType=getReady();

   //Check if carType is not ZZZZ
   while(carType!=QUIT)
   {
       //read days
       cout<<"Enter days rented ";
       cin>> days;
       //Check if carType is "Standard"
       if (carType == "Standard" )
           rate = STD_RATE;
       //Check if carType is "Compact"
       else if (carType == "Compact" )
           rate = COM_RATE;
       //Check if carType is "Subcompact"
       else if (carType == "Subcompact" )
           rate = SUB_RATE;
       else
       {
           //Set rate=0
           rate = 0;
           //print a invalid car type message
           cout<<"Invalid car type"<<endl;
       }
       //Check if rate is not 0
       if (rate != 0)
       {
           cout<<"Rental Fee: $"<<rate<<endl;
           if (days >= DAYS_FOR_DISCOUNT )
           {
               discount = rate * DISCOUNT_RATE;
               cout<<"Discount Fee: $"<<discount<<endl;
               cout<<"Net fee: $"<<(rate-discount)<<endl;
           }
       }
       carType=getReady();
   }

   system("pause");
   return 0;
}

string getReady()
{
   string carType;
   cout<<"Enter car type or , QUIT, to quit: ";
   cin>>carType;
   return carType;
}

---------------------------------------------------------------------------------------------------------------------

Sample Output:


Related Solutions

NEED TO DEBUG // This pseudocode should create a report that contains an // apartment complex...
NEED TO DEBUG // This pseudocode should create a report that contains an // apartment complex rental agent's commission. The // program accepts the ID number and name of the agent who // rented the apartment, and the number of bedrooms in the // apartment. The commission is $100 for renting a three-bedroom // apartment, $75 for renting a two-bedroom apartment, $55 for // renting a one-bedroom apartment, and $30 for renting a studio // (zero-bedroom) apartment. Output is the...
NEED TO DEBUG // This pseudocode should create a list that describes annual profit // statistics...
NEED TO DEBUG // This pseudocode should create a list that describes annual profit // statistics for a retail store. Input records contain a department // name (for example, “Cosmetics”) and profits for each quarter for // the last two years. The program should determine whether // the profit is higher, lower, or the same // for this full year compared to the last full year. start Declarations string department num salesQuarter1ThisYear num salesQuarter2ThisYear num salesQuarter3ThisYear num salesQuarter3ThisYear num salesQuarter1LastYear...
I NEED THIS IN PSEUDOCODE: SWITCH/CASE 2 - Complete the pseudocode below by including a SWITCH...
I NEED THIS IN PSEUDOCODE: SWITCH/CASE 2 - Complete the pseudocode below by including a SWITCH statement that takes the user input (an integer between 26-30) and prints out a count up in its English equivalent. For example: if the user inputs “26”, the code will print “twenty-six”, “twenty-seven” on the next line, and so on up to “thirty”. If the user inputs “30”, the code will print “thirty” and finish. CREATE inputNum PRINT ("Please enter a number between 26-30...
i need a pseudocode for a program in java that will convert dollars into euros and...
i need a pseudocode for a program in java that will convert dollars into euros and japanese yen using the print and prinln methods an if, if -else, statement a switch statement a while statement utilizes the file class uses the random class and random number generator and uses at least three methods other than main
I need to determine whether an existing business should take on a new expansion or not....
I need to determine whether an existing business should take on a new expansion or not. What would be the layout for the cash flow statement? Do I enter the details for both the existing business and the expansion separately in the one cash flow?
Hi, I need a Matlab code satisfies the following question. Output should be a graph similar...
Hi, I need a Matlab code satisfies the following question. Output should be a graph similar to a sine or cosine graph or similar to electrocardiograms (EKG/ECG) graph. Please I'd appreciate it. All love. Thanks :) In elementary quantum mechanics, the square well is used to model the behavior of a bound particle, in which one or more forces (external potentials, interaction with other particles, etc) prevent or restrict its ability to move about. We have seen in class that...
I need this in pseudocode: Similar to the previous assignment, you’re going to read in the...
I need this in pseudocode: Similar to the previous assignment, you’re going to read in the number of years the player played and the starting year of that player – followed by the statistics for those years. This time, however, you’re going to print out the years from worst to best in sorted order. Hint: this will require a second array to store years. If you can sort one array, can you sort both? Sample Output #1: Enter the number...
I need assistance on this problem in Pseudocode and in C++ Program 1: Stay on the...
I need assistance on this problem in Pseudocode and in C++ Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we...
I need a good pseudocode for C++ for a tic tac toe program.
I need a good pseudocode for C++ for a tic tac toe program.
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {   ...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {    public static void main(String[] args) {        //Generate random array for test and copy that into 3 arrays        int[] arr1=new int[20];        int[] arr2=new int[20];        int[] arr3=new int[20];        int[] arr4=new int[20];        Random rand = new Random();        for (int i = 0; i < arr1.length; i++) {            //Generate random array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT