Home
Welcome To Page # 2 Of
C++ Programs
All the given programs are thoroughly
checked & debugged and there is full guarantee for each and every program
execution.
LAB # 4
Solution # 1
#include<iostream.h>
#include<conio.h>
class integer
{
int i;
public:
void get_i()
{
cout<<"enter the value of i=";
cin>>i;
}
void print_i()
{
cout<<"i="<<i<<endl;
}
};
void main(void)
{ clrscr();
integer myint;
myint.get_i();
myint.print_i();
getch();
}
Solution # 2
#include<iostream.h>
#include<conio.h>
class print
{
int i;
public:
void display()
{
cout<<"This is my First class";
}
};
void main(void)
{
clrscr();
print p;
p.display();
getch();
}
Solution # 3
#include<iostream.h>
#include<conio.h>
class rectangle
{
int length;
int width;
public:
void get()
{
cout<<"Enter length :"<<endl;
cin>>length;
cout<<"Enter width :"<<endl;
cin>>width;
}
void perimeter()
{
int peri=2*(length+width);
cout<<"\nPerimeter is="<<peri;
}
void area()
{
int area=length*width;
cout<<"\nArea is="<<area;
}
};
void main(void)
{
clrscr();
rectangle rect;
rect.get();
rect.perimeter();
rect.area();
getch();
}
Solution # 4
#include<iostream.h>
#include<conio.h>
class arithmetic
{
int num1;
int num2;
public:
void get()
{
cout<<"Enter two numbers=";
cin>>num1>>num2;
}
void print()
{
cout<<"\nTwo entered numbers are\t"<<num1<<"and\t"<<num2;
}
void add()
{
cout<<"\nSum of two numbers entered is="<<num1+num2;
}
void subtract()
{
cout<<"\n Difference f two numbers is="<<num1-num2;
}
void multiply()
{
cout<<"\nProduct of two numbers is="<<num1*num2;
}
void divide()
{
cout<<"\nDivision of two numbers="<<num1/num2;
}
void modulus()
{
cout<<"\nModulus of ist number over second ="<<num1%num2;
}
};
void main(void)
{
clrscr();
arithmetic ar;
ar.get();
ar.print();
ar.add();
ar.subtract();
ar.multiply();
ar.divide();
ar.modulus();
getch();
}
Solution # 5
#include<iostream.h>
#include<conio.h>
class program
{
int num1;
int num2;
public:
void get()
{
cout<<"Enter two numbers=";
cin>>num1>>num2;
}
void mod()
{
cout<<"Modulus of two numbers="<<num1%num2;
}
};
void main(void)
{
clrscr();
program prog;
prog.get();
prog.mod();
getch();
}
LAB # 5
Solution # 1
#include<iostream.h>
#include<conio.h>
void main(void)
{
int intupperbound=32767,intlowerbound=-32768;
clrscr();
cout<<"intupperbound="<<intupperbound<<endl;
cout<<"intlowerbound="<<intlowerbound<<endl;
cout<<"intupperbound+1="<<intupperbound+1<<endl;
cout<<"intlowerbound-1="<<intlowerbound-1<<endl;
getch();
}
Solution # 2
#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
cout<<"Size of int in bytes="<<sizeof(int);
cout<<"\nSize of float in bytes="<<sizeof(float);
cout<<"\nSize of double in bytes="<<sizeof(double);
cout<<"\nSize of character in bytes="<<sizeof(char);
getch();}
Solution # 3
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main(void)
{ clrscr();
int x=111,y=222;
float z=34.456;
cout<<x<<y<<z<<endl;
cout<<setw(10)<<x<<setw(10)<<y<<setw(10)<<z<<endl;
cout<<setfill('*');
cout<<setw(10)<<x<<setw(10)<<y<<setw(10)<<z<<endl;
cout<<setprecision(2)<<z<<endl;
getch();}
Solution # 4
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class fsn
{
int i;
float f;
double d;
public:
void get()
{
cout<<"Enter value for int,float& double:";
cin>>i;
cin>>f;
cin>>d;
}
void print()
{
cout<<"Enterd integer was\t="<<i<<"\nEntered float was\t="
<<f<<"Entered double was\t="<<d;
}
void pri()
{
cout<<setw(10)<<"\nInteger is="<<i<<setfill('-')
<<setw(15)<<"float is="<<f<<setfill('-')
<<setw(15)<<"double is="<<d<<setfill('-');
}
};
void main(void)
{
clrscr();
fsn fa;
fa.get();
fa.print();
fa.pri();
getch();
}
Labs from 4 & 5 are on this page.
Wanna query about any program or suggestions. Mail us on : -
[email protected]
©2001.All rights reserved
by www.2k1cp.com.