Advertisement
Guest User

Untitled

a guest
Apr 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.32 KB | None | 0 0
  1. // COS1512Assignment02Question7.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. class Student
  11. {
  12.     private:
  13.         string studentName;
  14.         string studentNumber;
  15.         string studentAddress;
  16.         string studentDegree;
  17.  
  18.     public:
  19.         Student();
  20.         Student(string NstudentName, string NstudentNumber, string NstudentAddress, string NstudentDegree)
  21.         {
  22.             studentName = NstudentName;
  23.             studentNumber = NstudentNumber;
  24.             studentAddress = NstudentAddress;
  25.             studentDegree = NstudentDegree;
  26.         }
  27.  
  28.         string getStudentName() const { return(studentName); };
  29.         string getStudentNumber() const { return(studentNumber); };
  30.         string getStudentAddress() const { return(studentAddress); };
  31.         string getStudentDegree() const { return(studentDegree); };
  32.  
  33.         void setStudentName(string mStudentName) { studentName = mStudentName; };
  34.         void setStudentNumber(string mStudentNumber) { studentNumber = mStudentNumber; };
  35.         void setStudentAddress(string mStudentAddress) { studentAddress = mStudentAddress; };
  36.         void setStudentDegree(string mStudentDegree) { studentDegree = mStudentDegree; };
  37.  
  38.         float calcFee()
  39.         {
  40.             float initialRegistrationFee;
  41.             // student is undergraduate if studentGraduateType == B
  42.             char isStudentB = getStudentDegree()[0];
  43.             if (isStudentB == 'B')
  44.                  initialRegistrationFee = 500;
  45.             else
  46.                 initialRegistrationFee = 600;
  47.  
  48.             return initialRegistrationFee;
  49.         }
  50.  
  51.         friend ostream& operator<< (ostream& out, const Student& st);
  52. };
  53.  
  54. // this needs to be inside Student class and has to be renamed to display_info
  55. ostream& operator<< (ostream& out, const Student& st)
  56. {
  57.     // Since operator<< is a friend of the Point class, we can access Point's members directly.
  58.     out << "Student(" << st.studentName << ", " << st.studentNumber << ", " << st.studentAddress << ", " << st.studentDegree << ")" << endl;
  59.     return out;
  60. }
  61.  
  62.  
  63. class PostgradStd : public Student
  64. {
  65.     private:
  66.         string stuName, stuNumber, stuAddress, stuDegree, dissertation, Ndissertation;
  67.  
  68.     public:
  69.         PostgradStd(string NstudentName, string NstudentNumber, string NstudentAddress, string NstudentDegree, string Ndissertation) :
  70.             Student(NstudentName, NstudentNumber, NstudentAddress, NstudentDegree) {
  71.             stuName = NstudentName;
  72.             stuNumber = NstudentNumber;
  73.             stuAddress = NstudentAddress;
  74.             stuDegree = NstudentDegree;
  75.             dissertation = Ndissertation;
  76.         }
  77.  
  78.         string getStudentDissertation() const { return(dissertation); };
  79.         void SetStudentDissertation(string mStudentDissertation) { dissertation = mStudentDissertation; };
  80.  
  81.         float calcFee(float theValue = 12000)
  82.         {
  83.             float initialRegistrationFee = 600;
  84.             theValue = initialRegistrationFee + theValue;
  85.             return theValue;
  86.         }
  87.  
  88.         friend ostream& operator<< (ostream& ou, const PostgradStd& str);
  89. };
  90.  
  91. ostream& operator<< (ostream& ou, const PostgradStd& str)
  92. {
  93.     // Since operator<< is a friend of the Point class, we can access Point's members directly.
  94.     ou << "PostgradStd(" << str.stuName << ", " << str.stuNumber << ", " << str.stuAddress << ", " << str.stuDegree << ", " << str.dissertation << ")" << endl;
  95.     return ou;
  96. }
  97.  
  98.  
  99. int main()
  100. {
  101.     string meh;
  102.     Student* myStudent = new Student{ "Mary Mbeli", "12345678", "Po Box 16, Pretoria, 0818", "BSc" };
  103.     cout << "Student Name: " << myStudent->getStudentName() << endl;
  104.     cout << "Student Number: " << myStudent->getStudentNumber() << endl;
  105.     cout << "Student Address: " << myStudent->getStudentAddress() << endl;
  106.     cout << "Student Degree: " << myStudent->getStudentDegree() << endl;
  107.     cout << "Student Fee: " << myStudent->calcFee() << endl;
  108.     cout << endl << endl;
  109.     cout << *myStudent;
  110.     cout << endl << endl << endl;
  111.  
  112.     PostgradStd* myPostGradStd = new PostgradStd{ "Mary Mbeli", "12345678", "Po Box 16, Pretoria, 0818", "PhD", "test" };
  113.     cout << "Student Name: " << myPostGradStd->getStudentName() << endl;
  114.     cout << "Student Number: " << myPostGradStd->getStudentNumber() << endl;
  115.     cout << "Student Address: " << myPostGradStd->getStudentAddress() << endl;
  116.     cout << "Student Degree: " << myPostGradStd->getStudentDegree() << endl;
  117.     cout << "Student Fee: " << myPostGradStd->calcFee() << endl;
  118.     cout << "Student Dissertation: " << myPostGradStd->getStudentDissertation() << endl;
  119.     cout << endl << endl;
  120.     cout << *myPostGradStd;
  121.  
  122.     cin >> meh;
  123.     return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement