Aleena Akram 22F-8801 Lab 8: Question No 1
Aleena Akram 22F-8801 Lab 8: Question No 1
22F-8801
LAB 8
QUESTION NO 1
#include<iostream>
using namespace std;
class student
{
int rollno;
int age;
public:
static int count ;
student()
{
age = 0;
rollno = 0;
count++;
}
student(int i, int n)
{
age=i;
rollno=n;
count++;
}
void get()
{
cout << "age " << age<<endl;
cout << "rollno " << rollno<<endl;
cout << "count " << count<<endl;
}
};
int student::count = 0;
int main()
{
student s1(11, 12);
student s2(13, 14);
student s3(15, 16);
student s4(17, 18);
s1.get();
s2.get();
s3.get();
s4.get();
system("pause");
}
QUESTION NO 2
#include<iostream>
using namespace std;
class student
{
int rollno;
int age;
public:
static int count ;
student()
{
age = 0;
rollno = 0;
count++;
}
student(int i, int n)
{
age=i;
rollno=n;
count++;
}
void increase_count()
{
count = count + 2;
cout << "increase count " << count << endl;
}
void reset_count()
{
count = count / 2;
cout << "reset count " << count << endl;
}
void get()
{
cout << "age " << age<<endl;
cout << "rollno " << rollno<<endl;
cout << "count " << count<<endl;
increase_count();
reset_count();
}
};
int student::count = 0;
int main()
{
student s1(11, 12);
student s2(13, 14);
student s3(15, 16);
student s4(17, 18);
s1.get();
s2.get();
s3.get();
s4.get();
system("pause");
}
QUESTION NO 3
#include<iostream>
using namespace std;
class student
{
int rollno;
int age;
public:
static int count;
student()
{
age = 0;
rollno = 0;
count++;
}
student(int i, int n)
{
age = i;
rollno = n;
count++;
}
void increase_count()
{
count = count *2;
cout << "increase count " << count << endl;
}
void reset_count()
{
count = count / 2;
cout << "reset count " << count << endl;
}
void get()
{
cout << "age " << age << endl;
cout << "rollno " << rollno << endl;
cout << "count " << count << endl;
increase_count();
reset_count();
}
};
int student::count = 0;
int main()
{
student *p1, *p2, *p3, *p4;
student s1(11, 12);
p1 = &s1;
student s2(13, 14);
p2 = &s2;
student s3(15, 16);
p3 = &s3;
student s4(17, 18);
p4 = &s4;
(*p1).get();
(*p2).get();
(*p3).get();
(*p4).get();
system("pause");
}
QUESTION NO 4
#include<iostream>
using namespace std;
class stud {
private:
int a;
int b;
int c;
public:
void set(int a, int b, int c)
{
this->a = a;
this->b = b;
this->c = c;
}
void get()
{
cout << a << "\t" << b << "\t" << c;
}
};
int main()
{
stud s1;
s1.set(5, 6, 7);
s1.get();
system("pause");
return 0;
}
QUESTION NO 5
#include<iostream>
using namespace std;
class stud {
private:
const int a = 10;
int b;
const int c=5;
public:
stud() {
b = 10;
};
void set(int b)
{
b = b;
}
void get()
{
cout << "b " <<b<<endl;
}
void display()const
{
cout << "a " << a << endl;
cout << "c " << c << endl;
}
};
int main()
{
stud s2;
s2.set(6);
s2.get();
s2.display();
system("pause");
}
QUESTION NO 6
#include<iostream>
#include<string>
using namespace std;
class student
{
public:
int rollno;
int age;
string name;
};
class player :public student
{
public:
int score;
string sports_type;
};
int main()
{
player p;
p.age = 18;
p.rollno = 3;
p.name = "Aleena";
p.sports_type = "volley";
p.score = 5;
cout << "AGE= " << p.age << endl;
cout << "name= " << p.name << endl;
cout << "roll no= " << p.rollno << endl;
cout << " sports type= " << p.sports_type << endl;
cout << " score= " << p.score << endl;
system("pause");
}
QUESTION NO 7
#include<iostream>
#include<string>
using namespace std;
class student
{
public:
int rollno;
int age;
string name;
};
class player :public student
{
public:
int score;
string sports_type;
};
int main()
{
player p[10];
for (int i = 0; i < 10; i++)
{
cout << "enter name " << endl;
cin>>p[i].name;
cout << "enter age " << endl;
cin >> p[i].age;
cout << "enter rollno " << endl;
cin >> p[i].rollno;
cout << "enter score" << endl;
cin >> p[i].score;
cout << "enter sports type " << endl;
cin >> p[i].sports_type;
}
for (int i = 0; i < 10; i++)
{
cout <<"name= " <<p[i].name << endl;
cout <<"age= "<< p[i].age << endl;
cout<<"rollno= "<< p[i].rollno << endl;
cout<< "score= " <<p[i].score << endl;
cout<< "sports type= "<<p[i].sports_type << endl;
}
system("pause");
}