fork download
  1. // Attached: HW_8s-2b
  2. // ===========================================================
  3. // File: HW_8s_2b_Combined.cpp
  4. // ===========================================================
  5. // Programmer: Elaine Torrez
  6. // Class: CMPR 121
  7. // ===========================================================
  8.  
  9. #include <iostream>
  10. #include <string>
  11. using namespace std;
  12.  
  13. // ===========================================================
  14. // Date Class
  15. // ===========================================================
  16. class Date
  17. {
  18. private:
  19. int month;
  20. int day;
  21. int year;
  22.  
  23. public:
  24. Date()
  25. {
  26. month = 0;
  27. day = 0;
  28. year = 0;
  29. }
  30.  
  31. Date(int m, int d, int y)
  32. {
  33. month = m;
  34. day = d;
  35. year = y;
  36. }
  37.  
  38. ~Date()
  39. {
  40. }
  41.  
  42. void setDate(int m, int d, int y)
  43. {
  44. month = m;
  45. day = d;
  46. year = y;
  47. }
  48.  
  49. void displayDate()
  50. {
  51. cout << month << "/" << day << "/" << year;
  52. }
  53. };
  54.  
  55. // ===========================================================
  56. // FamousPeople Class
  57. // ===========================================================
  58. class FamousPeople
  59. {
  60. private:
  61. string name;
  62. string quote;
  63. Date birthdate;
  64.  
  65. public:
  66. FamousPeople()
  67. {
  68. name = "";
  69. quote = "";
  70. }
  71.  
  72. ~FamousPeople()
  73. {
  74. }
  75.  
  76. void setName(string n)
  77. {
  78. name = n;
  79. }
  80.  
  81. void setQuote(string q)
  82. {
  83. quote = q;
  84. }
  85.  
  86. void setDate(int m, int d, int y)
  87. {
  88. birthdate.setDate(m, d, y);
  89. }
  90.  
  91. void displayDate()
  92. {
  93. birthdate.displayDate();
  94. }
  95.  
  96. void displayPerson()
  97. {
  98. cout << "Name: " << name << endl;
  99. cout << "Birth Date: ";
  100. displayDate();
  101. cout << endl;
  102. cout << "Enter the quotation:" << endl;
  103. cout << "\"" << quote << "\"" << endl << endl;
  104. }
  105. };
  106.  
  107. // ===========================================================
  108. // Main Function
  109. // ===========================================================
  110. int main()
  111. {
  112. FamousPeople person1, person2, person3;
  113.  
  114. string name, quote;
  115. int month, day, year;
  116.  
  117. // First Person
  118. cout << "Enter the first famous person: ";
  119. getline(cin, name);
  120. person1.setName(name);
  121.  
  122. cout << endl;
  123. cout << "Enter the quotation:" << endl;
  124. getline(cin, quote);
  125. person1.setQuote(quote);
  126.  
  127. cout << endl;
  128. cout << "Enter the birthdate:" << endl;
  129. cout << "Month: ";
  130. cin >> month;
  131. cout << "Day: ";
  132. cin >> day;
  133. cout << "Year: ";
  134. cin >> year;
  135. person1.setDate(month, day, year);
  136.  
  137. cin.ignore();
  138.  
  139. cout << endl << "---- (Screen Clears) ----" << endl << endl;
  140.  
  141. // Second Person
  142. cout << "Enter the second famous person: ";
  143. getline(cin, name);
  144. person2.setName(name);
  145.  
  146. cout << endl;
  147. cout << "Enter the quotation:" << endl;
  148. getline(cin, quote);
  149. person2.setQuote(quote);
  150.  
  151. cout << endl;
  152. cout << "Enter the birthdate:" << endl;
  153. cout << "Month: ";
  154. cin >> month;
  155. cout << "Day: ";
  156. cin >> day;
  157. cout << "Year: ";
  158. cin >> year;
  159. person2.setDate(month, day, year);
  160.  
  161. cin.ignore();
  162.  
  163. cout << endl << "---- (Screen Clears) ----" << endl << endl;
  164.  
  165. // Third Person
  166. cout << "Enter the third famous person: ";
  167. getline(cin, name);
  168. person3.setName(name);
  169.  
  170. cout << endl;
  171. cout << "Enter the quotation:" << endl;
  172. getline(cin, quote);
  173. person3.setQuote(quote);
  174.  
  175. cout << endl;
  176. cout << "Enter the birthdate:" << endl;
  177. cout << "Month: ";
  178. cin >> month;
  179. cout << "Day: ";
  180. cin >> day;
  181. cout << "Year: ";
  182. cin >> year;
  183. person3.setDate(month, day, year);
  184.  
  185. cout << endl << "---- (Screen Clears) ----" << endl;
  186. cout << "Here are the famous people:" << endl << endl;
  187.  
  188. person1.displayPerson();
  189. person2.displayPerson();
  190. person3.displayPerson();
  191.  
  192. system("pause");
  193. return 0;
  194. }
Success #stdin #stdout #stderr 0s 5324KB
stdin
Standard input is empty
stdout
Enter the first famous person: 
Enter the quotation:

Enter the birthdate:
Month: Day: Year: 
----  (Screen Clears)  ----

Enter the second famous person: 
Enter the quotation:

Enter the birthdate:
Month: Day: Year: 
----  (Screen Clears)  ----

Enter the third famous person: 
Enter the quotation:

Enter the birthdate:
Month: Day: Year: 
----  (Screen Clears)  ----
Here are the famous people:

Name: 
Birth Date: 0/0/0
Enter the quotation:
""

Name: 
Birth Date: 0/0/0
Enter the quotation:
""

Name: 
Birth Date: 0/0/0
Enter the quotation:
""

stderr
sh: 1: pause: not found