Sie sind auf Seite 1von 58

S.U.S.C.E.

T,Tangori

WAP to check if a no. is Armstrong or not


#include<iostream.h> #include<math.h> #include<conio.h> void main () { clrscr (); int a,b,c,d,e; cout<<"Enter no."; cin>>a; b=a%10; c=a/10; d=c%10; e=c/10; if (a==pow(b,3)+pow(d,3)+pow(e,3)) { cout<<"Its an ARMSTRONG NO."; } else { cout<<"Its not an ARMSTRONG NO."; } getch (); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to implement reversal of a number


#include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,no=0; cout<<"Enter the no"; cin>>a; while(a>0) { b=a%10; a=a/10; no=no*10+b; } cout<<"the reverse is" << no; getch(); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to compute average of 1st n multiples of z


Nikhil Jaiswal

S.U.S.C.E.T,Tangori

#include<iostream.h> #include<conio.h> void main () { clrscr (); int z,x,b,i,c=0; cout<<"\nEnter no."; cin>>z; cout<<"Enter limit of multiple"; cin>>x; cout<<"Multiples of "<<z<< " are : "; for (i=0;i<=x;i++) { b=i*z; cout<<b<<" "; c=c+b; } cout<<"\nAverage is "<<c/(x+1); getch (); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to compute ADDITION , SUBTRACTION , MULTIPLICATION of two matrices


#include<iostream.h> #include<conio.h> Nikhil Jaiswal

S.U.S.C.E.T,Tangori void main () { clrscr (); int a[100][100],b[100][100],c[100][100],m,k,i,j,ch,n,x,y; cout<<"\nEnter ROWS of matrix A "; cin>>m; cout<<"\nEnter COLUMNS of matrix A "; cin>>n; cout<<"\nEnter elements of matrix A "; for (i=0;i<m;i++) { for (j=0;j<n;j++) { cin>>a[i][j]; }} cout<<"\nEnter ROWS of matrix B "; cin>>x; cout<<"\nEnter COLUMNS of matrix B "; cin>>y; cout<<"\nEnter elements of matrix B "; for (i=0;i<x;i++) { for (j=0;j<y;j++) { cin>>b[i][j]; }} cout<<"Elements of matrix A are : \n\t\t\t\t"; Nikhil Jaiswal

S.U.S.C.E.T,Tangori for (i=0;i<m;i++) { for (j=0;j<n;j++) { cout<<a[i][j]<<" "; } cout<<"\n\t\t\t\t"; } cout<<"\nElements of matrix B are : \n\t\t\t\t"; for (i=0;i<x;i++) { for (j=0;j<y;j++) { cout<<b[i][j]<<" "; } cout<<"\n\t\t\t\t"; } cout<<"\n1. ADDITION"; cout<<"\n2. SUBTRACTION"; cout<<"\n3. MULTIPLICATION"; cout<<"\nEnter your choice "; cin>>ch; switch(ch) { case 1 : if (m==x && n==y) { Nikhil Jaiswal

S.U.S.C.E.T,Tangori cout<<"\nADDITION SUCCESSFUL "; for (i=0;i<m;i++) { for (j=0;j<n;j++) { c[i][j]=a[i][j]+b[i][j]; }} cout<<"\n\nADDITON is : \n\t\t"; for (i=0;i<m;i++) { for (j=0;j<m;j++) { cout<<c[i][j]<<" "; } cout<<"\n\t\t"; }} else { cout<<"\nADDITION NOT SUCCESSFUL"; } break; case 2: if (m==x && n==y) { cout<<"\nSUBTRACTION SUCCESSFUL "; for (i=0;i<m;i++) { Nikhil Jaiswal

S.U.S.C.E.T,Tangori for (j=0;j<m;j++) { c[i][j]=a[i][j]-b[i][j]; }} cout<<"\nSUBTRATION is : \n\t\t"; for (i=0;i<m;i++) { for (j=0;j<m;j++) { cout<<c[i][j]<<" "; } cout<<"\n\t\t"; }} else { cout<<"\nSUBTRACTION NOT SUCCESSFUL "; } break; case 3 : if (n==x) { cout<<"MULTIPLICATION SUCCESSFUL "; for (i=0;i<m;i++) { for (j=0;j<n;j++) { c[i][j]=0; Nikhil Jaiswal

S.U.S.C.E.T,Tangori for (k=0;k<x;k++) { c[i][j]=c[i][j]+(a[i][k]*b[k][j]); }}} cout<<"\n\nMULTIPLICATION is : \n\t\t"; for (i=0;i<m;i++) { for (j=0;j<n;j++) { cout<<c[i][j]<<" "; } cout<<"\n\t\t"; }} else { cout<<"\nMULTIPLICATION NOT SUCCESSFUL "; } break; default: { cout<<"\nWRONG OPTION "; } } getch (); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to perform following operation on strings


1.Compute the length 2.Concatinate 2 strings 3.Comparison 4.Reversal
#include<iostream.h> #include<conio.h> #include<stdio.h> #include<string.h> void main () Nikhil Jaiswal

S.U.S.C.E.T,Tangori { clrscr (); int a,len; char str1[100],str2[100]; again: cout<<"\n\n\nEnter your choice"; cout<<"\n1. Calculate length"; cout<<"\n2. Contatinate"; cout<<"\n3. Comparison"; cout<<"\n4. Reversal"; cout<<"\n5. EXIT\n"; cin>>a; switch (a) { case 1: { cout<<"\nEnter string"<<" "; gets(str1); len=strlen(str1); cout<<"\nLength of STRING is "<<len; } goto again; case 2: { cout<<"\nEnter 1st string"<<" "; gets(str1); cout<<"\nEnter 2nd string"<<" "; Nikhil Jaiswal

S.U.S.C.E.T,Tangori gets(str2); cout<<"\nOn Concatination STRING is"<<" "<<strcat(str1,str2); } goto again; case 3: cout<<"\nEnter 1st string"<<" "; gets(str1); cout<<"\nEnter 2nd string"<<" "; gets(str2); if(strcmp(str1,str2)==0) { cout<<"\nStrings are EQUAL"; } else { cout<<"\nStrings are NOT EQUAL"; } goto again; case 4: int count=0,i,j; cout<<"\nEnter string"<<" "; gets(str1); cout<<"\nOn Reversal String is "; for (i=0;str1[i]!='\0';i++) { count++; } Nikhil Jaiswal

S.U.S.C.E.T,Tangori for (j=count;j>=0;j--) { cout<<str1[j]; } goto again; case 5: break; default: { cout<<"\nWrong Option"; } goto again; } }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to check if a string is PALINDROME or not ?


#include<iostream.h> #include<stdio.h> #include<string.h> #include<conio.h> void main() { clrscr(); char *a,*b; int l; cout<<"enter the string:"; gets(a); strcpy(b,a); strrev(a); if(strcmp(a,b)==0) { cout<<"\nIts a palindrome"<<endl; } else { cout<<"\nIts not a palindrome"<<endl; } getch (); } Nikhil Jaiswal

S.U.S.C.E.T,Tangori

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to implement FUNCTION OVERLOADING


#include<iostream.h> #include<conio.h>

int sumtotal (int ,int ); int sumtotal (int ,int ,int ); float sumtotal (float ,float ); double sumtotal (int ,double);

void main () { clrscr (); cout<<"\n"<<sumtotal (3,4,5); cout<<"\n"<<sumtotal (10,11.0); cout<<"\n"<<sumtotal (2.5,3.5); cout<<"\n"<<sumtotal (4,5); getch (); } int sumtotal (int x,int y) { return (x+y); } int sumtotal (int m,int n,int o) { Nikhil Jaiswal

S.U.S.C.E.T,Tangori return (m+n+o); }

float sumtotal (float d,float e) { return (d+e); } double sumtotal (int p,double q) { return (p+q); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to implement FRIEND FUNCTION


#include<iostream.h> #include<conio.h> class distance { int mts,cms; public: distance() { } distance (int a,int b) { mts=a; cms=b; } ~distance() { }; void showtotal () { cout<<"Total Distance is "; cout<<mts<<"m"<<" "<<cms<<"cm"; } friend distance add (distance d1,distance d2); Nikhil Jaiswal

S.U.S.C.E.T,Tangori }; distance add (distance d1,distance d2) { distance d; d.mts=d1.mts+d2.mts + (d1.cms+d2.cms)/100; d.cms=(d1.cms+d2.cms)%100; return d; } void main () { int q,w,e,r; clrscr (); cout<<"Input for 1st object in mts & cms respectively \n"; cin>>q>>w; cout<<"Input for 2nd object in mts & cms respectively \n"; cin>>e>>r; distance x(q,w),y(e,r),z; z=add(x,y); z.showtotal(); getch (); }

WAP to implement PRIVATE MEMBER FUNCTION


Nikhil Jaiswal

S.U.S.C.E.T,Tangori

#include<iostream.h> #include<conio.h> class abc { int x; void getdata () { cout<<"\nEnter value of x "; cin>>x; } public: void read () { getdata (); } void showdata () { cout<<"\nValue of x is "<<x; } }; void main () { clrscr (); abc a1; //a1.getdata (); a1.read (); Nikhil Jaiswal // wrong call; objects cannot access private member functions

S.U.S.C.E.T,Tangori a1.showdata (); getch (); }

WAP to implement STATIC DATA MEMBERS


#include<iostream.h> Nikhil Jaiswal

S.U.S.C.E.T,Tangori #include<conio.h> class abc { static int count; int number; public: void getdata (int a) { number=a; count++; } void showcount () { cout<<"\ncount is "<<count; } }; int abc :: count; void main () { clrscr (); abc a1,a2,a3; a1.showcount (); a2.showcount (); a3.showcount (); a1.getdata (10); a2.getdata (20); a3.getdata (30); Nikhil Jaiswal

S.U.S.C.E.T,Tangori a1.showcount (); a2.showcount (); a3.showcount (); getch (); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to implement CONSTRUCTORS(default, parameterised & copy) and DESTRUCTORS


#include<iostream.h> #include<conio.h> class sample { int x,y; public: sample() { x=1; y=2; } sample(int a,int b) { x=a; y=b; } sample(int a,float b=5) { Nikhil Jaiswal

S.U.S.C.E.T,Tangori x=a; y=b; } sample(sample &obj) { x=obj.x; y=obj.y; } ~sample() { cout<<"destructor"<<endl; } void display() { cout<<x<<y<<endl; } }; void main() { clrscr(); int r,s; sample s1,s2; cout<<"Enter value for 1st object"; cin>>r>>s; s1 = sample(r,s); cout<<"enter value for 2nd object"; cin>>r>>s; Nikhil Jaiswal

S.U.S.C.E.T,Tangori s2= sample(r); sample s3(s1); s1.display(); s2.display(); s3.display(); getch(); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to implement OVERLOADING of UNARY operators using MEMBER FUNCTION


#include<iostream.h> #include<conio.h> class abc { int a,b; public: void getdata( int x,int y) { a=x; b=y; } void display() { cout<<"x="<<a; cout<<"y="<<b<<endl; } void operator-() { a=-a; b=-b; } }; Nikhil Jaiswal

S.U.S.C.E.T,Tangori void main() { clrscr(); abc obj1; obj1.getdata(10,15); -obj1; obj1.display(); getch(); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to implement OVERLOADING of UNARY operators using FRIEND FUNCTION

#include<iostream.h> #include<conio.h> class abc { int a,b; public: void getdata( int x,int y) { a=x; b=y; } void display() { cout<<"\nx = "<<a; cout<<"\ny = "<<b<<endl; Nikhil Jaiswal

S.U.S.C.E.T,Tangori } friend void operator-(abc&a1); }; void operator-(abc&a1) { a1.a=-a1.a; a1.b=-a1.b; } void main() { clrscr(); abc obj1; obj1.getdata(10,15); obj1.display(); -obj1; obj1.display(); getch(); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to implement OVERLOADING of BINARY operator using FRIEND FUNCTION


Nikhil Jaiswal

S.U.S.C.E.T,Tangori

#include<iostream.h> #include<conio.h> class complex { float x,y; public: void getdata(float a,float b) { x=a; y=b; } void display() { cout<<"\n"<<x<<" + i "<<y<<"\n"; } complex operator-(complex&a1) { complex temp; temp.x=x-a1.x; temp.y=y-a1.y; return temp; } }; void main() { clrscr(); Nikhil Jaiswal

S.U.S.C.E.T,Tangori complex obj1,obj2,obj3; obj1.getdata(2.5,9.0); obj2.getdata(4.5,10.6); obj1.display(); obj2.display(); obj3=obj2-obj1; obj3.display(); getch(); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to implement OVERLOADING of BINARY operator using FRIEND FUNCTION


#include<iostream.h> #include<conio.h> class complex { float x,y; public: void getdata(float a,float b) { x=a; y=b; } void display() { cout<<"\n"<<x<<" + i "<<y<<"\n"; } friend complex operator-(complex&a1,complex&a2); }; complex operator-(complex&a1,complex&a2) { complex temp; temp.x=a1.x-a2.x; temp.y=a1.y-a2.y; return temp; } Nikhil Jaiswal

S.U.S.C.E.T,Tangori void main() { clrscr(); complex obj1,obj2,obj3; obj1.getdata(2.5,9.0); obj2.getdata(4.5,10.6); obj1.display(); obj2.display(); obj3=obj2-obj1; obj3.display(); getch(); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to implement OVERLOADING of + operator and == operator.


Nikhil Jaiswal

S.U.S.C.E.T,Tangori #include<iostream.h> #include<conio.h> #include<string.h> class mer { public: char *a; int len; mer(){}; mer(char *b); void operator +(char *c); void operator ==(mer b); void operator !(); void show() { cout<<a; } }; mer::mer(char*b) { len=strlen(b); a=new char[len+1]; strcpy(a,b); } void mer::operator +(char *c) { mer tmp; Nikhil Jaiswal

S.U.S.C.E.T,Tangori //int len1=len; int len2=strlen(c); tmp.len=len+len2; tmp.a=new char[tmp.len+1]; strcpy(tmp.a,a); strcat(tmp.a,c); cout<<"\n concatinated string: \t"<<tmp.a; } void mer::operator !() { mer t; t.len=len; t.a=new char[t.len]; strcpy(t.a,a); strrev(t.a); cout<<"\n reversed string is: \t"<<t.a; } void mer::operator==(mer b) { cout<<"\n string comparision:\t"; if (strcmp(a, b.a)==0) cout<<" the strings are equal"; else cout<<"the strings are not equal"; }

void main() Nikhil Jaiswal

S.U.S.C.E.T,Tangori { clrscr(); int i,gh='y'; char *w="Hello "; char *x="World"; mer s1(w),s2(x),s3,s4; cout<<"\n string 1=";s1.show(); cout<<"\n string 2=";s2.show(); do{ {

cout<<"\n menu:"; cout<<"\n1: string concatinate"; cout<<"\n2: string comparision"; cout<<"\n3: string reversal"; cout<<"\n enter your choice"; cin>>i; if(i==1){ s1+x; }

else if(i==2){ s1==s2; }

else if(i==3){ !s1; else cout<<"\n wrong choice"; }cout<<"\n do u wish 2 cont(y/n)";cin>>gh;}while(gh==1); getch(); } }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP to maintain EMPLOYEE database using STRUCTURES


#include<iostream.h> #include<conio.h> #include<stdio.h> struct employee { char name[15]; int age; Nikhil Jaiswal

S.U.S.C.E.T,Tangori void getdata () { puts("\n\nEnter Employee name "); gets(name); cout<<"\nEnter Age "; cin>>age; } void showdata () { cout<<"\nName : "; puts(name); cout<<"\nAge : "<<age; } }; void main () { clrscr (); const int size = 3; int i; employee database[size]; for (i=0;i<size;i++) { cout<<"\n\nEnter details for Employee "<<i+1; database[i].getdata (); } cout<<"\n\n\n"; for (i=0;i<size;i++) Nikhil Jaiswal

S.U.S.C.E.T,Tangori { cout<<"\n\nDetails for Employee "<<i+1; database[i].showdata (); } getch (); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP of Singlelevel inheritance


#include<iostream.h> #include<conio.h> class marks { protected: int m1,m2,score; public: void getmrks() { cout<<"Enter mrks of sub1"<<endl; cin>>m1; cout<<"Enter mrks of sub 2"<<endl; cin>>m2; } void shwmrks() { cout<<"Marks of sub1\t"<<m1<<endl; cout<<"Marks of sub2\t"<< m2<<endl; } void getscore() { cout<<"Enter the score"<<endl; cin>>score; } void shwscore() Nikhil Jaiswal

S.U.S.C.E.T,Tangori { cout<<"Score is"<<score<<endl; }}; class result:public marks { int total; public: void compute() { total=m1+m2+score; } void shwresult() { cout<<"Result is"<<total; }}; void main() { clrscr(); result o; o.getmrks(); o.getscore(); o.shwmrks(); o.shwscore(); o.compute(); o.shwresult(); getch(); } Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP of Multilevel inheritance


#include<iostream.h> #include<conio.h> class marks { Nikhil Jaiswal

S.U.S.C.E.T,Tangori protected: int m1,m2; public: void getmrks() { cout<<"enter mrks of sub1"<<endl; cin>>m1; cout<<"enter mrks of sub 2"<<endl; cin>>m2; } void shwmrks() { cout<<"marks of sub1\t"<<m1<<endl; cout<<"marks of sub2\t"<< m2<<endl; }}; class sport:public marks { protected: int score; public: void getscore() { cout<<"enter the score"<<endl; cin>>score; } void shwscore() { shwmrks(); cout<<"score is"<<score<<endl; }}; class result:public sport { int total; public: void compute() { total=m1+m2+score; } void shwresult() { cout<<"result is"<<total; }}; void main() { clrscr(); result o; o.getmrks(); o.getscore(); o.shwscore(); o.compute(); o.shwresult(); Nikhil Jaiswal

S.U.S.C.E.T,Tangori getch(); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP of Multiple inheritance


#include<iostream.h> #include<conio.h> class marks { protected: int m1,m2; public: void getmrks() { cout<<"Enter mrks of sub1"<<endl; cin>>m1; cout<<"Enter mrks of sub 2"<<endl; cin>>m2; } void shwmrks() { cout<<"Marks of sub1\t"<<m1<<endl; cout<<"Marks of sub2\t"<< m2<<endl; }}; class score { protected: int score; public: void getscore() { cout<<"Enter the score"<<endl; cin>>score; } void shwscore() { cout<<"Score is"<<score<<endl; } }; class result:public marks,public score { Nikhil Jaiswal

S.U.S.C.E.T,Tangori int total; public: void compute() { total=m1+m2+score; } void shwresult() { cout<<"Result is"<<total; } }; void main() { clrscr(); result o; o.getmrks(); o.getscore(); o.shwmrks(); o.shwscore(); o.compute(); o.shwresult(); getch(); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

WAP of hybrid inheritance


#include<iostream.h> #include<conio.h> class student { protected: int rollno; char name[10]; public: void getdata() { cout<<"Enter roll no"<<endl; cin>>rollno; cout<<"Enter name"<<endl; cin>>name; } void display() { cout<<"Rollno is "<<rollno<<endl; cout<<"Name is "<<name<<endl; } }; class marks:public student { protected: int m1,m2; public: void getmrks() { cout<<"Enter marks of subject1"<<endl; cin>>m1; cout<<"Enter marks of subject2"<<endl; cin>>m2; } void shw_mrks() { cout<<"Marks of sub1 "<<m1<<endl; cout<<"Marks of sub2 "<<m2<<endl; }}; class sport { protected: int score; public: void getscore() { Nikhil Jaiswal

S.U.S.C.E.T,Tangori cout<<"Enter score"<<endl; cin>>score;} void shwscore() { cout<<"Score is "<<score<<endl; } }; class result:public marks,public sport { protected: int total; public: void compute() { total= m1+m2+score; } void shwresult() { display(); cout<<"result is"<< total<<endl; }}; class average:public result { float avg; public: void calculate() { avg=total/3; } void shwavg() { cout<<"avg is"<<avg<<endl; } }; void main() { clrscr(); average obj1; obj1.getdata(); obj1.getmrks(); obj1.getscore(); obj1.shw_mrks(); obj1.shwscore(); obj1.compute(); obj1.shwresult(); obj1.calculate(); obj1.shwavg(); getch(); }

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

Nikhil Jaiswal

S.U.S.C.E.T,Tangori

Nikhil Jaiswal

Das könnte Ihnen auch gefallen