OOPS PRACTICAL FILE Department Of Computer Science Engineering BABA BANDA SINGH BAHADUR ENGINEERING COLLEGE, Fatehgarh Sahib ,Punjab - 140407 Submitted To :Prof. Rupendra Kaur Submitted By :Name: Parshant kumar Roll No :2100385 Class : 3C22 Subject : OOP INDEX S.No. Program Page 1. WAP to display a massage on screen. 1 2. WAP to print arithmetic operation. 2 3. WAP to show different types of errors in program. 3-4 4. WAP to calculate tax of an employee using functions. 5-6 5. WAP to overload a function volume. 7-8 6. 7. WAP to swap two number using call by value. WAP to swap two number using call by reference. 9-10 11-12 8. WAP to find sum & average of marks of student of a class. 13-14 9. WAP to find sum & average of marks of student of a class. 15-16 10. WAP to print fibonacci series using recursion. 17 11. WAP to show the working of pointer. 18 Remark TASK 1 AIM : WAP to display a massage on screen. PROGRAM : #include <iostream> using namespace std; int main() { cout << "Hello World!"; return 0; } OUTPUT : 1|Page TASK 2 AIM : WAP to print arithmetic operation. PROGRAM : #include <iostream> using namespace std; int main() { int a,b,sum,sub,multi,mod; float div; cout << "Enter a: "; cin >>a; cout << "Enter b: "; cin >>b; sum = a+b; cout << a << " + " << b << " = " << sum <<"\n"; sub = a-b; cout << a << " - " << b << " = " << sub <<"\n"; multi = a*b; cout << a << " * " << b << " = " << multi <<"\n"; div = (float)a/(float)b; cout << a << " / " << b << " = " << div <<"\n"; mod = a%b; cout << a << " % " << b << " = " << mod <<"\n"; return o; } 2|Page OUTPUT : 3|Page TASK 3 AIM : WAP to show different types of errors in program. PROGRAM : #include<iostream> using namespace std; int main() { int a,b; cout<<"Enter a : "; cin>>a; cout<<"Enter b : " cin>>b; a+b; sum = cout<<"Sum is : "<<sum; return 0; } OUTPUT : 4|Page TASK 4 AIM : WAP to calculate tax of an employee using functions. PROGRAM : #include <iostream> using namespace std; void cal(void); int main() { int i,n; cout<<"\nENTER THE NUMBER OF THE EMPLOYEES: "; cin>>n; for(i=1;i<=n;i++) cal(); return 0; } void cal() { int basic; float tax; cout<<"\nENTER THE AMOUNT OF BASIC: "; cin>>basic; if(basic<9000) 5|Page tax=basic*20/100; else tax=basic*25/100; cout<<"\nTHE AMOUNT OF TAX IS %0.2f = "<<tax<<"\n"; } OUTPUT : 6|Page TASK 5 AIM : WAP to overload a function volume. ` PROGRAM : #include<iostream> using namespace std; void volume(float); void volume(int,int,int); void volume(float, int); int main() { int a,b,c; float d; cout<<"Enter a,b,c,d :"; cin>>a>>b>>c>>d; volume(d); cout<<"\n"; volume(a,b,c); cout<<"\n"; volume(d,a); cout<<"\n"; return0; } 7|Page void volume(float x) { cout<<"volume of cube : "; float cu=x*x*x; cout<<cu<<"\n"; } void volume(int x,int y,int z) { cout<<"volume of cuboid is : "; float cub=x*y*z; cout<<cub<<"\n"; } void volume(float m,int n) { cout<<"volume of cuboid is : "; float cylin=3.14*m*n; cout<<cylin<<"\n"; } OUTPUT : 8|Page TASK 6 AIM :WAP to swap two number using call by value. PROGRAM : #include<iostream> using namespace std; void swap(int,int); int main() { int a,b; cout<<"Enter Value Of A :: "; cin>>a; cout<<"\nEnter Value of B :: "; cin>>b; cout<<"\nBefore Swapping, Value of :: \n\tA = "<<a<<"\tB = "<<b<<"\n"; swap(a,b); cout<<"\nOutside Function After Swapping, Value of :: \n\tA = "<<a<<"\tB=”<<b<<”\ n"; } void swap(int a,int b) { int c; c=a; a=b; b=c; cout<<"\nInside Function After Swapping, Value of :: \n\tA = "<<a<<"\tB = "<<b<<"\n"; } 9|Page OUTPUT : 10 | P a g e TASK 7 WAP to swap two number using call by reference. #include<iostream> using namespace std; void main (int&num1,int&num2); int main() { int a,b; cout <<"\n Using Call By Referen\n"; cout<<"Enter value of A = "; cin>>a; cout<<"Enter value of B = "; cin >>b; cout<<"\nBefore Swapping, Value of :: \n\tA = "<<a<<"\tB = "<<b<<"\n"; swap(a,b); cout<<"\nOutside Function After Swapping, Value of :: \n\tA = "<<a<<"\tB = "<<b<<"\n"; return 0; } void swap (int &num1, int &num2) { 11 | P a g e int temp; temp=num1; num1=num2; num2=temp; cout<<"\nInside Function After Swapping, Value of :: \n\tA = "<<num1<<"\tB = "<<num2<<"\n"; } OUTPUT : 12 | P a g e TASK 8 AIM: WAP to find sum & average of marks of student of a CLASS #include<iostream> using namespace std; class student { int mark1,mark2; public: void getmark() { cout<<"Enter Mark1 : "; cin>>mark1; cout<<"Enter Mark2 : "; cin>>mark2; } void showmark() { int sum= mark1+mark2; float avg= (mark1+mark2)/2; cout<<"Sum is : "<<sum <<"\n"; cout<<"Average is : "<<avg<<"\n"; } }; int main() { student s; 13 | P a g e s.getmark(); s.showmark(); return 0; } OUTPUT : 14 | P a g e TASK 9 WAP to print fibonacci series using recursion. #include <iostream> using namespace std; int fib(int x) { if((x==1)||(x==0)) { return(x); }else { return(fib(x-1)+fib(x-2)); } } int main() { int x , i=0; cout << "Enter the number of terms of series : "; cin >> x; while(i < x) { cout << "Fibonnaci Series : "; cout << " " << fib(i); i++; } return 0; } 15 | P a g e OUTPUT : 16 | P a g e TASK 10 AIM: WAP to make use of string functions. #include <iostream> #using namespace std; int main () { char key[] = "pine apple"; char buffer[50]; do { cout<<"What is my favourite fruit?"; cin>>buffer; } while (strcmp (key,buffer) != 0); cout<<"Answer is correct!!"<<endl; return 0; } OUTPUT : 17 | P a g e TASK 11 AIM : WAP to show the working of pointer. PROGRAM : #include <iostream> using namespace std; int main () { int var1=15; char var2[15]="hello"; cout << "Address of var1 variable: "; cout << &var1 << endl; cout << "Address of var2 variable: "; cout << &var2 << endl; return 0; } OUTPUT : 18 | P a g e