1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
struct video{
char name[50],
formatChar[15],
isReturned;
int releaseYear,
rentalLength,
format,
menuOption;
float rentalCost,
money;
bool inDebt,
hasMovie;
void menu(){
hasMovie = false;
money = getMoney();
cout << "Welcome to the video store. What would you like to do?\n";
if (hasMovie == false){
cout << "1. Rent a movie.\n" <<
"2. Exit the store.\n";
cin >> menuOption;
switch(menuOption){
case 1:
getRentalInfo();
break;
case 2:
leaveStore();
break;
}
}
else {
cout << "1. View your rental information.\n" <<
"2. Wait a day.\n" <<
"3. Exit the store.\n";
cin >> menuOption;
switch(menuOption){
case 1:
printInfo();
break;
case 2:
advanceTime();
break;
case 3:
leaveStore();
}
}
}
void getRentalInfo(){
cout << "What is the name of the movie you'd like to rent?\n";
cin.getline(name,50);
cout << "What year was it released?\n";
cin >> releaseYear;
cin.clear();
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
cout << "How many days would you like to rent it for?\n";
cin >> rentalLength;
cin.clear();
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
format = getFormat();
rentalCost = getRentalCost();
printInfo();
hasMovie = true;
}
float getMoney(){
float num = rand() % 21 + 10.0;
return num;
}
int getFormat(){
while(true){
cout << "What movie format would you like to rent?\n" <<
"1. VHS\n" <<
"2. DVD\n" <<
"3. Blu-ray\n";
cin >> format;
switch(format){
case 1:
cout << "You have chosen to rent a VHS.\n";
strcpy(formatChar,"VHS");
return 1;
case 2:
cout << "You have chosen to rent a DVD.\n";
strcpy(formatChar,"DVD");
return 2;
case 3:
cout << "You have chosen to rent a Blu-ray.\n";
strcpy(formatChar,"Blu-ray");
return 3;
default:
cout << "You have not selected a valid choice.\n";
break;
}
}
}
float getRentalCost(){
cout << "Costs per day are as follows:\n" <<
"VHS - $.50 per day\n" <<
"DVD - $1.00 per day\n" <<
"Blu-ray - $1.50 per day\n";
rentalCost = rentalLength*format*.50;
cout << "Therefore, renting " << name << " for " << rentalLength << " days will cost " << rentalCost << " dollars.\n";
return rentalCost;
}
void printInfo(){
if (hasMovie == false){
if (rentalCost > money){
inDebt = true;
cout << "You can't afford this. Leave.";
leaveStore();
}
else {
cout << "You are renting " << name << " (" << releaseYear << ").\n" <<
"It is a " << formatChar << ".\n" <<
"You are renting it for " << rentalLength << " days, which will cost you " << rentalCost << " dollars.";
}
}
else {
cout << "You are renting " << name << " (" << releaseYear << ").\n" <<
"It is a " << formatChar << ".\n" <<
"You are renting it for " << rentalLength << " more days, which will cost you " << rentalCost << " dollars.\n";
if (rentalLength < 0)
cout << "IT IS LATE!\n";
}
}
void advanceTime(){
rentalLength--;
if (rentalLength <=0);
lateRental();
}
void lateRental(){
while(true){
if (rentalLength == 0)
cout << "Your movie is due! Return it today, or you will have to pay a 50% interest for every day it is late. Will you return it? (y/n)";
else
cout << "Your movie is late. Return it now, and you'll be saved tomorrow's interest. Will you return it? (y/n)";
cin >> isReturned;
if (isReturned == 'y'){
returnMovie();
break;
}
else if (isReturned == 'n'){
rentalCost += .5*rentalCost;
cout << "Fine, we'll just add the interest. If you choose to return it tomorrow, you'll owe " << rentalCost << ".\n";
break;
}
else
cout << "Not a valid entry.";
}
}
void returnMovie(){
if (inDebt == true){
cout << "You can't afford this, I'm calling the police!\n";
leaveStore();
}
else {
money -= rentalCost;
cout << "Thank you for the returning the movie. You have " << money << " dollars left.\n";
leaveStore();
}
}
void leaveStore(){
if (inDebt == true){
cout << "Goodbye, come back soon!\n";
}
else {
cout << "I hope they lock you up and throw away the key, you criminal!\n";
}
}
};
int main(){
srand(time(NULL));
video t;
t.menu();
return 0;
}
|