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 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
// Program description: This program will calculate the cost of a guest staying at a hotel.
// *******************************************************************************************
#include <iostream>
#include <fstream>
using namespace std;
float mCost(float, float, float, float);
float nCost(float, float, float);
char getMembership();
float calcDiscount(float, float);
int main()
{
int nights, room, rCost, memberType, buffet, bCost, total;
char isMember = getMembership();
float discountCost;
float memberDiscount;
if(isMember == 'M' || isMember == 'm')
{
do{
cout << "Please enter number of nights stayed at hotel." << endl;
cin >> nights;
cout << "Please select type of room used, 1 = Economy Room, 2 = Standard Room, 3 = Luxury Room." << endl;
cin >> room;
if(room == 1)
{
rCost = 70;
}
if(room == 2)
{
rCost = 100;
}
if(room == 3)
{
rCost = 150;
}
cout << "Please enter type of membership used, 1 = Gold, 2 = Bronze, 3 = Silver." << endl;
cin >> memberType;
if(memberType == 1)
{
memberDiscount = .150;
}
if(memberType == 2)
{
memberDiscount = .100;
}
if(memberType == 3)
{
memberDiscount = .050;
}
}
while(nights == 0 || room == 0);
}
discountCost = mCost(rCost, nights, memberDiscount, total);
if(isMember == 'N' || isMember == 'n')
{
do{
cout << "Please enter number of nights stayed at hotel." << endl;
cin >> nights;
cout << "Please select type of room used, 1 = Economy Room, 2 = Standard Room, 3 = Luxury Room." << endl;
cin >> room;
if(room == 1)
{
rCost = 70;
}
if(room == 2)
{
rCost = 100;
}
if(room == 3)
{
rCost = 150;
}
cout << "Please select if you ate at the breakfast buffet while staying at hotel, 1 = Yes, 2 = No." << endl;
cin >> buffet;
if(buffet == 1)
{
bCost = 10;
}
if(buffet == 2)
{
bCost = 0;
}
}
while(nights == 0 || room == 0);
}
float nTotalCost = nCost(rCost, bCost, nights);
ofstream myfile ("HotelInvoice.txt");
if (myfile.is_open())
{
myfile << "This is the total member cost: $" << discountCost << endl;
myfile << "This is the total non-member cost: $" << nTotalCost << endl;
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
//**********************************************************************************
// void membership
// this function returns a char to show whether a customer is a member or not
//
// return value
// ------------------
// char
//
// Parameters
// ------------------
// *********************************************************************************
char getMembership()
{
char letter;
cout << "Enter your choice (M = Member or N = Non-member): " << endl;
cin >> letter;
while(letter != 'M' && letter != 'm' && letter != 'N' && letter != 'n')
{
cout << "Please enter M or N: " << endl;
cin >> letter;
return letter;
}
}
//****************************************************************
// void mCost*
// This function calculates the cost of stay for members
//
// return value
// ---------------
// float
//
// Parameters
// ---------------
// float rCost, float nights
//****************************************************************
float mCost(float rCost, float nights, float total, float memberDiscount)
{
float mTotal = rCost*nights;
float dTotal = calcDiscount(total, memberDiscount);
return dTotal;
}
//****************************************************************
// void calcDiscount
// This function calculates the discount for members
//
// return value
// ---------------
// float
//
// Parameters
// ---------------
// float total, float memberDiscount
//****************************************************************
float calcDiscount(float total, float memberDiscount)
{
float discount = total*memberDiscount;
float discountTotal = total-discount;
return discountTotal;
}
//****************************************************************
// void nCost
// This function calculates the cost of stay for non-members
//
// return value
// ---------------
// float
//
// Parameters
// ---------------
// float rCost, float bCost, float nights
//****************************************************************
float nCost(float rCost, float bCost, float nights)
{
float total = (bCost*nights)+(rCost*nights);
return total;
}
|