Experiment #1: Aim: Wap - Apparatus: A PC With C++ Software Procedure

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 48

Chandigarh Engineering College , Landran

EXPERIMENT #1
AIM: WAP TO PRINT ASCII CODE OF THE GIVEN CHARACTER. APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> void main() { int num; char ch; cout<<"\n\nEnter the alphabet whose ASCII code is to be obtained :"; cin>>ch; num=ch; cout<<"\n\n\nThe ASCII code of " <<ch<<" is :"<<num; }

OUTPUT:

1|Page

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #2
AIM: WRITE A PROGRAM TO FIND THE SQUARE ROOT OF A NUMBER APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> #include<math.h> void main() { int a,b; cout<<"Enter the number whose square root is required : "; cin>>a; b=sqrt(a); cout<<"square root of " <<a<<" is : "<<b; }

OUTPUT:

2|Page

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #3
AIM: WRITE A PROGRAM TO FIND THE GREATER OF TWO NUMBER APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> void main() { int a,b; cout<<"Enter the first variable : "; cin>>a; cout<<"\nEnter the second variable : "; cin>>b; if(a>b) cout<<a<<" is greater than "<<b; else cout<<b<<" is greater than "<<a; }

3|Page

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

OUTPUT:

4|Page

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #4
AIM: WRITE A PROGRAM TO CHECK WETHER A CHARACTER IS A VOWEL OR NOT APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> void main() { char ch; cout<<"Enter the character : "; cin>>ch; if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') {cout<<ch<<" is a vowel ";} else {cout<<ch<<" is not a vowel ";} }

OUTPUT:

5|Page

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #5
AIM: WRITE A PROGRAM TO FIND GREATER NUMBER OUT OF THREE APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> void main() { int a,b,c; cout<<"enter three numbers"; cin>>a>>b>>c; if(a>b) { if(a>c) cout<<a<<" is greater"; else cout<<c<<" is greater"; } else { if(b>c)
6|Page

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

cout<<b<<" is greater"; else cout<<c<<" is greater"; } }

OUTPUT:

7|Page

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #6
AIM: WAP TO PRINT A NUMBER CORESSPONDING TO THE NUMBER APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> void main() { int n; cout<<"enter a number:"; cin>>n; if(n==1) cout<<"SUNDAY"<<endl; else if(n==2) cout<<"MONDAY"<<endl; else if(n==3) cout<<"TUESDAY"<<endl; else if(n==4) cout<<" else if(n==5) cout<<"THRUSDAY"<<endl; else if(n==6)
8|Page

WEDNESSDAY"<<endl;

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

cout<<"FRIDAY"<<endl; else if(n==7) cout<<"SATURDAY"<<endl; else cout<<"entered number is wrong"<<endl; }

OUTPUT:

9|Page

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #7
AIM: WAP BY USING SWITCH STATEMENT APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> void main() { clrscr(); int a; cout<<"enter a no."; cin>>a; switch(a) { case 1: cout<<"monday"; break; case 2: cout<<"tuesday"; break; case 3: cout<<"wenday";
10 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

break; case 4: cout<<"thursday"; break; case 5: cout<<"friday"; break; default: cout<<"wrong choice"; } getch(); }

OUTPUT:

11 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #8
AIM: WAP TO PRINT * ** *** **** ***** APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { cout<<"*"; }
12 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

cout<<"\n"; } getch();

OUTPUT:

13 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #9
AIM: WAP TO PRINT 1 12 123 1234 12345 APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> void main() { int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { cout<<j<<" "; } cout<<endl; }
14 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

OUTPUT:

15 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #10
AIM: WAP TO PRINT 1 22 333 4444 APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> void main() { int i,j; for(i=1;i<=4;i++) { for(j=1;j<=i;j++) { cout<<i<<" "; } cout<<endl;}

16 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

OUTPUT:

17 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #11
AIM: WAP BY USING WHILE LOOP APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,c; char ch='y'; while(ch=='y') { cout<<"enter any two no."; cin>>a>>b; c=a+b; cout<<"sum="<<c<<endl; cout<<"press 'y' if you want to continue "; cin>>ch; } getch(); }
18 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

OUTPUT:

19 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #12
AIM: WAP TO FIND WHETHER A NUMBER IS ODD OR EVEN APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> void main() { int a; cout<<"enter a number "; cin>>a; if(a%2==0) cout<<"the given number is even"<<endl; else cout<<"the given numberis odd"<<endl; }

OUTPUT:

20 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #13
AIM: WRITE A PROGRAM BY USING ARRAY APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[10][10], b[10][10],c[10][10], i,j,m,n; cout<<"please enter no. of rows"; cin>>i; cout<<"please enter no. of columns"; cin>>j; for(m=0;m<i;m++) { for(n=0;n<j;n++) { cin>>a[m][n]; } } for(m=0;m<i;m++)
21 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

{ for(n=0;n<j;n++) { cin>>b[m][n]; } } for(m=0;m<i;m++) { for(n=0;n<j;n++) c[m][n]=a[m][n]+b[m][n]; } for(m=0;m<i;m++) { cout<<endl;

for(n=0;n<j;n++) {

cout<<c[m][n]; } } getch(); }

22 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

OUTPUT:

23 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #14
AIM: WAP OF SWAP BY CALL BY VALUE APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> void main() { void swap(int ,int); int x=10; int y=15; swap(x,y); cout<<"x="<<x<<endl; cout<<"y="<<y<<endl; } void swap(int a, int b) { int t; t=a; a=b; b=t; }

24 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

OUTPUT:

25 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #15
AIM: WAP OF SWAP BY CALL BY REFERENCE APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> void main() { void swap(int &,int &); int x=10; int y=15; swap(x,y); cout<<"x="<<x<<endl; cout<<"y="<<y<<endl; } void swap(int &a,int &b) { int t; t=a; a=b; b=t; }

26 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

OUTPUT:

27 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #16
AIM: WAP USING INLINE FUNCTION APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> void main() { float a,b; cout<<"enter two numbers : "; cin>>a>>b; float mul(float , float ); float div(float ,float ); cout<<a<<"*"<<b<<"="<<mul(a,b)<<endl; cout<<a<<"/"<<b<<"="<<div(a,b)<<endl; } inline float mul(float x, float y) { return(x*y); } inline float div(float p,float q) { return(p/q);
28 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

OUTPUT:

29 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #17
AIM: WAP BY USING FRIEND FUNCTION APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> class data { private: int a,b,c; public: void getsdata() { cout<<"enter two variables"; cin>>a>>b;

} friend void display(data obj); }; void display(data obj) { cout<<"your result for addition "<<(obj.a+obj.b);
30 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

} void main() { clrscr(); data d1; d1.getsdata(); display(d1); getch(); }

OUTPUT:

31 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #18
AIM: WAP BY USING RECURSION APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE: #include<iostream.h>
#include<conio.h> void main() { clrscr(); long fact (int); int n; cout<<"enter a number"<<endl; cin>>n; if(n<=0) cout<<"you cannot find factorial"; else cout<<"factorial is"<<fact(n); getch(); } long fact(int num) { if(num==1) return(1);
32 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

return(num*fact(num-1)); }

OUTPUT:

33 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #19
AIM: WAP USING STRUCTURES APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> struct data { int day; int month; int year; }; struct bio_data { int roll_number; data dob; }; void main() { bio_data student; cout<<"enter roll number :"<<endl; cin>>student.roll_number; cout<<"enter date of birth :"<<endl;
34 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

cout<<"enter day :"; cin>>student.dob.day; cout<<"enter monter in numbers cin>>student.dob.month; cout<<"enter year :" ; cin>>student.dob.year; cout<<"roll number:"<<student.roll_number<<endl; cout<<"your date of birth "<<endl; cout<<student.dob.day<<"/"<<student.dob.month<<"/"<<student.dob.y ear<<endl; } :";

OUTPUT:

35 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #20
AIM: WAP BY USING CLASS APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<stdio.h>

#include<iostream.h> #include<conio.h> class data { private: char a[20]; float basic,gross,ta,da; public: void getsdata() { cout<<"enter the name "; gets(a); cout<<"enter the basic salary "; cin>>basic; cout<<"enter ta "; cin>>ta; cout<<"enter da ";
36 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

cin>>da; } void display() { gross=basic+ta+da; cout<<"your name is "<<a<<endl; cout<<"your gross income is "<<gross; } };

void main() { clrscr(); data d; d.getsdata(); d.display(); }

OUTPUT:

37 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #21
AIM: WAP TO PERFORM ADDITION WITH OUTSIDE THE CLASS APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h>

class data { int a,b,c; public: void getdata(); void display(); }; void data :: getdata() { cout<<"enter two no. "; cin>>a>>b; } void data :: display() { c=a+b; cout<<"your result for addition is "<<c; } 38 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran


void main() { clrscr(); data d; d.getdata(); d.display(); getch(); }

OUTPUT:

39 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #22
AIM: WAP TO MULTIPLY AND DIVIDE 2 NUMBERS USING CLASSES APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> void main() { float a,b; cout<<"enter two numbers:"; cin>>a>>b; float mul(float,float); double div(double,double); cout<<a<<"*"<<b<<"="<<mul(a,b)<<endl; cout<<a<<"/"<<b<<"="<<div(a,b)<<endl; } float mul(float x, float y) { return(x*y); } double div(double p,double q) {
40 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

return(p/q); }

OUTPUT:

41 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #23
AIM: WAP FOR INHERITANCE APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<stdio.h> #include<iostream.h> #include<conio.h> class data { private: int a; public: void getsdata() { cout<<"enter roll no. "; cin>>a;

} void display() { cout<<"your roll no. is "<<a<<endl; }


42 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

}; class student:public data { private: char name[30]; public: void getsdata1() { cout<<"enter your name "; gets(name); } void display1() { cout<<"your name is "<<name; } };

void main() { clrscr(); student s; s.getsdata(); s.getsdata1();

43 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

s.display(); s.display1(); getch(); }

OUTPUT:

44 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #24
AIM: WAP TO PERFORM FUNCTION OVERLOADING APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE: #include<iostream.h>
#include<conio.h> class student { private: int c; float f; public: void sum(int a,int b) { c=a+b; } void sum(float d,float e) // function overloading, functions have //same name i.e sum { f=d+e; } void showdata() {
45 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

cout<<"sum of integer no's is"<<c<<endl; cout<<"sum of floating no's is"<<f; } }; void main() { clrscr(); int a,b; float d,e; student ab; cout<<"enter two integer numbers"; cin>>a>>b; cout<<"enter two floating point numbers"; ab.sum(a,b); cin>>d>>e; ab.sum(d,e); ab.showdata(); }

OUTPUT:

46 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

EXPERIMENT #25
AIM: WAP TO OVERLOAD INCREMENT OPERATOR APPARATUS: A PC WITH C++ SOFTWARE PROCEDURE:
#include<iostream.h> #include<conio.h> class test { int a; public: test() { a=5; } void show() { cout<<" value of a="<<a<<endl; } void operator++() { a++; }
47 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

Chandigarh Engineering College , Landran

}; void main() { clrscr(); test x; x.show(); ++x; x.show(); getch(); }

OUTPUT:

48 | P a g e

Jaskaran Kaur Gill/ece(B)100170413555/3rd sem

You might also like