Answer to Question #342534 in C++ for Oras

Question #342534

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.

1
Expert's answer
2022-05-18T15:26:07-0400
#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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS