Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int quo(int x, int y) {
- return x / y;
- }
- int rem(int x, int y) {
- return x % y;
- }
- void ex6_24(int num) {
- int r{0};
- if (num > 0) {
- r = rem(num,10);
- ex6_24(quo(num,10));
- }
- else {
- cout << endl;
- }
- if (r != 0) {
- cout << r << ' ';
- }
- }
- int timeOffMidnight (int hours, int minutes, int seconds) {
- int Midnight{0}; //this is our defining start point, we will measure how far off this time our input is
- int Noon{Midnight+12*60*60}; //This is our defined time for noon, in distance from midnight in seconds
- int timeSince{0}; //This will hold the amount of seconds since midnight
- timeSince = hours * 60 * 60 + minutes * 60 + seconds; //converts all times to seconds
- if (timeSince < Noon) { return timeSince; }
- else { return(timeSince-Noon); }
- }
- int timeBetweenTimes(int hours1, int minutes1, int seconds1, int hours2, int minutes2, int seconds2 ) {
- 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
- }
- double farenheit(double celTemp) {
- return(celTemp*1.8 + 32); //converts the input temp from celsius to farenheit
- }
- double celsius(double fTemp) {
- return((fTemp-32)/1.8); //converts input temp from farenheit to celsius
- }
- void chart () {
- cout << "Farenheit:" << setw(20) << "Celsius:" << endl;
- double fstart{100};
- double cstart{212};
- while (fstart >= 0) {
- cout << std::setprecision(5) << celsius(fstart) << " degrees" << setw(14) << farenheit(cstart) << " degrees" << endl;
- fstart = fstart -1;
- cstart = cstart-2.12;
- }
- }
- void Test6_24() {
- ex6_24(4562);
- cout << endl;
- }
- void Test6_25() {
- int hours, minutes, seconds;
- int hours1, minutes1, seconds1;
- int hours2, minutes2, seconds2;
- cout << "Please enter hours, minutes, seconds: ";
- cin >> hours >> minutes >> seconds;
- cout << "Time since the clock last struck " << timeOffMidnight(hours,minutes,seconds) << endl;
- cout << "Please enter hours, minutes, seconds for time 1: ";
- cin >> hours1 >> minutes1 >> seconds1;
- cout << "Please enter hours, minutes, seconds for time 2: ";
- cin >> hours2 >> minutes2 >> seconds2;
- cout << "Time between those two times (in seconds): " << timeBetweenTimes(hours1,minutes1,seconds1,hours2,minutes2,seconds2) << "s" << endl;
- }
- void Test6_26() {
- chart();
- }
- int main()
- {
- //Test6_24();
- //Test6_25();
- Test6_26();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement