Advertisement
riggnaros

ClockType

Feb 9th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. //clockType class
  7.  
  8. class clockType {
  9. private:
  10.     int hours;
  11.     int minutes;
  12.     int seconds;
  13.  
  14. public:
  15.     clockType(int clockHrs = 00, int clockMins = 00, int clockSecs = 00);
  16.     void setHours(int clockHrs);
  17.     void setMinutes(int clockMins);
  18.     void setSeconds(int clockSecs);
  19.     void showTime();
  20.  
  21.     int getHours();
  22.     int getMinutes();
  23.     int getSeconds();
  24. };
  25.  
  26. //constructor
  27.  
  28. clockType::clockType(int clockHrs, int clockMins, int clockSecs)
  29. {
  30.     hours = clockHrs;
  31.     minutes = clockMins;
  32.     seconds = clockSecs;
  33. };
  34.  
  35. //functions
  36.  
  37. void clockType::setHours(int clockHrs)
  38. {
  39.     cout << "Please intput the Hours: \n";
  40.     cin >> clockHrs;
  41.     hours = clockHrs;
  42. };
  43.  
  44. void clockType::setMinutes(int clockMins)
  45. {
  46.     cout << "Please input the Minutes: \n ";
  47.     cin >> clockMins;
  48.     minutes = clockMins;
  49. };
  50.  
  51. void clockType::setSeconds(int clockSecs)
  52. {
  53.     cout << "Please input the Seconds: \n";
  54.     cin >> clockSecs;
  55.     seconds = clockSecs;
  56. };
  57.  
  58. void clockType::showTime()
  59. {
  60.     getHours();
  61.     getMinutes();
  62.     getSeconds();
  63.     cout << "The current time is: " << hours << ':' << minutes << ':' << seconds << endl;
  64. };
  65.  
  66. int clockType::getHours()
  67. {
  68.     return hours;
  69. };
  70.  
  71. int clockType::getMinutes()
  72. {
  73.     return minutes;
  74. };
  75.  
  76. int clockType::getSeconds()
  77. {
  78.     return seconds;
  79. };
  80.  
  81. void menu(clockType clockSettings)
  82. {
  83.     int selection = 00;
  84.     char answer;
  85.     int clockHrs = 00;
  86.     int clockMins = 00;
  87.     int clockSecs = 00;
  88.  
  89.     cout << "Would you like to use the Clock Settings Program?(Y/N) \n";
  90.     cin >> answer;
  91.  
  92.     while (answer == 'y' || answer == 'Y') {
  93.  
  94.         cout << "Please select from the following: \n";
  95.         cout << "1. Show the current time.\n";
  96.         cout << "2. Set the Hours.\n";
  97.         cout << "3. Set the Minutes.\n";
  98.         cout << "4. Set the Seconds.\n";
  99.         cin >> selection;
  100.  
  101.         if (selection == 1)
  102.             clockSettings.showTime();
  103.         else if (selection == 2)
  104.             clockSettings.setHours(clockHrs);
  105.         else if (selection == 3)
  106.             clockSettings.setMinutes(clockMins);
  107.         else if (selection == 4)
  108.             clockSettings.setSeconds(clockSecs);
  109.         else
  110.             cout << "Please enter a valid selection." << endl;
  111.     }
  112. };
  113.  
  114. //int main
  115.  
  116. int main()
  117. {
  118.  
  119.     clockType clockSettings;
  120.     menu(clockSettings);
  121.  
  122.     return 0;
  123. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement