Advertisement
bwukki

Untitled

Feb 25th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int quo(int x, int y) {
  9.     return x / y;
  10. }
  11.  
  12. int rem(int x, int y) {
  13.     return x % y;
  14. }
  15.  
  16. void ex6_24(int num) {
  17.     int r{0};
  18.     if (num > 0) {
  19.         r = rem(num,10);
  20.         ex6_24(quo(num,10));
  21.     }
  22.     else {
  23.         cout << endl;
  24.     }
  25.     if (r != 0) {
  26.         cout << r << ' ';
  27.     }
  28. }
  29.  
  30. int timeOffMidnight (int hours, int minutes, int seconds) {
  31.     int Midnight{0}; //this is our defining start point, we will measure how far off this time our input is
  32.     int Noon{Midnight+12*60*60}; //This is our defined time for noon, in distance from midnight in seconds
  33.     int timeSince{0}; //This will hold the amount of seconds since midnight
  34.     timeSince = hours * 60 * 60 + minutes * 60 + seconds; //converts all times to seconds
  35.     if (timeSince < Noon) { return timeSince; }
  36.     else { return(timeSince-Noon); }
  37. }
  38.  
  39. int timeBetweenTimes(int hours1, int minutes1, int seconds1, int hours2, int minutes2, int seconds2 ) {
  40.     return(abs(timeOffMidnight(hours1, minutes1, seconds1) - timeOffMidnight(hours2,minutes2,seconds2))); //calculates how far each time was from the clock striking 12,then finds the distance between them
  41. }
  42.  
  43. double farenheit(double celTemp) {
  44.     return(celTemp*1.8 + 32); //converts the input temp from celsius to farenheit
  45. }
  46.  
  47. double celsius(double fTemp) {
  48.     return((fTemp-32)/1.8); //converts input temp from farenheit to celsius
  49. }
  50.  
  51. void chart () {
  52.     cout << "Farenheit:" << setw(20) << "Celsius:" << endl;
  53.     double fstart{100};
  54.     double cstart{212};
  55.     while (fstart >= 0) {
  56.     cout << std::setprecision(5) << celsius(fstart) << " degrees" << setw(14) << farenheit(cstart) << " degrees" << endl;
  57.     fstart = fstart -1;
  58.     cstart = cstart-2.12;
  59.     }
  60. }
  61.  
  62. void Test6_24() {
  63.     ex6_24(4562);
  64.     cout << endl;
  65. }
  66.  
  67. void Test6_25() {
  68.     int hours, minutes, seconds;
  69.     int hours1, minutes1, seconds1;
  70.     int hours2, minutes2, seconds2;
  71.     cout << "Please enter hours, minutes, seconds: ";
  72.     cin >> hours >> minutes >> seconds;
  73.     cout << "Time since the clock last struck " << timeOffMidnight(hours,minutes,seconds) << endl;
  74.     cout << "Please enter hours, minutes, seconds for time 1: ";
  75.     cin >> hours1 >> minutes1 >> seconds1;
  76.     cout << "Please enter hours, minutes, seconds for time 2: ";
  77.     cin >> hours2 >> minutes2 >> seconds2;
  78.     cout << "Time between those two times (in seconds): " << timeBetweenTimes(hours1,minutes1,seconds1,hours2,minutes2,seconds2) << "s" << endl;
  79. }
  80.  
  81. void Test6_26() {
  82.     chart();
  83. }
  84.  
  85. int main()
  86. {
  87.     //Test6_24();
  88.     //Test6_25();
  89.     Test6_26();
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement