Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6684207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:54:47+00:00 2026-05-26T04:54:47+00:00

I have a homework problem that asks: Desgin a derived class GraduateStudent from base

  • 0

I have a homework problem that asks:

Desgin a derived class GraduateStudent from base class Student. It adds a data member named Advisor to store the name of student’s thesis advisor. Provide constructor, destructor, accessor, and modifier functions. This class overrides the year function to returns one of two strings (“Masters” or “PhD”) depending on the number of hours completed, using using the chart below.

Hours Year
<=30 Masters

(greater than) 30 PhD

I’ve written:

using namespace std;


class Student
{
public:
    Student( string s = "", int h = 0);
    ~Student();
    string getName() const;
    int getHours() const;
    void setName(string s);
    void setHours (int h);
    string year () const;
private:
    string name;
    int hours;

};

class GraduateStudent: private Student
{
public:
    GraduateStudent(string s = "", int h=0, string advisor=""); //constructor
    ~GraduateStudent(); //destructor
    string getAdvisor();
    void setAdvisor(string advisor);
    //Class overrides??

private:
    string Advisor;
}

The class student was given, I’ve added the Graduate Student derived class.

My question is first if I have set up the derived class properly. My second question is how can I override the year function without if statements? I tried to use those statements but the editor gave me errors, I suspect since its a header file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:54:48+00:00Added an answer on May 26, 2026 at 4:54 am

    The student class you were “given” is not really written correctly to properly allow for overriding of the year function. A general use case scenario (where you hold student objects in a container won’t work properly).

    So, to fix (properly):

    // Generally, poor practice to have a using namespace
    // directive in a header file, instead just properly 
    // scope your variables (as below)
    // using namespace std;
    
    class Student
    {
    public:
        Student( std::string s = "", int h = 0);
    
        // Virtual desctructors allow you to properly free derived
        // classes given a base class pointer
        virtual ~Student();
    
        std::string getName() const;
        int getHours() const;
        void setName(std::string s);
        void setHours (int h);
    
        // This function needs to be virtual to be overridable
        virtual std::string year () const;
    private:
        std::string name;
        int hours;
    
    };
    
    // Use Public inheritance, after all a
    // GraduateStudent IS-A Student
    class GraduateStudent: public Student
    {
    public:
        GraduateStudent(std::string s = "", int h=0, string advisor=""); //constructor
        ~GraduateStudent(); //destructor
        std::string getAdvisor();
        void setAdvisor(string advisor);
        //Class overrides??
    
        // this function overrides the Student::year() function
        std::string year() const;
    
    private:
        std::string Advisor;
    }
    

    Also, why do you think you are required to implement the year() function without using if statements? That would be the appropriate thing to do in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my homework for my C class, we have to write a program that
This is a homework problem that I have. I have been doing some research
I have a homework that asks me to do the following: Design a template
I'm very new to XML and XSLT. I have a homework assignment that asks
I have a homework problem for my C++ class and the problem wants us
I have a homework problem for my algorithms class asking me to calculate the
Okay, so I have another question on a prolog homework problem I am struggling
I have a homework assignment where I need to take input from a file
In my homework, I have to design a class Message; among other attributes, it
Note: This is a homework assignment. I have two classes, one inherits from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.