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
|
#include <string.h>
#include <cmath>
#include <iostream>
using namespace std;
struct sPrice {bool student; bool disabled; int age; double price;};
struct sPrice SetParameters (bool student, bool disabled, int age, double price)
{
struct sPrice pr;
pr.student = student;
pr.disabled = disabled;
pr.age = age;
pr.price = price;
return (pr);
}
struct sPassenger {int age; bool student; bool disabled; int from; int to;};
int main()
{
int age; bool student; bool disabled; int from; int to;
cout << "Please Enter Your Age (0 - 150)" << endl;
cin >> age;
do
{
cout << "Please Enter Your Age Again (0 - 150)" << endl;
cin >> age;
}
while (age < 0 || age > 150);
if ( age > 12 && age < 65) age = 0;
else if ( age >= 65) age = 1;
else if ( age <= 12) age = 2;
cout << "Are you Disabled (Y/N)?" << endl;
char answer1;
cin >> answer1;
switch( answer1 )
{
case 'Y': case 'y':
disabled = true;
break;
case 'N': case 'n':
disabled = false;
break;
}
cout << "Are you a Student (Y/N)?" << endl;
char answer2;
cin >> answer2;
switch( answer2 )
{
case 'Y': case 'y':
student = true;
break;
case 'N': case 'n':
student = false;
break;
}
cout << "From (1)Taipei, (2)Taichung, (3)Tainan:" << endl;
cin >> from;
cout << "To (1)Taipei, (2)Taichung, (3)Tainan:" << endl;
cin >> to;
struct sPrice pr[11];
pr[0] = SetParameters (true, true, 0, 2.8);
pr[1] = SetParameters (true, true, 1, 1.7);
pr[2] = SetParameters (true, true, 2, 1.8);
pr[3] = SetParameters (true, false, 0, 3.6);
pr[4] = SetParameters (true, false, 1, 2.9);
pr[5] = SetParameters (true, false, 2, 1.9);
pr[6] = SetParameters (false, true, 0, 3.3);
pr[7] = SetParameters (false, true, 1, 2.0);
pr[8] = SetParameters (false, true, 2, 2.2);
pr[9] = SetParameters (false, false, 0, 5.6);
pr[10] = SetParameters (false, false, 1, 3.7);
pr[11] = SetParameters (false, false, 2, 3.2);
{
struct sPassenger ps;
ps.age = age;
ps.student = student;
ps.disabled = disabled;
}
bool satisfy (struct sPassenger ps, struct sPrice pr[11]);
{
}
double CheckPrice(struct sPassenger ps, struct sPrice pr[11],int size);
{
}
double distance;
if (from == 1 && to == 1) distance = 0;
if (from == 1 && to == 2) distance = 165.0;
if (from == 1 && to == 3) distance = 324.9;
if (from == 2 && to == 2) distance = 0;
if (from == 2 && to == 3) distance = 159.9;
if (from == 2 && to == 1) distance = 165.0;
if (from == 3 && to == 3) distance = 0;
if (from == 3 && to == 2) distance = 159.9;
if (from == 3 && to == 1) distance = 324.9;
double price;
if (age == 0 && disabled == true && student == true) price = 2.8;
else if (age == 1 && disabled == true && student == true) price = 1.7;
else if (age == 2 && disabled == true && student == true) price = 1.8;
else if (age == 0 && disabled == false && student == true) price = 3.6;
else if (age == 1 && disabled == false && student == true) price = 2.9;
else if (age == 2 && disabled == false && student == true) price = 1.9;
else if (age == 0 && disabled == true && student == false) price = 3.3;
else if (age == 1 && disabled == true && student == false) price = 2.0;
else if (age == 2 && disabled == true && student == false) price = 2.2;
else if (age == 0 && disabled == false && student == false) price = 5.6;
else if (age == 1 && disabled == false && student == false) price = 3.7;
else if (age == 2 && disabled == false && student == false) price = 3.2;
double ticketprice;
ticketprice = price * distance;
printf ("Your Ticket Price is $ %.2f\n" , ticketprice);
return (0);
}
|