Вы находитесь на странице: 1из 28

OOP Asssignment no 3 Lab 3

Program no 1
#include<iostream.h>

#include<conio.h>

class integer

int i;

public:

void get_i() {cout<<"Enter the value of i=\t"; cin>>i;}

void print_i() {cout<<"i="<<i<<endl;}

};

void main()

{clrscr();

integer myint;

myint.get_i();

myint.print_i();

getch();

Output(12-EE-133)

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 3

Program no2
#include<iostream.h>

#include<conio.h>

class arithmatic

{int a,b,summation,difference,product;

public:

void data()

cout<<"enter num1 to be operated=";

cin>>a;

cout<<"enter num2 to be operated=";

cin>>b;

void sum()

{ summation=a+b;

cout<<" Sum of entered numbers is="<<summation<<"\n";

void diff()

{ difference=a-b;

cout<<"Difference of entered number is="<<difference<<"\n";

void prod()

{product=a*b;

cout<<"product of entered numbers is="<<product;

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 3

}};

void main()

{clrscr();

arithmatic am;

am.data();

am.sum();

am.diff();

am.prod();

getch();

Output(12-EE-133)

Program no 3
#include<iostream.h>

#include<conio.h>

class integer

{ int a;

public:

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 3

void get()

cout<<"enter the digit=";

cin>>a;

void comp()

{ if (a>0) cout <<"positive";

else cout<<"negative";}

};

void main()

clrscr();

integer s1;

s1.get();

s1.comp();

getch();

Output(12-EE-133)

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 4

Program no 1
#include<iostream.h>

#include<conio.h>

class triangle

{int b,h,p,peri;

public:

void input()

{ cout<<"base of triangle=";

cin>>b;

cout<<"hypotinuse of triangle=";

cin>>h;

cout<<"perpendicular of triangle=";

cin>>p;

void result()

{peri=b+h+p;

if (h+b>p) cout<<"Perimeter oftriangle is ="<<peri<<"\n";

else cout<<"invalid";

}};

void main()

{clrscr();

triangle s;

s.input();

s.result();

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 4

getch();

Output(12-EE-133)

Program no 2
#include<iostream.h>

#include<iomanip.h>

#include<conio.h>

class variables

{ int a;

private:

float b;

private:

double c;

public:

void getdata()

{ cout<<"integer=";

cin>>a;

cout<<"float=";

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 4

cin>>b;

cout<<"private=";

cin>>c;}

void display()

cout<<setfill('=')<<setw(11)<<a<<setw(13)<<b<<setw(16)<<c<<endl;

}};

void main()

{clrscr();

variables s2;

s2.getdata();

s2.display();

getch();}

Output(12-EE-133)

Program no 3
#include<iostream.h>

#include<conio.h>

void main()

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 4

clrscr();

int i, j=2, k=4;

i=(j>3)&&(++k==6);

cout<<"i="<<i<<"j="<<j<< "k="<<k<<endl;

i=(j<3)&&(++k==6);

cout<<"i="<<i<<"j="<<j<<"k="<<k;

getch();

Output(12-EE-133)

Program no 4
#include<iostream.h>

#include<conio.h>

class result

{ int a;

public:

void input()

{ cout<<"Enter your marks =";

cin>>a;

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 4

void grade()

{ if (a>0 && a<=49) cout<<"Fails"<<endl;

if (a>49 &&a<=59) cout<<"your grade is 'D'"<<endl;

if (a>59 && a<=69) cout<<"your grade is 'C'"<<endl;

if (a>69 && a<=79) cout<<"your grade is 'B'"<<endl;

if (a>79 && a<=89) cout<<"your grade is 'A'"<<endl;

if (a>89 && a<=100) cout<<"your grade is 'A+'"<<endl;

if (a<0 && a>100) cout<<"invalid marks";

}};

void main()

{ clrscr();

result s;

s.input();

s.grade();

getch();}

Output(12-EE-133)

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 5

Program no 1
#include<iostream.h>

#include<conio.h>

typedef int bool;

const bool true=1,false=0;

void main()

clrscr();

long num=0,count=0,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

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 5

Output(12-EE-133)

Program no 2
#include<iostream.h>

#include<conio.h>

void main()

int n,sum=0,count=0;

float avg;

clrscr();

cout<<"Enter number > 0: \n";cin>>n;

while(!cin.eof())

if (cin.fail())

cin.clear();

cout<<"\a Error "<<char(cin.get())<<" ? \n";

else if (n<=0)

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 5

cout<<"\a number : "<<n<<"<=0 ? \n";

else

count++;

sum+=n;

cout<<"enter number > 0 : \n";

cin>>n;

avg=float(sum)/float(count);

cout<<"\n average= "<<avg;

getch();

Output(12-EE-133)

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

Program no 1
# include<iostream.h>

# include<conio.h>

class Rectangle

{ int l,w;

public:

void input() {cout<<"Enter length:\a\t";

cin>>l;

cout<<"Enter width:\t:";

cin>>w;

void printlenght()

{cout<<"Length="<<l<<endl;}

void printwidth()

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

{cout<<"Width="<<w<<endl;

void Perimeter() {int p;

p=2*(l+w);

cout<<"Perimeter="<<p<<endl;}

void Area() {int a;

a=l*w;

cout<<a<<endl;

};

void main()

{ char op;

Rectangle rect;

rect.input();

cout<<"Enter any character.";

cin>>op;

switch(op)

{case ('l'):

rect.printlenght(); break;

case('w'):

rect.printwidth(); break;

case ('p'):

rect.Perimeter(); break;

case ('a'):

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

rect.Area(); break;

default:

cout<<"Invalid Input";

getch();

Output(12-EE-133)

Program no 2
1) Table of three
#include<iostream.h>

#include<conio.h>

void main(void)

clrscr();

int tab=3,a,b;

for(a=1;a<=10;a++)

{b=tab*a;

cout<<tab<<"*"<<a<<"="<<b<<endl;

getch();

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

Output(12-EE-133)

2) Numbers from 10 to 0
#include<iostream.h>

#include<conio.h>

void main(void)

clrscr();

for(int a=10;a>=0;a--)

{cout<<a;

getch();

Output(12-EE-133)

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

3) Odd numbers between 20 and 30


#include<iostream.h>

#include<conio.h>

void main(void)

clrscr();

for(int a=20;a<=30;a++)

{if(a%2!=0)

{cout<<a<<endl;

}}

getch();

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

Output(12-EE-133)

4) Numbers from 1 to 20 in step of 3


#include<iostream.h>

#include<conio.h>

void main(void)

clrscr();

for(int a=1;a<=20;a+=3)

{cout<<a<<endl;

getch();

Output(12-EE-133)

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

Program no 3
# include<iostream.h>

# include<conio.h>

void main()

{for(int j=1; j<=3; j++)

{ for(int k=1; k<=j; k++)

{cout<<"^";

if(k==j) cout<<k;}

cout<<endl;}

getch();

Output(12-EE-133)

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

Program no 4
#include<iostream.h>

#include<conio.h>

void main(void)

clrscr();

int n;

long int f=1;

cout<<"Enter number for factorial=";

cin>>n;

for(;n>=1;n--)

f=f*n;

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

cout<<"Factorial="<<f<<endl;

getch();

Output(12-EE-133)

Program no 6
#include<iostream.h>

#include<conio.h>

main()

{clrscr();

int a,b,c,d;

for(a= 0;a<=14;a=a+4)

{ for (b=1,d=0;b<=4;b+=1)

{c=a+b;

cout<<c<<"\t";d=d+c;}cout<<d;

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

cout<<endl;

getch();

return 0;}

Output(12-EE-133)

Program no 7
#include<iostream.h>

#include<conio.h>

main()

clrscr();

cout<<"Enter a string of your choice : \n";

char ch;

int total=0;

for (;;)

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

cin.get(ch);

if (cin.eof())

break;

else if (ch=='\xFF')

continue;

else

total++;

cout<<"total letters = "<<total<<endl;

getch();

return 0;

Output(12-EE-133)

Program no 8
#include<iostream.h>

#include<conio.h>

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

int v=10;

void main(void)

cout<<"global v="<<v<<endl;

v=15;

int v=20;

cout<<"local v="<<v<<endl;

cout<<"modified global v="<<::v<<endl;

int v=30;

v=25;

cout<<"local v="<<v<<endl;

cout<<"modified global v="<<::v<<endl;

getch();

Output(12-EE-133)

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

Program no 9
#include<iostream.h>

#include<conio.h>

void main(void)

clrscr();

int a,b;

cout<<"enter first value = \n";

cin>>a;

cout<<"enter second value=\n";

cin>>b;

cout<<a%b)<<endl;

getch();

Output(12-EE-133)

Sohail Akhtar 12-EE-133 A2


OOP Assignment no 3 Lab no 6

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 6

Sohail Akhtar 12-EE-133 A2


OOP Asssignment no 3 Lab 6

Sohail Akhtar 12-EE-133 A2

Вам также может понравиться