You are on page 1of 12

1.

Calculate sum of two numbers


#include<iostream.h>

#include<conio.h>

class sum

private:

int n, m, sum;

public:

input()

cout<<"enter first number";

cin>>n;

cout<<"enter second number";

cin>>m;

print()

s=n+m;

cout<<"sum="<<s;

};

main()

sum obj;

obj.input();

obj.print();

}
output:

2.exchange values
#include<conio.h>

class abc

public:

exchange(int &a,int &b)

int t;

t=a;

a=b;

b=t;

};
main()

abc obj;

int m,n;

cout<<"enter first number in n";

cin>>n;

cout<<"enter second number in m";

cin>>m;

obj.exchange(n,m);

cout<<"values after exchange\n\n"

cout<<"values in m="<<m<<endl;

cout<<"values in n="<<n<<endl;

Output

3.greater of two numbers


#include<iostream.h>

#include<conio.h>
class ab

private:

int n,m;

public:

input()

cout<<"enter first number";

cin>>m;

cout<<"enter second number";

cin>>n;

test()

if(m>n)

cout<<"first number is greater";

else

cout<<"second number is greater";

};

main()

ab obj;

obj.input();

obj.test();

Output
4.largest set of 3 number
#include<iostream.h>

#include<conio.h>

class three

private:

int a,b,c;

public:

input()

cout<<"enter first number";

cin>>a;

cout<<"enter second number";

cin>>b;

cout<<"enter third number";

cin>>c;

}
test()

if(a>b)

if(a>c)

cout<<"first value is greater";

else

cout<<"Third value is greater";

else

if(b>c)

cout<<"second value is greater";

else

cout<<"Third value is greater";

};

main()

three obj;

obj.input();

obj.test();

Output
5.print natural num using for loop
#include<iostream.h>

#include<conio.h>

class abc

public:

print()

for( int c=1; c<=10;c++)

cout<<"c"<<endl;

};

main()

{
abc obj;

obj.print;

6.print num using while loop


#include<conio.h>

class abc

public:

print()

int i=1;

while(i<=10)

cout<<"i"<<endl;

i=i+1;

}
};

main()

abc obj;

obj.print();

Output

7.avg of 3 num
#include<iostream.h>

#include<conio.h>

class abc

public:

float mean(float a,float b)

return(a+b)/2;
}

};

main()

abc obj;

float m,n;

cout<<"enter first number"; cin>>m;

cout<<"enter second number"; cin>>n;

cout<<"mean of"<<m<<"&"<<"="<< obj.mean(m,n);

getch();

8.exchange vlue using sub algorithm


#include<conio.h>

class abc

{
public:

exchange(int &a,int &b)

int t;

t=a;

a=b;

b=t;

};

main()

abc obj;

int m,n;

cout<<"enter first number in n";

cin>>n;

cout<<"enter second number in n";

cin>>m;

obj.exchange(n,m);

cout<<"values after exchange\n\n"

cout<<"values in m="<<m<<endl;

cout<<"values in n="<<n<<endl;

Output

You might also like