Advertisement
Guest User

MP1_msaad1

a guest
Feb 17th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double power(double n, int p = 2)
  5. {
  6.     double total = 1;
  7.  
  8.     for (int i = 0; i < p; i++)
  9.     {
  10.         total = total * n;
  11.  
  12.     }
  13.     return total;
  14. }
  15.  
  16. long hms_to_secs(int h, int m, int s)
  17. {
  18.     int total = 0;
  19.     total = (h * 3600) + (m * 60) + s;
  20.     return total;
  21. }
  22.  
  23. void swap(int& x, int& y) {
  24.  
  25.     int t = x;
  26.     x = y;
  27.     y = t;
  28. }
  29.  
  30. int main() {
  31.  
  32.     double n;
  33.     int p;
  34.  
  35.     cout << "Power Function" << endl;
  36.     cout << "Enter a number " << endl;
  37.     cin >> n;
  38.     cout << "Enter a power " << endl;
  39.     cin >> p;
  40.  
  41.     cout << n << " to the power of " << p << " is equal to " << power(n, p) << endl;
  42.  
  43.     int h;
  44.     int m;
  45.     int s;
  46.     char ch;
  47.  
  48.     cout << "Enter time as HH:MM:SS or enter a negative value for hour to quit " << endl;
  49.  
  50.     for (int i = 0; i >= 0; i++) {
  51.  
  52.         cin >> h;
  53.         if (h >= 0)
  54.         {
  55.             cin >> ch >> m >> ch >> s;
  56.             cout << h << ":" << m << ":" << s << " is equal to " << hms_to_secs(h, m, s) << " seconds " << endl;
  57.             cout << "Enter time as HH:MM:SS or enter a negative value for hour to quit" << endl;
  58.         }
  59.         else break;
  60.  
  61.     }
  62.  
  63.     int x;
  64.     int y;
  65.  
  66.     cout << "Enter the first integer " << endl;
  67.     cin >> x;
  68.     cout << "Enter the second integer " << endl;
  69.     cin >> y;
  70.     cout << "The values before swapping are x = " << x << " and " << " y = " << y << endl;
  71.     swap(x, y);
  72.     cout << "The vaues after swapping are x = " << x << " and " << " y = " << y << endl;
  73.  
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement