Home
Welcome To The Programming
Page#3 Of 2k1CP
All the given programs are thoroughly checked &
debugged and there is full guarantee for each and every program execution.
LAB # 6
Solution # 1
#include<iostream.h>
#include<conio.h>
class integer
{
int i;
public:
void get()
{
cout<<"Enter the value of i=";
cin>>i;
}
void print()
{
if(i>0)
cout<<"positive";
if(i<0)
cout<<"negative";
}
};
void main(void)
{ clrscr();
integer myint;
myint.get();
myint.print();
getch();
}
Solution # 2
#include<iostream.h>
#include<conio.h>
class triangle
{
int a,b,c;
public:
void input()
{
cout<<"Enter three sides of triangle=";
cin>>a>>b>>c;
}
void validate()
{
if((b+c)>a||(a+c)>b||(a+b)>c)
cout<<"\n\tValid";
else
cout<<"\n\tInvalid";
}
void print()
{
cout<<"\nThree sides are..."<<endl;
cout<<a<<"\n"<<b<<"\n"<<c;
}
};
void main(void)
{
clrscr();
triangle tri;
tri.input();
tri.validate();
tri.print();
getch();
}
Solution # 3
#include<iostream.h>
#include<conio.h>
void main(void)
{
int x=10;
clrscr();
cout<<x<<endl;
cout<<++x<<endl;
cout<<x<<endl;
x=10;
cout<<x<<endl;
cout<<x++<<endl;
cout<<x<<endl;
getch(); }
Solution # 4
#include<iostream.h>
#include<conio.h>
typedef int bool;
const bool true=1;
const bool false=0;
void main(void)
{ clrscr();
bool var=true;
if(var)cout<<"true"<<endl;
else
cout<<"false"<<endl;
var=false;
if(var)cout<<"true"<<endl;
else cout<<"false"<<endl;
getch();
}
LAB # 7
Solution # 1
#include<iostream.h>
#include<conio.h>
void main(void)
{ clrscr();
int a,b,c;
a=b=c=1;
cout<<"a<++b results in:"<<(a<++b)<<endl;
cout<<"a<c++ results in:"<<(a<c++)<<endl;
cout<<"a=2 results in :"<<(a=2)<<endl;
cout<<"a==2 results in :"<<(a==2)<<endl;
getch();
}
Solution # 2
#include<iostream.h>
#include<conio.h>
void main(void)
{ clrscr();
int i=10,j;
j=2;
cout<<"(i*j++)+(i*j)="<<(i*j++)+(i*j)<<endl;
j=2;
cout<<"(i*j)+(i*j++)="<<(i*j)+(i*j++)<<endl;
j=2;
cout<<"(i*j++)+(i+j--)="<<(i*j++)+(i*j--)<<endl;
j=2;
cout<<"(i*j--)+(i*j++)="<<(i*j--)+(i*j++)<<endl;
j=2;
cout<<"(i*++j)+(i*j)="<<(i*++j)+(i*j)<<endl;
j=2;
cout<<"(i*j)+(i*++j)="<<(i*j)+(i*++j)<<endl;
j=2;
cout<<"(i*++j)+(i*--j)="<<(i*++j)+(i*--j)<<endl;
j=2;
cout<<"(i*--j)+(i*++j)="<<(i*--j)+(i*++j)<<endl;
getch();
}
Solution # 3
#include<iostream.h>
#include<conio.h>
void main(void)
{ clrscr();
int i,j=2,l=4;
i=(j>3)&&(++l==6);
cout<<"i="<<i<<"\tj="<<j<<"\tl="<<l<<endl;
i=(j<3)&&(++l==6);
cout<<"i="<<i<<"\tj="<<j<<"\tl="<<l;
getch();
}
Solution # 4
#include<iostream.h>
#include<conio.h>
class result
{ int marks;
public:
void input()
{ cout<<"enter marks :";
cin>>marks;
}
void grade()
{ if(marks<50)
cout<<"FAIL";
else if(marks>49&&marks<=59)
cout<<"Passed with C grade";
else if(marks>59&&marks<=69)
cout<<"Passed with B grade";
else if(marks>69&&marks<=79)
cout<<"Passed with A grade";
else if(marks>79&&marks<=100)
cout<<"Passed with A1 grade";
else if(marks>100&&marks<0)
cout<<"invalid marks";
else
cout<<"Never get here";}
};
void main(void)
{ clrscr();
result r;
r.input();
r.grade();
getch(); }
Solution # 6
#include<iostream.h>
#include<conio.h>
class rectangle
{
int length;
int width;
public:
void get()
{
cout<<"Enter length :"<<"\a";
cin>>length;
cout<<"\n Enter width :"<<"\a";
cin>>width;
}
void printlength()
{
cout<<"Length="<<length<<endl;
}
void printwidth()
{
cout<<"Width is="<<width<<endl;
}
void perimeter()
{ int peri;
peri=2*(length+width);
cout<<"Perimeter is="<<peri<<endl; }
void area()
{
int area;
area=length*width;
cout<<"Area is="<<area<<endl; }
};
void main(void)
{ char i,j,k,l;
clrscr();
rectangle rect;
rect.get();
cout<<"Enter l or L for printlength...\nEnter w for W for print width...\n"
<<"Enter p or P for perimeter...\nEnter a or A for area...";
cin>>i;
switch(i)
{
case'l':
case'L':
rect.printlength();
break;
case'w':
case'W':
rect.printwidth();
break;
case'p':
case'P':
rect.perimeter();
break;
case'a':
case'A':
rect.area();
break;
default:
cout<<"INVALID";}
getch();
}
LAB# 8
Solution # 1
#include<iostream.h>
#include<conio.h>
typedef int bool;
const bool true=1;
const bool false=0;
void main(void)
{
clrscr();
int num=0,count=0;
long sum=0;
bool check=true;
while(check)
{
++num;
if(num%2==1)
{
count++;
sum=sum+num;
cout<<sum<<endl;
check=(count<10);
}
}
cout<<"sum="<<sum;
getch();
}
Solution # 2
#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
char ch;
while(cin.get(ch),!cin.eof())
cout<<ch;
getch(); }
Solution # 3
#include<iostream.h>
#include<conio.h>
void main(void)
{
clrscr();
int n;
int sum=0,count=0;
float avg;
cout<<"Enter number>0...";
cin>>n;
while(!cin.eof())
{
if(cin.fail())
{
cin.clear();
cout<<"\a ERROR"<<char(cin.get())<<"?";
}
else if(n<=0)
cout<<"\a number:"<<n<<"<<=0?";
else
{
count++;
sum=sum+n;
}
cout<<"enter number>0...";
cin>>n;
}
avg=float(sum)/float(count);
cout<<"\nAverage="<<avg;
getch();
}
Solution # 5
#include<iostream.h>
#include<conio.h>
class fsn
{
int a,b;
public:
void input()
{
cout<<"Enter two integers...\n";
cin>>a>>b;
}
void print()
{
cout<<"Entered integers are "<< a<<" and "<< b<<endl;
}
void smaller()
{
if(a<b)
cout<<"Smaller of two ="<< a<<endl;
else
cout<<"Smaller of two= "<< b<<endl;
}
void greater()
{
if(a>b)
cout<<"Greater of two= "<< a<<endl;
else
cout<<"Greater of two= "<< b<<endl;
}
};
void main(void)
{
clrscr();
fsn f;
f.input();
f.print();
f.smaller();
f.greater();
getch();
}
Labs from 6-8 are on this page.
Wanna query about any program or suggestions. Mail us on : -
[email protected]
©2001.All rights
reserved by www.2k1cp.com.