Sie sind auf Seite 1von 28

1.

WAP TO PRINT HELLO IN C++:-

#include<iostream.h>

void main()

//WAP in C++ to print the hello msg on the screen

cout<<"Hello Welcome in the world of C++";

getch();

Output:-

2. WAP in C++ for addition of two numbers:-

#include<conio.h>

#include<iostream.h>

void main()

//WAP in C++ for addition of two numbers


{

int a,b,sum;

clrscr();

cout<<"Enter the value of a,b ";

cin>>a>>b;

sum=a+b;

cout<<"The sum of two numbers are shown here for you = " <<sum;

getch();

Output:-

3. #include<conio.h>

#include<iostream.h>

void main()

//WAP TO SUB TWO NO.//

int a,b,sub;

clrscr();

cout<<"enter two no.";

cin>>a>>b;

sub=a-b;

cout<< a << "-" << b<<"=" <<sub;

getch();

}
OUTPUT:-

4TH.

#include<conio.h>

#include<iostream.h>

void main()

//WAP in C++ for multiplication between two numbers//

int a,b,mult;

cout<<"Enter the values of a,b";

cin>>a>>b;

mult=a*b;

cout<<"The Multiplications of two numbers are ="<<mult;

getch();

OUPUT:-

5TH. #include<conio.h>

#include<iostream.h>

void main()
//WAP TO DIVIDE BETWEEN TWO NUMBERS//

int a,b,div;

clrscr();

cout<<"enter two numbers";

cin>>a>>b;

div=a/b;

cout<<"the div of two no."<<div;

getch();

Output:-

6. #include<conio.h>

#include<iostream.h>

void main()

int num1,num2,temp;

clrscr();

cout<<"enter 1st number:";

cin>>num1;
cout<<"enter 2nd number:";

cin>>num2;

//displaying numbers before swapping

cout<<"before swapping:first number:"<<num1<<"second


number:"<<num2;

//swapping

temp=num1;

num1=num2;

num2=temp;

//displaying numbers after swapping

cout<<"\nafter swapping: first number:"<<num1<<"second number:


"<<num2;

getch();

OUTPUT:-

7.wap of bitwise operator:-

#include<conio.h>

#include<iostream.h>

#include<iomanip.h>

void main()

int a=8,b=15;

clrscr();
cout<<"a^b is"<<(a^b)<<endl;

cout<<"a&b is"<<(a&b)<<endl;

cout<<"a/b is"<<(a/b)<<endl;

cout<<"a<<3 is"<<(a<<3)<<endl;

cout<<"a>>3 is"<<(a>>3)<<endl;

cout<<"a is"<<a<<endl;

getch();

Output:-

8.wap to fIND THE SIMPLE INTEREST:

#include<conio.h>

#include<iostream.h>

//WAP in C++ to find the simple interest//

void main()

clrscr();

float p,r,t,SI;

cout<<"Enter the values of p,r,t";

cin>>p>>r>>t;

SI=(p*r*t)/100;

cout<<"Your result is="<<SI;


getch();

OUTPUT:

9TH. WAP IN C++ TO FIND THE BIGGEST NUMBER IN THE THREE NUMBERS:

#include<conio.h>

#include<iostream.h>

//WAP in c++ to find the greater among three numbers//

void main()

int a,b,c;

clrscr();

cout<<"Enter the values of a,b,c";

cin>>a>>b>>c;

if((a>b)&&(a>c))

{
cout<<"A is greater"<<a;

else if

cout<<"b is greater"<<b;

else

cout<<"c is grater"<<c;

getch();
}

OUTPUT:

10TH. WAP IN C++ TO FIND THE BIGGEST IN TWO NUMBERS:

#include<conio.h>

#include<iostream.h>

//WAP in c++ to find the greater among two numbers//

void main()

int a,b;

clrscr();

cout<<"Enter the values of a,b";

cin>>a>>b;

if(a>b)

cout<<"\n A is greater "<<a;

else

cout<<"\n b is greater"<<b;

getch();

OUTPUT:
11th.WAP FOR SCOPE RESOLUTION OPERATOR:-

#include<conio.h>

#include<iostream.h>

#include<iomanip.h>

int m=30;//global variable


void main()

clrscr();

int m=10; //local variable

cout<<"local m="<<m<<"\n";

cout<<"global m="<<::m<<"\n";

::m=50;

cout<<"local m="<<m;

cout<<"global m="<<::m;

getch();

OUTPUT:-

12TH.WAp to find the greater among the two numbers:

#include<conio.h>

#include<iostream.h>

//WAP in c++ to find the greater among three numbers//


void main()

int a,b,c;

clrscr();

cout<<"Enter the values of a,b,c";

cin>>a>>b>>c;

if((a>b)&&(a>c))

cout<<"A is greater"<<a;
}

else if

cout<<"b is greater"<<b;

else

cout<<"c is grater"<<c;

getch();

output:

13th. WAP in c++ to use the size of operator:

#include<conio.h>

#include<iostream.h>

//WAP in C++ to use the size of operator//

void main()
{

clrscr();

cout<<"\n char="<<sizeof(char);

cout<<"\n int="<<sizeof(int);

cout<<"\n float="<<sizeof(float);

cout<<"\n double="<<sizeof(double);

cout<<"\n longint="<<sizeof(long int);

getch();

}
ouput:

14.wap for check no. Is even or odd use if else:-

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int n;

cout<<"enter an integer:";

cin>>n;

if(n%2==0)

cout<<n<<"is even.";

else

cout<<n<<"is odd.";

getch();
}

OUTPUT:-

15.WAP FOR switch case:

#include<iostream.h>

#include<math.h>

#include<conio.h>

void main()

clrscr();

int choice;

float side1,side2,r,a,b,c,s,area;

float pi=3.14;

cout<<"\1: area of triangle";

cout<<"\n 2: area of circle";

cout<<"\n 3: area of rectangle";

cout<<"Enter your choice";

cin>>choice;
switch(choice)

case 1:

cout<<"enter side of triangle";

cin>>a>>b>>c ;

s=((a+b+c)/2);

area=(sqrt(s*(s-a)*(s-b)*(s-c)));

cout<< "area is" <<area;


break;

case 2:

cout<<"enter side of circle";

cin>>r;

area=pi*r*r;

cout<< "area is" <<area;

break;

case 3:

cout<<"enter side of rectangle";


cin>>side1>>side2;

area=side1*side2;

cout<< "area is" <<area;

break;

default:

cout<<"you enter wrong choice" ;

break;

getch();

Output:
16.WAP FOR CALCULATE AVG MARKS OF STUDENTS:-

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int marks[5],i;

float sum=0,avg;
cout<<"enter marks obtained in 5 subjects:";

for(i=0;i<5;i++)

cin>>marks[i];

sum=sum+marks[i];

avg=sum/5;

cout<<"your grade is ";

if(avg>80)

cout<<"A";

else if(avg>60 && avg<=80)

cout<<"B";

else if(avg>40 && avg<=60)

{
cout<<"C";

else

cout<<"D";

getch();

OUTPUT:-

17.WAP to print friend function

#include<conio.h>

#include<iostream.h>

class abc

int a,b;

public:

void setv()

a=20;

b=45;

friend int sum(abc x)


};

int sum(abc x)

return(x.a+x.b);

};

void main()

abc s;

clrscr();
s.setv ();

cout<<sum(s);

getch();

Output:-

18.wap to pointer :-

#include<conio.h>

#include<iostream.h>

void main()

int alpha=1;

cout<<"\n the value"<<alpha<<"is stored at address"<<& alpha;

cout<<"\n the value"<<*(& alpha)<<"is stored at address"<<& alpha;

getch();

};

OUTPUT:-
19.WAP pointer and structure:-

#include<iostream.h>

#include<iomanip.h>

#include<conio.h>

struct student

int roll;

char name [20];

int age;

};

void main()

student s;

void print_data(student st);

clrscr();

cout<<"enter the student record"<<endl;

cout<<"Roll no:";

cin>>s.roll;

cout<<"Name:";

cin>>s.name;

cout<<"Age:";

cin>>s.age;

print_data(s);

getch();
}

void print_data(student st)

cout<<"record details\n";

cout<<"Roll no:"<<st.roll<<endl;

cout<<"Name:"<<st.name<<endl;

cout<<"Age:"<<st.age<<endl;

}
OUTPUT:-

20. wap for function overloading:-

#include<conio.h>

#include<iostream.h>

#include<iomanip.h>

int square(int);

int square(int,int);

void main()

clrscr();

cout<<square(10)<<endl;

cout<<square(10,20)<<endl;
getch();

//function definitions

int square(int s)

return(s*s);

int square(int x,int y)

{
return(x*y);

OUTPUT:-

21.WAP FOR INLINE FUNCTION IN C++:-

#include<conio.h>

#include<iostream.h>

inline float area(float r)

return(3.14*r*r);

void main()

float radius,a;

clrscr();

cout<<"enter the radius of a circle:";

cin>>radius;
a=area(radius);

cout<<"the area of circle="<<a;

getch();

22.WAP FOR MULTIPLE CONSTRUCTOR IN A CLASS:-

#include<conio.h>

#include<iostream.h>

class circle

int radius;

int area;

public:

circle() //default constructor

radius=0;

circle(int r) //parametrized constructor

radius=r;

circle(circle &c) //copy constructor

radius=c.radius;

void cal(void) //area of circle


{

area=3.142*radius*radius;

void display(void)

cout<<"\n the radius of circle is"<<radius;

cout<<"\n the area of circle is"<<area;

};
void main()

circle c1(10);

circle c2(c1);

circle c3;

clrscr();

c1.cal();

c2.cal();

c3.cal();

c1.display();

c2.display();

c3.display();

getch();

}
23. WAP FOR POINTER IN C++:-

#include<iostream.h>

#include<conio.h>

void main()

int a=5,*b,**c;

b=&a;

c=&b;

cout<<"address of a"<<&a;

cout<<"address of b"<<b;

cout<<"address of c"<<*c;

cout<<"address of b"<<&b;

cout<<"address of b"<<c;

cout<<"address of c"<<&c;

getch();

OUTPUT:-

24. WAP FOR THIS POINTER:-


#include<conio.h>

#include<iostream.h>

#include<iomanip.h>

void main()

int size;

int*ptr;

clrscr();

cout<<"enter the size of array";


cin>>size;

ptr=new int[size];

cout<<"enter the value of array element";

for(int i=0; i<size; i++)

cin>>ptr[i];

cout<<"array elements are";

for(i=0; i<size; i++)

cout<<setw(5)<<ptr[i];

delete ptr;

getch();

25.WAP FOR CALCULATE MARKS OF STUDENTS:-

#include<iostream.h>

#include<iomanip.h>
#include<conio.h>

//base class

class student

int roll;

char name[25];

public:

void getdata()

{
cout<<"enter the roll number"<<endl;

cin>>roll;

cout<<"enter name of student"<<endl;

cin>>name;

void display()

cout<<"Roll No.:"<<roll<<endl;

cout<<"name:"<<name<<endl;

};

//derived class

class test:public student

protected:

int sub1,sub2;

public:

void readdata();
void putdata();

};

void test::readdata()

getdata();

cout<<"enter the marks of subject-1"<<endl;

cin>>sub1;

cout<<"enter the marks of subject-2"<<endl;

cin>>sub2;
}

void test::putdata()

display();

cout<<"marks of subject-1:"<<sub1<<endl;

cout<<"marks of subject-2:"<<sub2<<endl;

class total:public test

int total_marks;

public:

void compute()

total_marks=sub1+sub2;

cout<<"sum of marks:"<<total_marks<<endl;

};

void main()
{

total x;

clrscr();

x.readdata();

x.putdata();

x.compute();

getch();

}ss

26.WAP FOR POINTER TO DERIVED CLASS:-

#include<conio.h>

#include<iomanip.h>

#include<iostream.h>

class base

int a;

public:

base()

{
a=10;

};

void display()

cout<<"a="<<a;

};

class derived:public base

{
int b;

public:

derived()

b=20;

};

void display()

cout<<"b="<<b;

};

void main()

base s; //s is obj. created of base class

clrscr();

base *ptr;

ptr=&s;

ptr->display();
derived d;

ptr=&d;

((derived*)ptr)->display();

getch();

OUTPUT:-SSSSSSS

Das könnte Ihnen auch gefallen