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
|
#include <iostream>
#include <string>
int displayMenu();
void displayDescriptionPackages();
void packageA(std::string&, char[], int, double);
void packageB(std::string&, char[], int, double);
void packageC(std::string&, char[], int, double);
void displayBill(std::string, char[], int, int&, double);
enum menuChoices { PACKAGE_A = 1, PACKAGE_B, PACKAGE_C, EXIT };
int main()
{
std::string customerName{};
char package[]{ 'A', 'B', 'C' };
int hours{};
double total{};
bool keepLooping{ true };
while (keepLooping)
{
int choice{ displayMenu() };
std::cin.ignore();
std::cout << "Input the name of the customer: ";
std::getline(std::cin, customerName);
switch (choice)
{
case PACKAGE_A:
packageA(customerName, package, choice, total) ;
keepLooping = true;
break;
case PACKAGE_B:
packageB(customerName, package, choice, total);
keepLooping = true;
break;
case PACKAGE_C:
packageC(customerName, package, choice, total);
keepLooping = true;
break;
case EXIT:
std::cout << "Program ending.\n";
keepLooping = false;
break;
default:
std::cout << "Your choice " << choice << " is incorrect.\n";
std::cout << "Your choices are between " << PACKAGE_A <<
" and " << EXIT << std::endl;
}
}
return 0;
}
int displayMenu()
{
int choice{};
std::cout << "\n\t\t\t==========Internet Service Provider==========\n";
std::cout << "\t\t\t----------------------------\n";
std::cout << "\t\t\t1. Package A.\n";
std::cout << "\t\t\t2. Package B.\n";
std::cout << "\t\t\t3. Package C.\n";
std::cout << "\t\t\t4. Exit the Program\n";
std::cout << "\t\t\t------------------------------------------------\n";
displayDescriptionPackages();
std::cout << "\nSelect the package the customer wants: ";
std::cin >> choice;
return choice;
}
void displayDescriptionPackages()
{
std::cout << "\n\t\t\t==========Description==========\n";
std::cout << "\t\t\t----------------------------\n";
std::cout << "\t\t\t Package A.\n";
std::cout << "\t\t\t - $9.95 per month.\n";
std::cout << "\t\t\t - 5 hours access.\n";
std::cout << "\t\t\t - Additional minutes are $0.08\n";
std::cout << "\t\t\t Package B.\n";
std::cout << "\t\t\t - $14.95 per month.\n";
std::cout << "\t\t\t - 10 hours access.\n";
std::cout << "\t\t\t - Additional minutes are $0.06\n";
std::cout << "\t\t\t Package C.\n";
std::cout << "\t\t\t - $19.95 per month.\n";
std::cout << "\t\t\t - Unlimited Access.\n";
}
void packageA(std::string &name, char package[], int choice, double total)
{
const double price{ 9.95 };
const int hoursAccess{ 5 };
const double costPerMin{ 0.08 };
const int totalMinsIntoHrs{ 60 };
int hours{};
std::cout << "How many hours " << name << " used: ";
std::cin >> hours;
if (hours > hoursAccess)
{
total = price + ((hours - hoursAccess) * (costPerMin * totalMinsIntoHrs));
}
else
total = price;
displayBill(name, package, choice, hours, total);
}
void packageB(std::string &name, char package[], int choice, double total)
{
const double price{ 14.95 };
const int hoursAccess{ 10 };
const double costPerMin{ 0.06 };
const int totalMinsIntoHrs{ 60 };
int hours{};
std::cout << "How many hours " << name << " used: ";
std::cin >> hours;
if (hours > hoursAccess)
{
total = price + ((hours - hoursAccess) * (costPerMin * totalMinsIntoHrs));
}
else
total = price;
displayBill(name, package, choice, hours, total);
}
void packageC(std::string &name, char package[], int choice, double total)
{
const double price{ 19.95 };
int hours{};
total = price;
displayBill(name, package, choice, hours, total);
}
void displayBill(std::string name, char package[], int choice, int &hours, double total)
{
if (choice == PACKAGE_C)
{
std::cout << "\n\t\t\t==================Payment Due================\n";
std::cout << "\t\t\t-----------------------------------------------\n";
std::cout << "\t\t\t Customer Name: " << name << " .\n";
std::cout << "\t\t\t Package " << package[choice - 1] << " .\n";
std::cout << "\t\t\t Hours Used: UNLIMITED .\n";
std::cout << "\t\t\t Total Amount Due: " << total << " .\n";
std::cout << "\t\t\t------------------------------------------------\n";
}
else
{
std::cout << "\n\t\t\t==================Payment Due================\n";
std::cout << "\t\t\t-----------------------------------------------\n";
std::cout << "\t\t\t Customer Name: " << name << " .\n";
std::cout << "\t\t\t Package " << package[choice - 1] << " .\n";
std::cout << "\t\t\t Hours Used: " << hours << " .\n";
std::cout << "\t\t\t Total Amount Due: " << total << " .\n";
std::cout << "\t\t\t------------------------------------------------\n";
}
}
|