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
|
#include <iostream>
#include <iomanip>
using namespace std;
void SetupConsole(void);
void GetUserInput(int &nDays, int &nShipType);
double GetBasePrice(int nShipType);
double GetMarkupPrice(double dMSRP, int nDays);
void DisplayResult(double dMSRP, double dMarkupPrice, int nDays, int nShipType);
int main()
{
int nDays;
int nShipType;
SetupConsole();
GetUserInput(nDays, nShipType);
double dMSRP = GetBasePrice(nShipType);
double dMarkUpPrice = GetMarkupPrice(dMSRP, nDays);
DisplayResult(dMSRP, dMarkUpPrice, nDays, nShipType);
}
void SetupConsole(void)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
}
void GetUserInput(int &nDays, int &nShipType)
{
cout << "Hello, welcome to the automated ship building system";
cout << "brought to you by Clay and Class Inc. What type of";
cout << "ship do you want?" << endl << endl;
cout << "1) Frigate" << endl;
cout << "2) Container" << endl;
cout << "3) Fishing" << endl;
cout << "4) Weather" << endl;
cout << "Ship selection: ";
cin >> nShipType;
while (nShipType >= 5)
{
cout << "Ship selection: ";
cin >> nShipType;
}
if (nShipType == 1)
{
cout << "You chose a frigate ship!" << endl;
}
else if (nShipType == 2)
{
cout << "You chose a container ship!" << endl;
}
else if (nShipType == 3)
{
cout << "You chose a fishing ship!" << endl;
}
else if (nShipType == 4)
{
cout << "You chose a weather ship!" << endl;
}
cout << "Enter the number of days until the deadline: ";
cin >> nDays;
while (nDays < 90)
{
cout << "Sorry, can't do that! Try asking";
cout << "something more reasonable." << endl;
cout << "Enter the number of days until the deadline: ";
cin >> nDays;
}
if (nDays >= 90)
{
return;
}
}
double GetBasePrice(int nShipType)
{
if (nShipType == 1)
{
return 100000;
}
else if (nShipType == 2)
{
return 500000;
}
else if (nShipType == 3)
{
return 350000;
}
else if (nShipType == 4)
{
return 600000;
}
}
double GetMarkupPrice(double dMSRP, int nDays)
{
if (nDays < 90)
{
return(-1);
}
else if (nDays < 180)
{
return(2 * dMSRP);
}
else if (nDays < 240)
{
return(1.5 * dMSRP);
}
else if (nDays <= 360)
{
return(dMSRP);
}
else if (nDays > 360)
{
return(.85 * dMSRP);
}
}
void DisplayResult(double dMSRP, double dMarkupPrice, int nDays, int nShipType)
{
if (nShipType == 1)
{
cout << "frigate" << endl;
}
else if (nShipType == 2)
{
cout << "container" << endl;
}
else if (nShipType == 3)
{
cout << "fishing" << endl;
}
else if (nShipType == 4)
{
cout << "weather" << endl;
}
cout << "Here is the calculated cost for a ";
cout << nShipType << " ship." << endl;
cout << "Maximum days of labor: " << setw(22) << nDays << endl;
cout << "Base price per ship $: " << setw(22) << dMSRP << endl;
cout << "Mark up price $: " << setw(22) << dMarkupPrice << endl;
cout << "Please send your check to Clay and Class Inc, ";
cout << "5150 Rich St.";
}
| |