Skip to content

Instantly share code, notes, and snippets.

Created April 29, 2014 12:15
Show Gist options
  • Save anonymous/11398448 to your computer and use it in GitHub Desktop.
Save anonymous/11398448 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
/*
Programming Assignment 02
This program will accept, from the user, the type of recreational equipment being rented, as well as the duration of the rental. It will then display a summary of the sale, first listing the duration of the rental, then the recreational equipment being rented, and then the total cost of the rental.
Program Preconditions
1. The user will enter the type of equipment rental, which will be S for skateboard, I for inline skates, T for touring bike, or M for mountain bike.
2. The user must enter the duration of the rental, in minutes, which should be a whole number between 1 and 720.
Program Postconditions
1. The program will display the duration of rental, in minutes.
2. The program will display the type of equipment rental, which will be skateboard, inline skates, touring bike or mountain bike.
3. The program will display the total cost of the rental in dollars (if any) and cents (if any).
*/
char get_equipment_type();
int get_rental_duration();
int compute_rental_cost(char type, int time);
void report_rental_cost(char type, int time, int price);
int main() {
//Display the words "Trail Rentals Cashiering Program, version 1.0 (c) Ping, 2014" on the computer //monitor.
cout << "Trail Rentals Cashiering Program, version 1.0" << endl;
cout << "(c) Ping, 2014" << endl;
char type; //type of equipment rented
int time; //time in minutes of rental
int price; //price of rental in cents
type = get_equipment_type();
time = get_rental_duration();
price = compute_rental_cost(type, time);
report_rental_cost(type, time, price);
//Display the words "Finishing Trail Rentals Cashiering Program, version 1.0
cout << "Finishing Trail Rentals Cashiering Program, version 1.0" << endl;
}
//This function asks the user for the equipment type, and returns that type as either an ’s’
//(for //skateboard), ’i’ (for inline skate), ’t’ (for touring bike), or ’m’ (for mountain bike).
char get_equipment_type() {
char userresponse;
char type;
//Display the words "Enter the type of rental, S(kateboard), I(nline skate), T(ouring bike, or
//M(ountain //bike):" on the computer monitor.
cout << "Enter the type of rental," << endl;
cout << "S(kateboard), I(nline skate), T(ouring bike), or M";
cout << "(ountain bike): " << endl;
cin >> userresponse;
if ((userresponse == ’s’) || (userresponse == ’S’))
type = ’s’;
else if ((userresponse == ’i’) || (userresponse == ’I’))
type = ’i’;
else if ((userresponse == ’t’) || (userresponse == ’T’))
type = ’t’;
else
type = ’m’;
return type;
}
//This function asks the user for the duration of the rental, in minutes,
//and returns that number.
int get_rental_duration() {
int userresponse;
int time;
//Display the words "Enter the duration of the rental in minutes:" on the
//computer monitor.
cout <<"Enter the duration of rental in minutes: ";
cin >> userresponse;
if ((userresponse > 0) && (userresponse < 721))
time = userresponse;
else
time = 60;
return time;
}
//This function accepts the equipment type (’s’, ’i’, ’t’, or ’m’) and the
//duration of the rental, and returns //the cost of the rental in dollars
//(if any) and cents (if any).
int compute_rental_cost(char type, int time) {
int cost;
if ((type = ’s’) || (type = ’i’))
cost = time * 15;
else if (type = ’t’)
cost = time * 17;
else if ((type = ’m’) && (time <= 60))
cost = 900;
else ((type = ’m’) && (time >60));
cost = 900 + ((time −60) * 19);
return cost;
}
//This function accepts the equipment type (’s’, ’i’, ’t’, or ’m’) and the
//total cost. It will then convert the //total cost of the rental to dollars
//(if any) and cents (if any), and display the information to the user in a
//well−formatted Englist language sentence.
void report_rental_cost(char type, int time, int price) {
int dollarcost;
int centcost;
//Calculate the total amount of dollars (if any) and cents (if any)
if (price < 100)
centcost = price;
else (price > 100);
dollarcost = price / 100;
centcost = (price % 100) / 100;
cout << "This ";
cout << time;
cout << " minute ";
cout << type;
cout << " rental will cost ";
if ((dollarcost = 0) && (centcost > 1))
cout << centcost << " cents." << endl;
else if ((dollarcost = 1) && (centcost > 1))
cout << dollarcost << " dollar and " <<
cout << centcost << " cents." << endl;
else if ((dollarcost >= 1) && (centcost = 0))
cout << dollarcost << " dollars." << endl;
else if ((dollarcost >= 1) && (centcost = 1))
cout << dollarcost << " dollars and " <<
cout << centcost << " cent." << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment