Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // COS1512Assignment02Question7.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- class Student
- {
- private:
- string studentName;
- string studentNumber;
- string studentAddress;
- string studentDegree;
- public:
- Student();
- Student(string NstudentName, string NstudentNumber, string NstudentAddress, string NstudentDegree)
- {
- studentName = NstudentName;
- studentNumber = NstudentNumber;
- studentAddress = NstudentAddress;
- studentDegree = NstudentDegree;
- }
- string getStudentName() const { return(studentName); };
- string getStudentNumber() const { return(studentNumber); };
- string getStudentAddress() const { return(studentAddress); };
- string getStudentDegree() const { return(studentDegree); };
- void setStudentName(string mStudentName) { studentName = mStudentName; };
- void setStudentNumber(string mStudentNumber) { studentNumber = mStudentNumber; };
- void setStudentAddress(string mStudentAddress) { studentAddress = mStudentAddress; };
- void setStudentDegree(string mStudentDegree) { studentDegree = mStudentDegree; };
- float calcFee()
- {
- float initialRegistrationFee;
- // student is undergraduate if studentGraduateType == B
- char isStudentB = getStudentDegree()[0];
- if (isStudentB == 'B')
- initialRegistrationFee = 500;
- else
- initialRegistrationFee = 600;
- return initialRegistrationFee;
- }
- friend ostream& operator<< (ostream& out, const Student& st);
- };
- // this needs to be inside Student class and has to be renamed to display_info
- ostream& operator<< (ostream& out, const Student& st)
- {
- // Since operator<< is a friend of the Point class, we can access Point's members directly.
- out << "Student(" << st.studentName << ", " << st.studentNumber << ", " << st.studentAddress << ", " << st.studentDegree << ")" << endl;
- return out;
- }
- class PostgradStd : public Student
- {
- private:
- string stuName, stuNumber, stuAddress, stuDegree, dissertation, Ndissertation;
- public:
- PostgradStd(string NstudentName, string NstudentNumber, string NstudentAddress, string NstudentDegree, string Ndissertation) :
- Student(NstudentName, NstudentNumber, NstudentAddress, NstudentDegree) {
- stuName = NstudentName;
- stuNumber = NstudentNumber;
- stuAddress = NstudentAddress;
- stuDegree = NstudentDegree;
- dissertation = Ndissertation;
- }
- string getStudentDissertation() const { return(dissertation); };
- void SetStudentDissertation(string mStudentDissertation) { dissertation = mStudentDissertation; };
- float calcFee(float theValue = 12000)
- {
- float initialRegistrationFee = 600;
- theValue = initialRegistrationFee + theValue;
- return theValue;
- }
- friend ostream& operator<< (ostream& ou, const PostgradStd& str);
- };
- ostream& operator<< (ostream& ou, const PostgradStd& str)
- {
- // Since operator<< is a friend of the Point class, we can access Point's members directly.
- ou << "PostgradStd(" << str.stuName << ", " << str.stuNumber << ", " << str.stuAddress << ", " << str.stuDegree << ", " << str.dissertation << ")" << endl;
- return ou;
- }
- int main()
- {
- string meh;
- Student* myStudent = new Student{ "Mary Mbeli", "12345678", "Po Box 16, Pretoria, 0818", "BSc" };
- cout << "Student Name: " << myStudent->getStudentName() << endl;
- cout << "Student Number: " << myStudent->getStudentNumber() << endl;
- cout << "Student Address: " << myStudent->getStudentAddress() << endl;
- cout << "Student Degree: " << myStudent->getStudentDegree() << endl;
- cout << "Student Fee: " << myStudent->calcFee() << endl;
- cout << endl << endl;
- cout << *myStudent;
- cout << endl << endl << endl;
- PostgradStd* myPostGradStd = new PostgradStd{ "Mary Mbeli", "12345678", "Po Box 16, Pretoria, 0818", "PhD", "test" };
- cout << "Student Name: " << myPostGradStd->getStudentName() << endl;
- cout << "Student Number: " << myPostGradStd->getStudentNumber() << endl;
- cout << "Student Address: " << myPostGradStd->getStudentAddress() << endl;
- cout << "Student Degree: " << myPostGradStd->getStudentDegree() << endl;
- cout << "Student Fee: " << myPostGradStd->calcFee() << endl;
- cout << "Student Dissertation: " << myPostGradStd->getStudentDissertation() << endl;
- cout << endl << endl;
- cout << *myPostGradStd;
- cin >> meh;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement