You are on page 1of 22

# INDEX Enrollment no: Subject code

:

SNO NAME OF PRACTICAL WAP to show use of bitwise operator. 1 WAP to find out prime number between 1 to 2 3 4 5 6 7 8
100. WAP to calculate factorial of given number.

Date

Pageno. Remark

WAP to Swap two number using call by value. WAP to swap two number using call by reference. WAP to perform sum of two integers, float number using function overloading. WAP to display Fibonacci series. WAP to print following output using Switch:

1) * * * *

2)

1 1 2 1

3)

1 1 2 1 1 2 3 2 1 1 2 1 1

* * 1 2 3 2 1

9

WAP to create class of student that have following data: Name, roll no, marks, getdata and result. WAP to implement single inheritance. WAP to implement constructor. WAP to implement virtual function.

10 11 12

//1. WAP to show bitwise operator. 1

#include<conio.h> #include<iostream.h> void main() { clrscr(); int num,num1; cout<<"\nenter any two value"; cin>>num>>num1; cout<<"\n"<<num<<"&"<<num1<<":"<<(num&num1); cout<<"\n"<<num<<"|"<<num1<<":"<<(num|num1); cout<<"\n"<<num<<"<<"<<num1<<":"<<(num<<num1); cout<<"\n"<<num<<">>"<<num1<<":"<<(num>>num1); cout<<"\n"<<"!"<<num<<":"<<!num; getch(); }

OUTPUT: enter any two value4 5 4&5:4 4|5:5 4<<5:128 4>>5:0 !4:0

//2.WAP to display prime number between 100. #include<conio.h> 2

//3. 83.37.19.5.73. #include<conio.89.59.17.7.h> void main() { clrscr().#include<iostream.h> 3 . cout<<"PRIME NUMBERS ARE:".".71.11.79.29.i++){ int j=2.3. } OUTPUT: PRIME NUMBERS ARE:2.61.i<=100. } if(i==j) cout<<i<<".31.97.43.23.WAP to calculate factorial of given number.h> #include<iostream.53.47. for(int i=1.67. else j++.13. } getch().41. while(j<i) { if(i%j==0) break.

void main() { clrscr(). cout<<"\nfacorial of "<<num<<":". int fact=1.WAP to swap two value using call by value. cin>>num. #include<conio. int num. while(num>1) fact=fact*(num--). cout<<"\nenter value:".h> void main() 4 . } OUTPUT: enter value:5 facorial of 5:120 //4. getch().h> #include<iostream. cout<<fact.

num2=num3. num3=num1.h> #include<iostream.WAP to swap two value using call by value. } OUTPUT: enter any two value5 6 Before swapping values: After swapping values: num1=5 num2=6 num1=5 num2=6 //5. num1=num2. swap(num1. cout<<"enter any two value". getch(). cin>>num1>>num2. cout<<"\nBefore swapping values:"<<"\nnum1="<<num1<<"\nnum2="<<num2.int num2) { int num3. int num1.int). #include<conio.{ clrscr().h> void main() 5 .num2. } void swap(int num1. cout<<"\nAfter swapping values:"<<"\nnum1="<<num1<<"\nnum2="<<num2. void swap(int.num2).

} OUTPUT: enter any two value5 6 Before swapping values: After swapping values: num1=5 num2=6 num1=6 num2=5 //6. cout<<"enter any two value".h> 6 . *num1=*num2.int *num2) { int num3. #include<iostream.{ clrscr(). cin>>num1>>num2.h> #include<conio. getch().num2.WAP to perform sum of two integer. num3=*num1. void swap(int*. cout<<"\nAfter swapping values:"<<"\nnum1="<<num1<<"\nnum2="<<num2.float number using function overloading. *num2=num3.&num2).int*). swap(&num1. } void swap(int *num1. cout<<"\nBefore swapping values:"<<"\nnum1="<<num1<<"\nnum2="<<num2. int num1.

getch(). } int add(int x. cin>>x1>>y1. int x. cin>>x>>y.y). } OUTPUT: enter two integer vlaue 5 6 7 .y1.int ).int add(int .float y1) { return(x1+y1). float add(float . float x1. cout<<"\nenter two float vlaue". cout<<"\nenter two integer vlaue". cout<<"\nsum of int"<<add(x. void main() { clrscr(). } float add(float x1.y1). cout<<"\nsum of float"<<add(x1.float ).y.int y) { return(x+y).

sum of int11 enter two float vlaue 5.WAP to display fabonacci series.7 //7.h> #include<iostream.h> void main() { 8 . #include<conio.7 7 sum of float12.

int z=x+y. cin>>num.5.clrscr(). cout<<"fabonacci series of "<<num<<":"<<x. cout<<"\nenter value:". for(int i=1.i<num. } getch().2."<<y.13 /*8.1. WAP to print following output using switch: 1) * ** *** 2) 1 121 12321 3) 1 121 12321 121 1 9 . int num.i++) { cout<<". x=y.8. int x=1.3. } OUTPUT: enter value:7 fabonacci series of 7:1. y=z. int y=1.

j>=1....j>=1. deep: cout<<".. cout<<"\n2... int ch. cin>>num..num. 10 .i++) { for(int j=num-i. cout<<endl.. for(int i=1..h> #include<iostream... cout<<"\n1. cout<<"\nTriangle of * "<<num<<":\n".i<=num...h> void main() { clrscr().j--) cout<<" *". Triangle of num in reverse order". cout<<"\nenter your choice:"... cin>>ch. for(j=i..*/ #include<conio.. switch(ch) { case 1: cout<<"\nenter value:"...".j--) cout<<" ".". cout<<"\n3.. Triangle of *"..MENU.. Triangle of num.

j>=1.j<=i. cout<<"Triangle of num "<<num<<":\n".} break. cin>>num. 11 . for(i=1.i++) { for(int j=num-i. case 3: cout<<"\nenter value:". for(j=1.j++) cout<<j.j--) cout<<" ". for(i=1.i<=num. cin>>num.j>=1.i<=num. } break.j--) cout<<" ".j<=i.j--) cout<<j. for(j=1.j++) cout<<j. case 2: cout<<"\nenter value:". cout<<"Triangle of num "<<num<<":\n".j>=1. cout<<endl. for(j=i-1.i++) { for(int j=num-i.

..i<=num-1. cout<<endl.... default: cout<<"ur choice is invailid select vailid choice". Triangle of * 2.j--) cout<<j.i++) { for(int j=1.. cout<<endl. 3.j++) cout<<" "... for(j=(num-1)-i.MENU..j<=num-i.j>=1... 1. goto deep... Triangle of num.for(j=i-1.j<=i. for(j=1. } OUTPUT: ...... } getch().j--) cout<<j.. } break. Triangle of num in reverse order enter your choice:3 12 ..j++) cout<<j..j>=1.. } for(i=1.

#include<conio.marks[3]. 13 .h> #include<iostream. char name[15].h> class Student { int enroll. public: void getinfor(). WAP to create class of student that have following data: Name. getdata and result. roll no.enter value:7 Triangle of num 7: 1 121 12321 1234321 123454321 12345654321 1234567654321 12345654321 123454321 1234321 12321 121 1 //9. marks.

cout<<"\nresult:"<<avg<<"%".i++) cin>>marks[i].i++) sum=sum+marks[i].0. 14 . int sum=0. } void main() { clrscr(). }. float avg=sum/3. } void Student:: getinfor() { cout<<" \nstudent name:"<<name. cout<<"\ntotal:". for(int i=0. cout<<"\nrollnumber:"<<enroll.setinfor(). void Student:: setinfor() { cout<<"\nenter student name". cin>>enroll. cout<<sum. s1. cin>>name.i<3. for(int i=0. Student s1.void setinfor().i<3. cout<<"\nenter rollnumber".

getinfor(). getch(). cin>>num.333332% //10. 15 .s1.h> #include<conio. WAP to implement single inheritance #include<iostream. } }.h> class Base { public: int num. void getinput() { cout<<"enter value:". } OUTPUT: enter student name anshu enter rollnumber34 35 67 88 student name:anshu rollnumber:34 total:190 result:63.

getch(). cout<<"factorial of"<<num<<":"<<fact. d.i<=num. d.fact().i++) fact=fact*i.getinput().class Derived:public Base { public: void fact() { int fact=1. } OUTPUT: enter value:5 factorial of5:120 16 . } }. void main() { clrscr(). Derived d. for(int i=1.

char name[15]. }.h> #include<iostream. cin>>name. Student:: Student() //constructor definition { cout<<"\nenter student name".WAP to implement constructor #include<conio. 17 .h> class Student { int enroll.marks[3]. //contructor void getinfor(). public: Student().//11.

Student s1. cout<<sum.i++) cin>>marks[i].i++) sum=sum+marks[i].i<3.i<3. cout<<"\ntotal:".cout<<"\nenter rollnumber". } OUTPUT: enter student namedd enter rollnumber7 18 . int sum=0. } void Student:: getinfor() { cout<<" \nstudent name:"<<name. s1.0.getinfor(). for(int i=0. } void main() { clrscr(). cin>>enroll. for(int i=0. cout<<"\nresult:"<<avg<<"%". float avg=sum/3. getch(). cout<<"\nrollnumber:"<<enroll.

19 .h> class Base { protected: int num. WAP to implement virtual function.h> #include<iostream. } virtual void getdata() { cout<<"\n Area of Square:"<<area().333336% //12. #include<conio.66 77 77 student name:dd rollnumber:7 total:220 result:73. public: void setdata() { cout<<"\nenter value num". cin>>num.

cin>>num1>>num2. } int area().num2. } void getdata() { cout<<"\n Area of Rectangle:"<<area(). } void main() 20 . public: void setdata() { cout<<"\nenter value num1 and num2". }. int Derived::area() { return (num1*num2). } class Derived :public Base { protected: int num1. int Base::area() { return (num*num). }.} int area().

Base b.//pointer point to derived class. ptr->getdata(). ptr1->setdata(). ptr=&b. } OUTPUT: enter value num 5 Area of Square: 25 enter value num1 and num2 6 8 Area of Rectangle: 48 21 . ptr1->getdata().//pointer point to base class. Derived *ptr1.{ clrscr(). Base *ptr. ptr->setdata(). getch(). Derived d. ptr1=&d.

22 .