fork download
  1. // Attached: HW_7c
  2. // ===========================================================
  3. // File: HW_7c_NoInput.cpp
  4. // ===========================================================
  5. // Programmer: Elaine Torrez
  6. // Class: CMPR 121
  7. // ===========================================================
  8.  
  9. #include <iostream>
  10. #include <string>
  11. using namespace std;
  12.  
  13. class Presidents
  14. {
  15. private:
  16. int number;
  17. string name;
  18. string quote;
  19.  
  20. public:
  21. Presidents()
  22. {
  23. number = 0;
  24. name = "";
  25. quote = "";
  26. }
  27.  
  28. void setNumber(int num)
  29. {
  30. number = num;
  31. }
  32.  
  33. void setName(string n)
  34. {
  35. name = n;
  36. }
  37.  
  38. void setQuote(string q)
  39. {
  40. quote = q;
  41. }
  42.  
  43. void displayPresidents()
  44. {
  45. cout << name << ", " << number << "th president, said:" << endl;
  46. cout << "\"" << quote << "\"" << endl;
  47. }
  48. };
  49.  
  50. int main()
  51. {
  52. Presidents p1, p2, p3;
  53.  
  54. // Hardcoded data (no user input)
  55. p1.setNumber(37);
  56. p1.setName("Richard Nixon");
  57. p1.setQuote("I am not a crook.");
  58.  
  59. p2.setNumber(45);
  60. p2.setName("Donald Trump");
  61. p2.setQuote("Is our country still spending money on the GLOBAL WARMING HOAX?");
  62.  
  63. p3.setNumber(42);
  64. p3.setName("Bill Clinton");
  65. p3.setQuote("I did not have sexual relations with that woman.");
  66.  
  67. cout << "The presidents are:" << endl;
  68.  
  69. p1.displayPresidents();
  70. p2.displayPresidents();
  71. p3.displayPresidents();
  72.  
  73. return 0;
  74. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
The presidents are:
Richard Nixon, 37th president, said:
"I am not a crook."
Donald Trump, 45th president, said:
"Is our country still spending money on the GLOBAL WARMING HOAX?"
Bill Clinton, 42th president, said:
"I did not have sexual relations with that woman."