*note, please do only exercise 2, exercise 1 is listed forreference. Thanks! Exe
ID: 3614963 • Letter: #
Question
*note, please do only exercise 2, exercise 1 is listed forreference. Thanks!Exercise 2:
Write the implementation file for the TestScoreclass in Exercise 1. The constructor just assigns itsparameters to the private data members, and the observerssimply return the corresponding member.
Exercise 1:
Given the following declaration for a TestScoreclass, write a derived class declaration calledIDScore that adds an integer student ID number asa private member, and that supplies (1) a constructor whoseparameters correspond to the three member fields, and (2) anobserver that returns the ID number.
class TestScore
{
public:
TestScore(string name, int score);
string GetName( ) const;
int GetScore ( ) const;
private:
string studentName;
int studentScore;
};
Explanation / Answer
//Here is cpp program with aboveimplementation.
#include<iostream> using namespace std; class TestScore { public: TestScore(){} TestScore(string name, int score){ studentName = name; studentScore = score; } string GetName( ) const; int GetScore ( ) const; private: string studentName; int studentScore; };
class Derived : public TestScore { private: int IDScore; public: Derived(){ TestScore::TestScore(); }; Derived(string a,int b,ints):TestScore(a,b){ IDScore = s; } int GetIDScore(); }; string TestScore::GetName() const { return studentName; } int TestScore::GetScore() const { return studentScore; } int Derived::GetIDScore(){ return IDScore; } int main() { Derived s("myname",80,1); cout<<"Name is:"<<s.GetName()<<" , score is:"<<s.GetScore()<<endl; cout<<"ID is:"<<s.GetIDScore()<<endl; system("pause"); }
#include<iostream> using namespace std; class TestScore { public: TestScore(){} TestScore(string name, int score){ studentName = name; studentScore = score; } string GetName( ) const; int GetScore ( ) const; private: string studentName; int studentScore; };
class Derived : public TestScore { private: int IDScore; public: Derived(){ TestScore::TestScore(); }; Derived(string a,int b,ints):TestScore(a,b){ IDScore = s; } int GetIDScore(); }; string TestScore::GetName() const { return studentName; } int TestScore::GetScore() const { return studentScore; } int Derived::GetIDScore(){ return IDScore; } int main() { Derived s("myname",80,1); cout<<"Name is:"<<s.GetName()<<" , score is:"<<s.GetScore()<<endl; cout<<"ID is:"<<s.GetIDScore()<<endl; system("pause"); }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.