fork download
  1. //student simulator
  2.  
  3. #include <string>
  4. #include <iostream>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. class student
  10. {
  11. private:
  12. int num; //student num
  13. float grade; //student grade
  14. int workEthic; //rating of student work ethic (1-10)
  15. string personalityType; //string value
  16.  
  17. public:
  18. student(int n, float g, int wE, string pT)
  19. : num(n),
  20. grade(g),
  21. workEthic(wE),
  22. personalityType(pT)
  23. {}
  24.  
  25. student() :num(0), grade(0), workEthic(0), personalityType("dead")
  26. {}
  27.  
  28. void askQuestion()
  29. {
  30. workEthic++;
  31. grade += 0.5;
  32. }
  33.  
  34. void sleep()
  35. {
  36. workEthic = 0;
  37. personalityType = "sleepy";
  38. grade -= 3.3;
  39.  
  40. }
  41.  
  42. void wake()
  43. {
  44. workEthic += 3;
  45. personalityType = "awake";
  46. grade += 3.2;
  47. }
  48.  
  49. void display()
  50. {
  51. cout << "id num=" << num << endl;
  52. cout << "grade=" << grade << endl;
  53. cout << "work ethic=" << workEthic << endl;
  54. cout << personalityType << endl;
  55. }
  56. };
  57.  
  58.  
  59. int main()
  60. {
  61. student matthew(5, 96.5, 2, "bored");
  62. matthew.sleep();
  63. matthew.display();
  64. cout << endl;
  65.  
  66. matthew.wake();
  67. matthew.askQuestion();
  68. matthew.display();
  69. return 0;
  70. }
  71.  
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
id num=5
grade=93.2
work ethic=0
sleepy

id num=5
grade=96.9
work ethic=4
awake