Lab Manual

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

PRACTICAL:2

DEVELOP 3 PROGRAM USING CIN AND COUT


PRACTICAL 2.1
Aim: Write a program to display a hello world using cout
INPUT:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"Hello world";
getch();
}

OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


PRACTICAL 2.2
Aim: Write a program to display Addition of Three number
INPUT:
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"enter value of a,b,c";
a=10;
b=20;
c=30;
c=a+b+c;
cout<<"result"<<a+b+c;
getch();
}

OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


PRACTICAL 2.3
Aim: Write a program to display addition of 3 number using user input.
INPUT:
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c,add;
clrscr();
cout<<"enter value of a,b,c";
cin>>a>>b>>c;
add=a+b+c;
cout<<"addition="<<add;
getch();
}

OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


PRACTICAL:3
Develop programs using scope resolution operator, simple
manipulators and enumeration.
PRACTICAL 3.1
Aim: write a program to demonstrate use of scope resolution operator.
INPUT:
#include<iostream.h>
#include<conio.h>
int a=30;
void main()
{
clrscr();
int a=10;
cout<<"value of local a="<<a;
cout<<"\nvalue of global a="<<::a;
getch();
}

OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


PRACTICAL 3.2
Aim: write a program to demonstrate use of endl and set precision
manipulation.
INPUT:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
float a=22.326789,b=22.326789,c=22.326789,d=22.326789;
clrscr();
cout<<a<<endl<<setprecision(3)<<b<<endl<<c<<endl<<setprecision(2)<<d<<endl;
getch();
}

OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


PRACTICAL 3.3
Aim: write a program to demonstrate use of enum keyword.
INPUT:
#include<iostream.h>
#include<conio.h>
void main()
{
enum GENDER {male,female};
clrscr();
GENDER gender=male;
switch(gender)
{
case male:
cout<<"gender is male";
break;
case female:
cout<<"gender is female";
break;
default:
cout<<"value can be male or female";
}
getch();
}

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


PRACTICAL:4
Develop programs using call by reference and return by
reference, default arguments, constant argument, inline and function
overloading.
PRACTICAL 4.1
Aim: write a program to demonstrate using call by reference.
INPUT:
#include<iostream.h>
#include<conio.h>
void swap(int&,int&);
void main()
{
int x,y;
clrscr();
cout<<"enter two number:"<<endl;
cin>>x>>y;
swap(x,y);
cout<<"after swapping:"<<endl;
cout<<x<<" "<<endl<<y;
getch();
}
void swap(int&a,int&b)
{
int temp;
temp=a;
a=b;
b=temp;
}

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


PRACTICAL 4.2
Aim: write a program to demonstrate use of return by reference.
INPUT:
#include<iostream.h>
#include<conio.h>
int x=10;
int& retbyref()
{
return x;
}
void main()
{
retbyref();
cout<<x;
getch();
}

OUTPUT:

PRACTICAL 4.3
Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093
Aim: write a program to demonstrate use of default arguments.
INPUT:
#include<iostream.h>
#include<conio.h>
void set_point(int x,int y=0);
void main()
{
int p,q;
cout<<"enter x coordinate";
cin>>p;
set_point(p);
cout<<"enter x and y coordinate";
cin>>p>>q;
set_point(p,q);
getch();
}
void set_point(int x,int y)
{
cout<<x<<" "<<y;
}

OUTPUT:

PRACTICAL 4.4
Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093
Aim: write a program to demonstrate use of inline function.
INPUT:
#include<iostream.h>
#include<conio.h>
const float Pi=3.14;
inline float area(int r)
{
return(Pi*r*r);
}
void main()
{
clrscr();
int ra;
cout<<"enter radius";
cin>>ra;
cout<<"area of circle"<<area(ra);
getch();
}

OUTPUT:

PRACTICAL 4.5

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


Aim: write a program to demonstrate use of function overloading.
INPUT:
#include<iostream.h>
#include<conio.h>
const float Pi=3.14;
float area(int r)
{
return(Pi*r*r);
}
float area(int l,int b,int h)
{
return(l*b*h);
}
void main()
{
clrscr();
int ra,la,ba,ha;
cout<<"enter radius";
cin>>ra;
cout<<"area of circle="<<area(ra);
cout<<"enter length,breath,height";
cin>>la>>ba>>ha;
cout<<"area of rect="<<area(la,ba,ha);
getch();
}

OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


PRACTICAL:5

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


Aim: Develop programs using structure.
INPUT:
#include<iostream.h>
#include<conio.h>
struct student
{
int rollno;
char *name;
int marks;
}s1,s2;
void main()
{
s1.rollno=93;
s1.name="yashti";
s1.marks=94;
clrscr();
cout<<s1.rollno<<endl<<s1.name<<endl<<s1.marks;
getch();
}

OUTPUT:

PRACTICAL:6
Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093
Define minimum 5 different classes such as student, distance,
shape, employee, account, inventory, vector, movie-ticket booking, time,
point, etc. with data member & member functions. Also develop programs
to test those classes functionality.
PRACTICAL 6.1
Aim: Develop a class student with data member & member function.
INPUT:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class student
{
private:
int rollnum;
char name[20];
public:
void getdata()
{
cout<<"Enter roll number:";
cin>>rollnum;
cout<<"Enter name:";
cin>>name;
}
void putdata()
{
cout<<"Your name is:"<<name<<endl;
cout<<"Your roll number is:"<<rollnum;
}
};
void main()
{
student s1;
clrscr();
s1.getdata();
s1.putdata();
getch();
}

OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093
PRACTICAL:6.2
Aim: Develop a class distance with data member & member function.
INPUT:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class distance
{
int feet,inch;
public:
void set_distance()
{
cout<<"Enter feet:";
cin>>feet;
cout<<"Enter inch:";
cin>>inch;
}
void get_distance()
{
cout<<"Feet are:"<<feet<<"\tInch are:"<<inch;
}
void add(distance d1,distance d2)
{
feet=d1.feet+d2.feet;
inch=d1.inch+d2.inch;
feet=feet+(inch/12);
inch=inch%12;
}
};
void main()
{
distance d1,d2,d3;
clrscr();
d1.set_distance();
d2.set_distance();
d3.add(d1,d2);
d3.get_distance();
getch();
}

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


PRACTICAL:6.3
Aim: Write a program to demonstrate use of employee.
INPUT:
#include<iostream.h>
#include<conio.h>
class emp
{
int emp_no;
clrscr();
char emp_name[20];
float emp_basic;
float emp_da;
float emp_it;
float emp_net_sal;
public:
void get_emp_detail();
float find_net_sal(float basic,float da, float it);
void show_emp_detail();
};
void emp::get_emp_detail()
{
cout<<"enter emp basic";
cin>>emp_basic;
cout<<"enter emp_da";
cin>>emp_da;
cout<<"enter emp_it";
cin>>emp_it;
}
float emp::find_net_sal(float basic,float da,float it)
{
return(basic+da)-it;
}
void emp::show_emp_detail()
{
cout<<"enter emp_basic";
cout<<"enter emp_da";
cout<<"enter emp_it";
cout<<"net salary="<<find_net_sal(emp_basic,emp_da,emp_it);
}
void main()
{

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093


emp e;
e.get_emp_detail();
e.show_emp_detail();
getch();
}
OUTPUT:

Basic Object Orianted Programming [4320702] ENROLMENT NO.: 239830331093

You might also like