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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
#include <iostream>
#include <cmath>
const double PI= 3.141519;
int askForStroke();
double askForBore();
int askForVolHead();
double calculateVolEngine(double bore, int stroke);
double calculateVolChamber(double bore, int vol_head);
double calculateCompRatio(double vol_engine, double vol_chamber);
bool askForExit(char exit_condition, char repeat_condition);
int main()
{
do {
int stroke = askForStroke();
double bore = askForBore();
int vol_head = askForVolHead();
std::cout << "Your engine is " << bore << " bore x "
<< stroke << " stroke." << std::endl;
double vol_engine = calculateVolEngine(bore, stroke);
std::cout << "Your displacement is " << vol_engine
<< "cc." << std::endl;
double vol_chamber = calculateVolChamber(bore, vol_head);
std::cout << "Your heads have " << vol_chamber
<< "cc combustion chambers." << std::endl;
double comp_ratio = calculateCompRatio(vol_engine, vol_chamber);
std::cout << "Your compression ratio is " << comp_ratio << ":1" << std::endl;
if(stroke >= 78) {
if(bore >=88){
std::cout << "You will need head and case work." << std::endl;
} else { // you don't need this any more --> if (bore < 88)
std::cout <<"You will need head work." << std::endl;
}
} else { // you don't need this any more --> if (stroke >= 78)
std::cout <<"You will need case work." << std::endl;
}
if (comp_ratio >= 8.8)
std::cout <<" Your compression ratio is too high." << std::endl;
else if (comp_ratio <= 7.8)
std::cout <<"Your compression ratio is too low." << std::endl;
std::cout << "Reselect Components " << vol_engine << " "
<< comp_ratio << ":1" << std::endl;
std::cout << " a. yes" << std::endl;
std::cout << " b. no (quit)" << std::endl;
} while (askForExit('b', 'a'));
std::cout << "Thank you for using Engine build v1.0" << std::endl;
return 0;
}
int askForStroke()
{
int stroke {0};
do {
std::cout << "Customize your air cooled type I VW engine" << std::endl;
std::cout << "Select Crankshaft 0000cc 0.0:1" << std::endl;
std::cout << " a. 69 mm stock" << std::endl;
std::cout << " b. 74 mm stroker" << std::endl;
std::cout << " c. 76 mm" << std::endl;
std::cout << " d. 78 mm" << std::endl;
std::cout << " e. 82 mm" << std::endl;
char menu_pic;
std::cin >> menu_pic;
switch (menu_pic)
{
case 'a':
stroke = 69;
break;
case 'b':
stroke = 74;
break;
case 'c':
stroke = 76;
break;
case 'd':
stroke = 78;
break;
case 'e':
stroke = 82;
break;
case 'q':
std::cout << "Thanks for using Engine build v1.0" << std::endl;
break;
default:
std::cout << "oops!, Invalid Input" << std::endl;
stroke = 0;
break;
}
} while (stroke==0);
return stroke;
}
double askForBore()
{
double bore {0.0};
do {
std::cout << "Select Pistons 0000cc 0.0:1" << std::endl;
std::cout << " a. 83 mm underbore" << std::endl;
std::cout << " b. 85.5mm stock" << std::endl;
std::cout << " c. 88 mm overbore" << std::endl;
std::cout << " d. 90.5mm" << std::endl;
std::cout << " e. 92 mm" << std::endl;
std::cout << " f. 94 mm" << std::endl;
char menu_pic;
std::cin >> menu_pic;
switch (menu_pic)
{
case 'a':
bore = 83.0;
break;
case 'b':
bore = 85.5;
break;
case 'c':
bore = 88.0;
break;
case 'd':
bore = 90.5;
break;
case 'e':
bore = 92.0;
break;
case 'f':
bore = 94.0;
break;
case 'q':
std::cout << "Thanks for using Engine build v1.0" << std::endl;
break;
default:
std::cout << "oops!, Invalid Input" << std::endl;
bore = 0.0;
break;
}
} while (bore == 0.0);
return bore;
}
int askForVolHead()
{
int vol_head {0};
do {
std::cout << "Select Heads 1585cc 0.0:1" << std::endl;
std::cout << " a. 51 cc stock" << std::endl;
std::cout << " b. 53 cc stage I" << std::endl;
std::cout << " c. 56 cc stage II" << std::endl;
std::cout << " d. 60 cc stage III" << std::endl;
char menu_pic;
std::cin >> menu_pic;
switch (menu_pic)
{
case 'a':
vol_head = 51;
break;
case 'b':
vol_head = 53;
break;
case 'c':
vol_head = 56;
break;
case 'd':
vol_head = 60;
break;
case 'q':
std::cout << "Thanks for using Engine build v1.0" << std::endl;
break;
default:
std::cout << "oops!, Invalid Input" << std::endl;
vol_head = 0;
}
} while (vol_head == 0);
return vol_head;
}
double calculateVolEngine(double bore, int stroke)
{
double vol_engine = ((4*((bore/2)*(bore/2))*PI*stroke)/1000);
return vol_engine;
}
double calculateVolChamber(double bore, int vol_head)
{
double vol_chamber = ((((3/2.0)*((bore/ 2)*(bore/2))*PI)/1000)+vol_head);
return vol_chamber;
}
double calculateCompRatio(double vol_engine, double vol_chamber)
{
double comp_ratio = ((vol_engine/4/vol_chamber)+1);
return comp_ratio;
}
bool askForExit(char exit_condition, char repeat_condition)
{
while(true) {
char doagain;
std::cin >> doagain;
if (doagain == repeat_condition)
return true;
else if (doagain == exit_condition)
return false;
else
std::cout << "oops!, Invalid Input" << std::endl;
}
}
|