Write C++ program to create a base class named Person that includes variables: name and age and then define a derived class named Student that includes four functions setName(), setAge(),setMark(), getName(), getAge() and getMark () to set and return the name of student, age and mark. then define a derived class named Student2 which is derived from both above classes and includes one function named checkAge() to check if the age of students Less than 12 then the student is in primary school and checkMark() to check if mark is less than 50 then student is passes the exam.
#include <cstring>
class Person{
  protected:
    std::string name;
    int age;
};
class Student: public Person{
  protected:
    int mark;
  public:
    void setName(std::string studName){
      name= studName;
    }
    std::string getName(){
      return name;
    }
    void setAge(int studAge){
      age=studAge;
    }
    int getAge(){
      return age;
    }
    void setMark(int studMark){
      mark=studMark;
    }
    int getMark(){
      return mark;
    }
};
class Student2: public Student{
  public:
    int checkAge(){     // it says "Less" not "less". So it returns 1 if age is less than 12. switch "return"s if you need
      if(age<12) return 1;
      return 0;
    } Â
    int checkMark(){    //same
      if(mark<50) return 1;
      return 0;
    }
};
Don't use "using namespace std" before functions, that's a really bad thing to do. add int main(){} or whatever you need
Comments
Leave a comment