Constructors example

 #include <iostream>

using namespace std;

class exam

{

    int total;

    char grade;

    void intro(void);

    public:

    exam(){

        intro();

    }

    exam(int t,char g)

    {   

        intro();

        total=t;

        grade=g;

        cout<<"Your total marks are"<<total<<" and grade is "<<grade<<endl;

        

    }

   

};

void exam::intro()

    {

        cout<<"Hello,Namaste,Sat sriyakal"<<endl;

    }

    


int main() {

    exam e1(95,'A');

    exam e2;

return 0;

}


Comments

Popular posts from this blog

Hackerrank-Accessing Inherited Functions problem-Inheritance

Inheritance- Code with Harry-Lecture 41 solution (Multiple inheritance)