fork download
  1. // Attached: HW_8-1a
  2. // ===========================================================
  3. // File: HW_8-1a_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. class Student
  14. {
  15. private:
  16. int id;
  17. int units;
  18. string name;
  19.  
  20. public:
  21. // Default constructor
  22. Student()
  23. {
  24. id = 0;
  25. name = "";
  26. units = 0;
  27. }
  28.  
  29. // Overloaded constructor
  30. Student(int studentId, string studentName, int studentUnits)
  31. {
  32. id = studentId;
  33. name = studentName;
  34. units = studentUnits;
  35. }
  36.  
  37. // Destructor
  38. ~Student()
  39. {
  40. }
  41.  
  42. // Set functions
  43. void setID(int studentId)
  44. {
  45. id = studentId;
  46. }
  47.  
  48. void setName(string studentName)
  49. {
  50. name = studentName;
  51. }
  52.  
  53. void setUnits(int studentUnits)
  54. {
  55. units = studentUnits;
  56. }
  57.  
  58. // Display function
  59. void displayRecord()
  60. {
  61. cout << "ID: " << id << endl;
  62. cout << "Name: " << name << endl;
  63. cout << "Units: " << units << endl;
  64. }
  65. };
  66.  
  67. int main()
  68. {
  69. Student s1;
  70. Student s2(100, "Tom P. Lee", 12);
  71.  
  72. cout << "Here is student #1:" << endl;
  73. s1.displayRecord();
  74. cout << endl;
  75.  
  76. cout << "Here is student #2:" << endl;
  77. s2.displayRecord();
  78. cout << endl;
  79.  
  80. s1.setID(100);
  81. s1.setName("John Lee Hooker");
  82. s1.setUnits(15);
  83.  
  84. cout << "Here is student #1 after the set functions:" << endl;
  85. s1.displayRecord();
  86.  
  87. return 0;
  88. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Here is student #1:
ID:      0
Name:    
Units:   0

Here is student #2:
ID:      100
Name:    Tom P. Lee
Units:   12

Here is student #1 after the set functions:
ID:      100
Name:    John Lee Hooker
Units:   15