0% found this document useful (0 votes)
0 views11 pages

Static Variables Lab

The document contains multiple implementations of a 'student' class in C++ with varying constructors, member functions, and static variables. It demonstrates the use of static members to track the number of instances and displays roll numbers and values of static variables. The document also includes multiple 'main' functions to test the functionality of the class.

Uploaded by

hemayatkhan7374
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views11 pages

Static Variables Lab

The document contains multiple implementations of a 'student' class in C++ with varying constructors, member functions, and static variables. It demonstrates the use of static members to track the number of instances and displays roll numbers and values of static variables. The document also includes multiple 'main' functions to test the functionality of the class.

Uploaded by

hemayatkhan7374
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

class student class student

{ {
int roll; int roll;
char name[20]; char name[20];
int i;
public: public:
void display() void display()
{ {
printf("%d ", roll); printf("%d ", roll);
puts(name); puts(name);
} }
}; };

void main() void main()


{ {
student s1; student s1;
student s2; student s2;
cout << sizeof(s1)<<endl; cout << sizeof(s1)<<endl;
cout << sizeof(s2)<<endl; cout << sizeof(s2)<<endl;
cout << sizeof(student)<<endl; cout << sizeof(student)<<endl;
cout << sizeof(student*)<<endl; cout << sizeof(student*)<<endl;
} }
class student class student
{ {
int roll; int roll;
char name[20]; char name[20];
int i; static int i;
public: public:
void display() void display()
{ {
cout<<roll<<endl; cout<<roll<<endl;
puts(name); puts(name);
} }
}; };

void main()
{
student s1;
student s2;
cout << sizeof(s1)<<endl;
cout << sizeof(s2)<<endl;
cout << sizeof(student)<<endl;
cout << sizeof(student*)<<endl;
}
class student class student
{ {
int roll; int roll;
static int i; static int i;
public: public:

student()
{
i = 1;
roll = i;
i++;
cout << "const of " << i << endl;
void display() }
{ void display()
cout << roll << endl; {
cout << roll << endl;
}
}
void show()
void show()
{
{
cout << i << endl;
cout << i << endl;
}
}
};
};

void main() void main()


{ {
student s1; student s1;
student s2; student s2;

s1.display(); s1.display();
s1.show(); s1.show();
} }

class student void main()


{ {
int roll; student s1;
static int i; s1.display();
public: s1.show();
}
student() void main()
{ {
student s1;
roll = i; student s2;
i++;
cout << "const of " << roll << endl; s1.display();
} s1.show();
void display() s2.display();
{ s2.show();
cout << "Value of Roll Number =" << roll << endl; }
}
void show()
{
cout <<"Value of i="<< i << endl;
}
};
int student::i = 0;
class student class student
{ {
int roll; int roll;
static int i; static int i;
public: public:

student() student()
{ {

roll = i; roll = i;
i++; i++;
cout << "const of " << roll << endl; cout << "const of " << roll << endl;
} }
void display() void display()
{ {
cout << "Value of Roll Number =" << roll << endl; cout << "Value of Roll Number =" << roll << endl;
} }
void show() void show()
{ {
cout <<"Value of i="<< i << endl; cout <<"Value of i="<< i << endl;
} }
}; };
int student::i = 100; int student::i = 1000;

void main() void main()


{ {
student s1; student s1;
student s2; student s2;

s1.display(); s1.display();
s1.show(); s1.show();
s2.display(); s2.display();
s2.show(); s2.show();
} }
class student class student
{ {
int roll; int roll;
static int i; static int i;
public: public:

student() student()
{ {
i++;
roll = i; roll = i;
i++;
cout << "const of " << roll << endl; cout << "const of " << roll << endl;
} }
void display() void display()
{ {
cout << "Value of Roll Number =" << roll << endl; cout << "Value of Roll Number =" << roll << endl;
} }
void show() void show()
{ {
cout <<"Value of i="<< i << endl; cout <<"Value of i="<< i << endl;
} }
}; };
int student::i = 0; int student::i = 0;

void main() void main()


{ {
student s1; student s1;
student s2; student s2;

s1.display(); s1.display();
s1.show(); s1.show();
s2.display(); s2.display();
s2.show(); s2.show();
} }
class student
{
int roll;
static int i;
public:
student()
{
i++;
roll = i;
cout << "const of " << roll << endl;
}
student(int num)
{
i = i + 10;
roll = i;
cout << "11111111 const of " << roll <<
endl;
}

void display()
{
cout << "Value of Roll Number =" << roll << endl;
}
void show()
{
cout <<"Value of i="<< i << endl;
}
};
int student::i = 0;
void main() void main()
{ {
student s1; student s1(1);
student s2(2); student s2;

s1.display(); s1.display();
s1.show(); s1.show();
s2.display(); s2.display();
s2.show(); s2.show();
} }
class student void main()
{ {
int roll; student s1;
static int i; student s2;
static int j;
public: s1.display();
student() s1.show();
{ s2.display();
i++; s2.show();
roll = i; }
cout << "const of " << roll << endl; void main()
} {
student(int num) student s1;
{ student s2(2);
i = i + 1;
roll = i; s1.display();
cout << "11111111 const of " << roll << s1.show();
endl; s2.display();
z } s2.show();
~student() }
{ void main()
j++; {
cout << "dstr of " << roll << endl; student s1;
cout << "i " << i << endl; s1.display();
cout << "j " << j << endl; s1.show();
} student s2;
void display() s2.display();
{ s2.show();
cout << "Value of Roll Number =" << roll << endl; }
} void main()
void show() { student s1;
{ s1.display();
cout << "Value of i=" << i << endl; s1.show();
cout << "Value of j=" << j << endl; student s2(2);
} s2.display();
}; s2.show();
int student::i = 0; }
int student::j = 0;

void main()
class student {
{ student s1;
int roll; s1.show();
static int i; student s2(2);
static int j; s2.show();
}
public: void main()
student() {
{ student s1;
i++; s1.show();
roll = i; {
cout << "const of " << roll << endl; student s2(2);
} s2.show();
student(int num) }
{ student s3;
i = i + 1; }
roll = i; void main()
cout << "11111111 const of " << roll << {
endl; student s1;
z } s1.show();
~student() {
{ student s2(2);
j++; s2.show();
cout << "dstr of " << roll << endl; }
cout << "i " << i << endl; student s3;
cout << "j " << j << endl; s3.show();
} }
void display() void main()
{ {
cout << "Value of Roll Number =" << roll << endl; student s1;
} s1.show();
void show() {
{ student s2(2);
cout << "Value of Roll Number =" << roll << endl; s2.show();
cout << "Value of i=" << i << endl; }
cout << "Value of j=" << j << endl; student s3;
} s2.show();
}; }
int student::i = 0;
int student::j = 0;
class student class student
{ {
int roll; int roll;
static int i; static int i;
static int j; static int j;
public: public:
student() student()
{ {
i++; i++;
roll = i; roll = i;
cout << "const of " << roll << endl; cout << "const of " << roll << endl;
} }
student(int num) student(int num)
{ {
i = i + 1; i = i + 1;
roll = i; roll = i;
cout << "11111111 const of " << roll << cout << "11111111 const of " << roll <<
endl; endl;
z } z }
~student() ~student()
{ {
j++; j++;
cout << "dstr of " << roll << endl; cout << "dstr of " << roll << endl;
cout << "i " << i << endl; cout << "i " << i << endl;
cout << "j " << j << endl; cout << "j " << j << endl;
} }
void display() void display()
{ {
cout << "Value of Roll Number =" << roll << endl; cout << "Value of Roll Number =" << roll << endl;
cout << "Value of i=" << i << endl; cout << "Value of i=" << i << endl;
cout << "Value of j=" << j << endl; cout << "Value of j=" << j << endl;
} }
void show() static void show()
{ {
cout << "Value of Roll Number =" << roll << endl; cout << "Value of Roll Number =" << roll << endl;
cout << "Value of i=" << i << endl; cout << "Value of i=" << i << endl;
cout << "Value of j=" << j << endl; cout << "Value of j=" << j << endl;
} }
}; };
int student::i = 0; int student::i = 0;
int student::j = 0; int student::j = 0;
void main() void main()
{ {
student s1; student s1;
s1.show(); s1.show();
s1.display(); s1.display();
} }

void main()
{

student::show();
student::display();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy