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<iostream>
using namespace std;
//Function prototypes
void announce();
float getStart(float startHours, float startMinutes);
int getDistance(float distance);
void getCommand();
float getFinish(float finishHours, float finishMinutes);
float conv2knotsKm(float speed);
int main()
{
// Announce the program.
announce();
// define variables
float startHours, startMinutes, distance, finishHours, finishMinutes,speed;
//Display menu and Prompt for a command.
char cmd;
getCommand();
cin >> cmd;
switch(cmd){
case 'd':
case 'D':
cout << getDistance(distance);
break;
case 's':
case 'S':
cout << getStart( startHours, startMinutes);
break;
case 'f':
case 'F':
cout << getFinish( finishHours, finishMinutes);
cout << conv2knotsKm( speed);
break;
case 'q':
case 'Q':
cout << "quiting the program"<< endl;
break;
default:
cout << "Error - Wrong Choice"<< endl;
}
}
//--------------------------------------------------------------------------------------------------------------
// "announce " this function announces the program and prints out the instructions for the user at the
// start of new race.
//----------------------------------------------------------------------------------------------------------------
void announce(){
cout<<" YachtRace : A yacht race program calculates the average speed of the \n"
"yacths in a race over the distance of 100 nautical miles."<<endl;
}
// Gets the start time convert it into minutes.
float getStart(float startHours, float startMinutes){
cout << "Enter a new start time (08:00 - 17:00):";
cin >> startHours;
//startHours = startHours / 100;
startHours = (int)startHours % 100;
//startMinutes = startHours / 60;
startMinutes = (int)startHours % 60;
cout << startMinutes << "minutes" << endl;
return startMinutes;
}
// Prompt for and get the distance.
int getDistance (float distance){
cout << " Enter the distance in NM: ";
cin >> distance;
return distance;
}
// Display the command menu.
void getCommand ( ){
cout<< "Command menu:\n";
cout<< "D - Distance:Enter a distance (in nautica miles, max 100)\n";
cout<< "S - Start Time: enter a new start race time( 8:00:00 - 17:00:00)\n";
cout<< "F - Finish Time: Enter the yacht finish time and display the speed\n";
cout<< "Q - Quits the program\n";
}
// promt for and get the finish time change it into minutes.
float getFinish (float finishHours, float finishMinutes){
cout << "Enter a finish time start time + 24 hours: ";
cin >> finishHours;
//finishHours = finishHours / 100;
finishHours = (int)finishHours % 100;
//finishMinutes = finishHours / 60;
finishMinutes = (int)finishHours % 60;
cout << finishMinutes << "minutes" << endl;
return finishMinutes;
}
// calculates the average speed in knots and km.
float conv2knotsKm(float speed){
float finishMinutes;
float startMinutes;
float distance;
float velocity;
speed = distance/( finishMinutes - startMinutes);//average speed in knots.
speed = speed * 60;
velocity = 7.5 * 1.852;// average speed in km/h.
return speed, velocity;
}
|