Created
September 15, 2016 02:22
-
-
Save gegagome/009487e264af0649dbf47f309d8c8e91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| #include "PaceCalculator.h" | |
| int main(int argc, const char * argv[]) { | |
| cout.setf(ios::fixed); | |
| cout.setf(ios::showpoint); | |
| cout.precision(2); | |
| int input = 0; | |
| PaceCalculator paceCalculator; | |
| paceCalculator.programIntent(); | |
| paceCalculator.userPrompt(); | |
| cin >> input; | |
| if (input == 1) { | |
| double value = 0.0; | |
| paceCalculator.promptForKPH(); | |
| cin >> value; | |
| cout << paceCalculator.convertToMPH(value) << " KPH" << endl; | |
| } else if (input ==2) { | |
| int value1, value2; | |
| paceCalculator.promptForMinutes(); | |
| cin >> value1; | |
| paceCalculator.promptForSeconds(); | |
| cin >> value2; | |
| cout << paceCalculator.convertToMPH(value1, value2) << " MPH" << endl; | |
| } else { | |
| cout << "Enter a valid value" << endl; | |
| } | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <string> | |
| using namespace std; | |
| #include "PaceCalculator.h" | |
| double PaceCalculator::convertToMPH (double kph) { | |
| return kph / KILOS_IN_MILE; | |
| } | |
| double PaceCalculator::convertToMPH (int minutes, int seconds) { | |
| int timeInseconds = (minutes * 60) + seconds; | |
| double resultInMPH = SECONDS_IN_HOUR / double(timeInseconds); | |
| return resultInMPH; | |
| } | |
| void PaceCalculator::userPrompt () { | |
| cout << "\n\n---- INSTRUCTIONS ----" << endl; | |
| cout << "1 - Enter 1 for your \npace in KPH" << endl; | |
| cout << "2 - Enter 2 for your \nminutes or seconds per\nmile.\n" << endl; | |
| } | |
| void PaceCalculator::programIntent() { | |
| cout << "***********************" << endl; | |
| cout << "*** PACE CALCULATOR ***" << endl; | |
| cout << "***********************" << endl; | |
| cout << endl; | |
| cout << "Calculate your pace in " << endl; | |
| cout << "miles per hours or your" << endl; | |
| cout << "pace in kph" << endl; | |
| } | |
| void PaceCalculator::promptForKPH () { | |
| cout << "\nEnter your pace in KPH" << endl; | |
| } | |
| void PaceCalculator::promptForMinutes () { | |
| cout << "\nEnter your minutes" << endl; | |
| } | |
| void PaceCalculator::promptForSeconds () { | |
| cout << "\nEnter your seconds" << endl; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef PaceCalculator_h | |
| #define PaceCalculator_h | |
| #include <iostream> | |
| #include <string> | |
| using namespace std; | |
| #include <stdio.h> | |
| class PaceCalculator { | |
| public: | |
| const double KILOS_IN_MILE = 1.61; | |
| const int SECONDS_IN_HOUR = 3600; | |
| double convertToMPH (double); | |
| double convertToMPH (int, int); | |
| void programIntent (); | |
| void userPrompt (); | |
| void promptForKPH (); | |
| void promptForMinutes (); | |
| void promptForSeconds (); | |
| private: | |
| }; | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment