C++ Program For Static Variables

Free C++ course with real-time projects Start Now!!

Program 1

//Program of static variable
#include<iostream>
#define clrscr() system("cls")
using namespace std;
class Student
{
    public:
    int rno,mno;
    static int ccode;
    static int count;
    Student(int rno,int mno)
    {
        this->rno=rno;
        this->mno=mno;
        count++;
    }
    void display();
};
void Student::display()
{
    cout<<"\nRoll no: "<<rno;
    cout<<"\tMobile No:"<<mno;
    cout<<"\tCollege Code"<<Student::ccode;
}
int Student::count=0;
int Student::ccode=101;
int main()
{
    clrscr();
    Student S1(101,12345);
    Student S2(102,22334);
    Student S3(103,5556);
    Student S4(104,11223);
    S1.display();
    S2.display();
    S3.display();
    S4.display();
    
    cout<<"\nTotal Student admited: ";
    cout<<Student::count;
   

  return 0;
}

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *