C++ Help! using multiple data type variable declarations, input with cin, output
ID: 3861767 • Letter: C
Question
C++ Help! using multiple data type variable declarations, input with cin, output with cout including escape characters and formatting, arithmetic operations, boolean logic, while and do while loops, if-else, nested if-else-if and/or switch branching.
Here are some fun facts related to the project. The early 70's VW beetle came with a
1585cc air cooled motor that produced 50HP. The engine is highly customizable and can be downsized
for improved mileage or upsized for massive HP gains. Some engine components are bolt on. Some
components require that you take your components to the machine shop for work before you can bolt
them on. Either way, you will need to be mindful of the engine's compression ratio (cr). When the cr is
too low, you leave power and mileage on the table. If the cr is too high, your engine will be prone to
preignition, otherwise known as knock or ping. You will not be tested on the background.
Understanding of the background is not necessary for project completion.
Tasks:
You will need to compute several quantities.
1. The first is the engine volume (vol_engine):
(4*((bore/2)^2)*pi*stroke)/1000
2. The second is the combustion chamber volume (vol_chamber):
(((3/2)*((bore/2)^2)*pi)/1000)+head volume
3. The final quantity is the compression ratio (comp_ratio):
(engine volume/4/combustion chamber volume)+1
All pistons 88mm and larger require head machine work. All pistons 90.5mm and larger require case machine work. All strokes 78mm and larger require case machine work. All compression ratios 8.8 and higher are too high. All compression ratios 7.8 and lower are too low. The menus will accept menu pick q at any prompt as a way to terminate the program. Invalid menu picks simply redisplay the current menu
Consistency issues: In order to avoid total chaos in variable naming and typing, use the following:
Variable Name
Data type
vol_engine
Double
vol_chamber
Double
vol_head
Integer (from heads menu)
stroke
Integer (from crankshaft menu)
bore
Double (from pistons menu)
comp_ratio
Double
menu_pic
char (user input)
PI
double (3.14159)
Output:
Your output must conform strictly to the output format included with this document. You must use tabs
for alignment. Items in italics and underlined are user inputs. Items in smaller font are instructional and
are not to be output. Sample output follows.
Expected Output 1:
Customize your air cooled type I VW engine
Select Crankshaft 0000cc 0.0:1
a. 69 mm stock
b. 74 mm stroker
c. 76 mm
d. 78 mm
e. 82 mm
> a
Select Pistons 0000cc 0.0:1
a. 83 mm underbore
b. 85.5mm stock
c. 88 mm overbore
d. 90.5mm
e. 92 mm
f. 94 mm
> b
Select Heads 1585cc 0.0:1
a. 51 cc stock
b. 53 cc stage I
c. 56 cc stage II
d. 60 cc stage III
> a
your engine is 85.5 bore x 69 stroke
your displacement is 1585cc
your heads have 51cc combustion chambers
your compression ratio is 7.6:1
(if applicable, one of the following two. Don't output this line)
your compression ratio is too low
your compression ratio is too high
(if applicable, one of the following three. Don't output this line)
you will need head work
you will need case work
you will need case and head work
Reselect Components 1585cc 7.6:1
a. yes
b. no (quit)
> c
oops!, Invalid Input
Reselect Components 1585cc 7.6:1
a. yes
b. no (quit)
> b
Thanks for using Engine build v1.0
Variable Name
Data type
vol_engine
Double
vol_chamber
Double
vol_head
Integer (from heads menu)
stroke
Integer (from crankshaft menu)
bore
Double (from pistons menu)
comp_ratio
Double
menu_pic
char (user input)
PI
double (3.14159)
Explanation / Answer
#include <iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
int main(){
int stroke,heads;
double bore,PI=3.14159,comp_ratio,vol_engine,vol_chamber,vol_head;
char menu_pic;
do{
cout<<"Customize your air cooled type I VW engine "<<endl;
do{
cout<<"Select Crankshaft 0000cc 0.0:1" <<endl;
cout<<"a.69 mm stock b.74 mm stroker c.76 mm d.82 mm >";
cin>>menu_pic;}while(menu_pic !='a' && menu_pic !='b' && menu_pic!='c' && menu_pic!='d'&& menu_pic!='q');
if(menu_pic == 'a'){
stroke = 69;}else if(menu_pic == 'b'){stroke=74;}else if (menu_pic == 'c'){stroke=76;}else if(menu_pic == 'd'){stroke=82;}else if ( menu_pic=='q'){cout<<"Exiting program "; exit(0);}else{cout<<"Invalid entry/n";}
do{
cout<<"Select Pistons 0000cc 0.0:1 ";
cout<<"a.83 mm underbore b.85.5 mm stock c.88 mm overbore d.90.5 mm e.92 mm f. 94 mm >";
cin>>menu_pic;
}while(menu_pic !='a' && menu_pic !='b' && menu_pic!='c' && menu_pic!='d'&& menu_pic!='e' && menu_pic!='f'&&menu_pic!='q');
if(menu_pic == 'a'){
bore = 83;}else if(menu_pic == 'b'){bore=85.5;}else if (menu_pic == 'c'){bore=88;}else if(menu_pic == 'd'){bore=90.5;}else if (menu_pic == 'e'){bore=92;}else if(menu_pic == 'f'){bore=94;}else if ( menu_pic=='q'){cout<<"Exiting program "; exit(0);}else{cout<<"Invalid entry/n";}
do{
cout<<"Select Heads 1585cc 0.0:1 ";
cout<<"a.51 heads stock b.53 heads stage I c.56 heads stage II d.60 heads stage III >";
cin>>menu_pic;}while(menu_pic !='a' && menu_pic !='b' && menu_pic!='c' && menu_pic!='d'&&menu_pic!='q');
if(menu_pic == 'a'){
heads = 51;}else if(menu_pic == 'b'){heads=53;}else if (menu_pic == 'c'){heads=56;}else if(menu_pic == 'd'){heads=60;}else if ( menu_pic=='q'){cout<<"Exiting program "; exit(0);}else{cout<<"Invalid entry/n";}
cout<<"your engine is " <<bore <<"bore x "<<stroke <<" stroke"<<endl;
cout<<"your displacement is 1585 heads"<<endl;
cout<<"your heads have "<<heads <<"heads combustion chambers ";
vol_engine=(4*(pow(bore/2,2))*PI*stroke)/1000;
vol_chamber=((3/2)*(pow(bore/2,2)*PI)/1000)+heads;
comp_ratio=(vol_engine/4/vol_chamber)+1;
cout<<"your compression ratio is"<<comp_ratio<<":1 ";
if(comp_ratio>=8.8){
cout<<"your compression ratio is too high ";}
else if(comp_ratio<=7.8){
cout<<"your compression ratio is too low ";}
if(bore>=88){cout<<"require head machine work ";}else if(bore>=90.5){cout<<"require case machine work ";}else if(stroke>=78){cout<<"requires case machine work ";}else{}
do{
cout<<"Reselect components 1585cc a.yes b.no(quit) >";
cin>>menu_pic;}while( menu_pic !='a' && menu_pic!='b' &&menu_pic!='q');
if(menu_pic=='a' || menu_pic == 'b'){}else if ( menu_pic=='q'){cout<<"Exiting program "; exit(0);}else{cout<<"Invalid entry/n";}
}while(menu_pic!='b');
if(menu_pic== 'b'){cout<<"Thanks for using Engine Build v1.0 ";}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.