Showing posts with label Gorakhpur. Show all posts
Showing posts with label Gorakhpur. Show all posts

Function overriding in C++ (basics)

 #include <iostream>

#include <string>

using namespace std;

class student{

      public:

      void displaystu(){

            cout<<"Hi! My name is Vaibhav Yadav and I'm from ECE Department, First Year' 25"<<endl;

      }

};

class update: public student{

      public:

      void displaystu(){

            student::displaystu();

            cout<<"Details UPDATED"<<endl<<"Hi! My name is Vaibhav Yadav and I'm from 'IT' Department, First Year' 25"<<endl;

      }

};

int main()

{

    update up;

    up.displaystu();

    return 0;

}


Class Constructor and Destructor for this Class

 #include<iostream>

using namespace std;

class Student

{

string name;

public:

Student(){

    name = "Vaibhav Yadav";

    cout<<"Constructor of Student Class has been Called"<<endl;

    cout<<"Student Name is: "<<name<<endl;

}

~Student(){

    cout<<"---Destructor Of Student Class has been called---"<<endl;

    cout<<"---Memory for 'obj name' has been deallocated and memory has been released---"<<endl;

}

};


main()

{

Student stu;

return 0;

}


Operator Overloading in C++

#include<iostream> using namespace std; class Complex { private: int real, imag; public: Complex(int r = 0, int i = 0){       re...