thespeedracer38

Height

Jan 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. class Height{
  8.     int meter, centi_meter;
  9. public:
  10.     inline Height();
  11.     inline Height(int ,int);
  12.     inline Height(const Height&);
  13.     inline ~Height();
  14.     inline void input();
  15.     inline void display();
  16.     inline Height add(Height&);
  17. };
  18.  
  19. Height::Height(){
  20.     meter = 0;
  21.     centi_meter = 0;
  22. }
  23.  
  24. Height::Height(int meter, int centi_meter){
  25.     Height::meter = meter;
  26.     Height::centi_meter = centi_meter;
  27. }
  28.  
  29. Height::Height(const Height &copy){
  30.     meter = copy.meter;
  31.     centi_meter = copy.centi_meter;
  32. }
  33.  
  34. Height::~Height(){
  35.    
  36. }
  37.  
  38. Height Height::add(Height &height){
  39.     int c_m = (centi_meter + height.centi_meter) % 100;
  40.     int m = (meter + height.meter) + ((centi_meter + height.centi_meter) / 100);
  41.     return Height(m, c_m);
  42. }
  43.  
  44. void Height::input(){
  45.     cout << "Meter = ";
  46.     cin >> meter;
  47.     cout << "Centi Meter = ";
  48.     cin >> centi_meter;
  49. }
  50.  
  51. void Height::display(){
  52.     cout << meter << "m " << centi_meter << "cm" << endl;
  53. }
  54.  
  55. int main(int argc, char** argv) {
  56.     system("cls");
  57.     Height obj1, obj2;
  58.     cout << "Enter the first height" << endl;
  59.     obj1.input();
  60.     cout << "Enter the second height" << endl;
  61.     obj2.input();
  62.     Height result = obj1.add(obj2);
  63.     cout << " ";
  64.     obj1.display();
  65.     cout << "+";
  66.     obj2.display();
  67.     cout << "=";
  68.     result.display();
  69.     cin.ignore();
  70.     cin.get();
  71.     return 0;
  72. }
Add Comment
Please, Sign In to add comment