You are on page 1of 16

LAB FILE WORK OF OOPS(C++)

1. #include<iostream>
using namespace std;

class student

public:

long int rollno;

char section;

char name[10];

void get()

cout<<"roll no."<<endl<<"section"<<endl<<"name"<<endl;

cin>>rollno>>section>>name;

void set()

cout<<rollno<<endl<<section<<endl<<name<<endl;

};

int main()

student s;

s.get();

s.set();
}

OUTPUT-

2.
#include<iostream>
using namespace std;
class studnet
{
public:
int rollno;
char section;
char name[20];
void get()
{
cin>>rollno>>section>>name;
cout<<rollno<<section<<name;
}
void set()
{
cout<<rollno<<section<<name;
}
};
int main()
{
studnet s[10];
for(int i=0;i<2;i++)
{
s[i].get();
s[i].set();
}

}
OUPUT

3. #include<iostream>
using namespace std;
class abc
{
public:
int a;
int b;
void getdata();
void setdata();
};
void abc::getdata()
{
cin>>a>>b;

} void abc::setdata()
{
cout<<a<<b;
}
int main()
{
abc a1;
a1.getdata();
a1.setdata();
}
OUPUT
4.
#include<iostream>
using namespace std;
class complex
{
public:
int a=0,b=0,real=0,img=0;
complex(){
a=0;
b=1;
}
complex(int x, int y){
real=x;
img=y;
}
complex(int l){
a=l;
}
void display(){
cout<<a<<b<<real<<img<<endl;
}
};

int main(){
complex c1;
c1.display();
complex c2(4);
c2.display();
complex c3(5,3);
c3.display();
}
OUTPUT

5.
#include<iostream>
#include<conio.h>
using namespace std;

class test
{
public:
int a;
test(){
a=1;
cout<<a;
}
~test(){

}
};

int main()
{
test t;
}
OUTPUT
6. #include<iostream>
using namespace std;
class test{
public:
int a,b;
void display(){
cout<<a<<endl<<b;
}
};

int main()
{
test t;
t.display();
}

OUTPUT

7.
#include<iostream>
using namespace std;
class example{
public:
int a,b;
example(int x, int y){
a=x;
b=y;
cout<<"Constructor Called"<<endl;
}
void display(){
cout<<a<<endl<<b;
}
};

int main(){
example o(10,20);
example o1=o;
o.display();
o1.display();
}
OUTPUT
8.
#include<iostream>
using namespace std;
class sample{
public:
int a;
sample(int x)
{
a=x;
}
void display(){
cout<<a<<endl;
}
};

int main(){
int s=0;
sample obj(s);
sample obj1=sample(5);
sample obj2=5;
obj.display();
obj1.display();
obj2.display();
}
OUTPUT
9.
#include<iostream>
using namespace std;
class student
{
public:
int rollno;
char section;
char name[10];
void get()
{
cin>>rollno>>section>>name;
}
void set()
{
cout<<rollno<<section<<name;
}
};
int main()
{
student*s;
s->get();
s->set();
}

OUTPUT

You might also like