Advertisement
Felanpro

Classes

Mar 16th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. class Human
  9. {
  10. public:
  11.     int age;
  12.     int length;
  13.     int weight;
  14.  
  15.     string eyecolor;
  16.     string name;
  17.  
  18.     void growOld();
  19.     void exercise();
  20.     void eatDoritos();
  21.     void grow();
  22.  
  23. };
  24.  
  25. void Human::grow()
  26. {
  27.     length++;
  28. }
  29.  
  30. void Human::growOld()
  31. {
  32.     age++;
  33. }
  34.  
  35. void Human::exercise()
  36. {
  37.     weight--;
  38. }
  39.  
  40. void Human::eatDoritos()
  41. {
  42.     weight++;
  43. }
  44.  
  45. int main()
  46. {
  47.     Human a;
  48.     a.age = 17;
  49.     a.length = 180;
  50.     a.weight = 77;
  51.     a.eyecolor = "Brown";
  52.     a.name = "James";
  53.  
  54.     Human b;
  55.     b.age = 45;
  56.     b.length = 190;
  57.     b.weight = 89;
  58.     b.eyecolor = "Blue";
  59.     b.name = "John";
  60.  
  61.     //Display of their characteristics
  62.     cout << "Human A" << setw(10) << "Human B" << endl;
  63.     cout << a.name << setw(8) << b.name << setw(10) << "Name" << endl;
  64.     cout << a.age << setw(10) << b.age << setw(10) << "Age" << endl;
  65.     cout << a.weight << setw(10) << b.weight << setw(10) << "\tWeight (kg)" << endl;
  66.     cout << a.length << setw(10) << b.length << setw(10) << "\tLength (cm)" << endl;
  67.     cout << a.eyecolor << setw(8) << b.eyecolor << setw(10) << "Eyecolor" << endl;
  68.  
  69.     //3 years passes by and human a as well as human b changes, both in shape and form. Who are they now?
  70.  
  71.     //Human a
  72.     a.growOld();
  73.     a.growOld();
  74.     a.growOld();
  75.  
  76.     a.eatDoritos();
  77.     a.eatDoritos();
  78.     a.eatDoritos();
  79.     a.eatDoritos();
  80.     a.eatDoritos();
  81.  
  82.     a.grow();
  83.     a.grow();
  84.     a.grow();
  85.     a.grow();
  86.  
  87.     //Human b
  88.     b.growOld();
  89.     b.growOld();
  90.     b.growOld();
  91.  
  92.     b.exercise();
  93.     b.exercise();
  94.     b.exercise();
  95.     b.exercise();
  96.     b.exercise();
  97.     b.exercise();
  98.  
  99.     b.grow();
  100.  
  101.     cout << "------------------" << endl;
  102.  
  103.     //Display of their characteristics
  104.     cout << "Human A" << setw(10) << "Human B" << endl;
  105.     cout << a.name << setw(8) << b.name << setw(10) << "Name" << endl;
  106.     cout << a.age << setw(10) << b.age << setw(10) << "Age" << endl;
  107.     cout << a.weight << setw(10) << b.weight << setw(10) << "\tWeight (kg)" << endl;
  108.     cout << a.length << setw(10) << b.length << setw(10) << "\tLength (cm)" << endl;
  109.     cout << a.eyecolor << setw(8) << b.eyecolor << setw(10) << "Eyecolor" << endl;
  110.  
  111.     int pause; cin >> pause; //Pause the program
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement