Sunteți pe pagina 1din 69

Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to input & print Array elements */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,n,a[16];
public:
void get();
void output();
};
void mca::get()
{
cout<<"Enter the limit= ";
cin>>n;
cout<<"\nEnter an elements is an Array= ";
for(i=0;i<n;i++)
{
cin>>a[i];
}
}
void mca::output()
{
cout<<"\nElements of an Array is= ";
for(i=0;i<n;i++)
{
cout<<" "<<a[i];
}
}
void main()
{
clrscr();
mca m;
m.get();
m.output();
getch();
}

OUTPUT : -

*******************************
Department Of Computer Application Page No …………….
Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to find sum & average of array elements */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,n,a[16],sum;
float avg;
public:
void get();
void output();
};
void mca::get()
{
sum=0;
cout<<"Enter the limit= ";
cin>>n;
cout<<"\nEnter the elements of an Array= ";
for(i=0;i<n;i++)
{
cin>>a[i];
sum=sum+a[i];
}
avg=(float)sum/n;
}
void mca::output()
{
cout<<"\nContents in an Array is= ";
for(i=0;i<n;i++)
{
cout<<" "<<a[i];
}
cout<<"\nSum of all elements of an Array is= "<<sum;
cout<<"\nAverage is= "<<avg;
}
void main()
{
clrscr();
mca m;
m.get();
m.output();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to sort & search an elements array elements with classes*/

#include<iostream.h>
#include<conio.h>
class mca
{
int elm,beg,end,mid,i,j,n,a[16];
public:
void get();
void sort();
void search();
};
void mca::get()
{
cout<<"How many elements do you want to enter in an array= ";
cin>>n;
cout<<"\nEnter an elements= ";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nEntered Elements= ";
for(i=0;i<n;i++)
{
cout<<" "<<a[i];
}
}
void mca::sort()
{
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
int temp;
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"\nSorted Elements= ";
for(i=0;i<n;i++)
{
cout<<" "<<a[i];
}
}
void mca::search()
{
cout<<"\nEnter the element that you want to search= ";

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

cin>>elm;
end=n;
mid=(beg+end)/2;
while((end>=beg)&&(elm!=a[mid]))
{
if(a[mid]>elm)
{
end=mid-1;
}
else
{
beg=mid+1;
}
mid=(beg+end)/2;
}
if(a[mid]==elm)
{
cout<<"\nElement "<<elm<<" is Searched at Location i.e."<<mid+1;
break;
}
if(beg>end)
{
cout<<"\nSearch Unsuccessful";
}
}
void main()
{
clrscr();
mca m;
m.get();
m.sort();
m.search();
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of call by address with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int s;
public:
void sum(int &,int &);
};
void mca::sum(int &a1,int &b1)
{
s=0;
s=a1+b1;
cout<<"Sum of two numbers= "<<s;
}
void main()
{
clrscr();
mca m;
int a,b;
cout<<"Enter the value of a and b= ";
cin>>a>>b;
m.sum(a,b);
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of call by reference with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int s;
public:
void sum(int *,int *);
};
void mca::sum(int *a1,int *b1)
{
s=0;
s=((*a1)+(*b1));
cout<<"Sum of two numbers= "<<s;
}
void main()
{
clrscr();
mca m;
int a,b,c;
cout<<"\nEnter the value of a and b= ";
cin>>a>>b;
m.sum(&a,&b);
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of call by value with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int s;
public:
void sum(int ,int);
};
void mca::sum(int a1,int b1)
{
s=0;
s=a1+b1;
cout<<"Sum of two numbers= "<<s;
}
void main()
{
int a,b,c;
clrscr();
mca m;
cout<<"Enter the two numbers= ";
cin>>a>>b;
m.sum(a,b);
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of conditional operator with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int a,b,c,d;
public:
void con();
};
void mca::con()
{
cout<<"Enter the Three Numbers= ";
cin>>a>>b>>c;
d=(a>b)?((a>c)?a:c):((b>c)?b:c);
cout<<"\nGreatest among Three Numbers= "<<d;
}
void main()
{
clrscr();
mca m;
m.con();
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to check how many no i.e given by user is equal to 10, greater
than 10 & less than 10 with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int c,c1,c2,i,n,a[16];
public:
void get();
void output();
};
void mca::get()
{
cout<<"How many elements do you want to enter in an array= ";
cin>>n;
cout<<"\nEnter an elements= ";
for(i=0;i<n;i++)
{
cin>>a[i];
}
}
void mca::output()
{
c=0; c1=0; c2=0;
for(i=0;i<n;i++)
{
if(a[i]==10)
{
c2++;
}
else if(a[i]<10)
{
c1++;
}
else
{
c++;
}
}
cout<<"\nGreater than Ten= "<<c;
cout<<"\nLess than Ten= "<<c1;
cout<<"\nEquals to Ten= "<<c2;
}
void main()
{
clrscr();
mca m;
m.get();

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

m.output();
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to search an element with linear search in classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int elm,b,c,i,n,a[16];
public:
void found();
};
void mca::found()
{
cout<<"How many elements do you want to enter in an array= ";
cin>>n;
cout<<"\nEnter an elements= ";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nEntered Elements= ";
for(i=0;i<n;i++)
{
cout<<" "<<a[i];
}
cout<<"\nEnter an element that you want to find= ";
cin>>elm;
for(i=0;i<n;i++)
{
if(a[i]==elm)
{
cout<<"Searching element found at "<<i+1<<" position";
break;
}
}
if(i==n)
{
cout<<"\nNot Found";
}
}
void main()
{
clrscr();
mca m;
m.found();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to input & print Matrix elements */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,j,r,c,a[16][16];
public:
void get();
void output();
};
void mca::get()
{
cout<<"Enter the number of Rows and Columns in a Matrix= ";
cin>>r>>c;
cout<<"\nEnter an Elements in Matrix=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
}
void mca::output()
{
cout<<"\nContents in a Matrix=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<" "<<a[i][j];
}
cout<<"\n";
}
}
void main()
{
clrscr();
mca m;
m.get();
m.output();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to copy an elements of matrix into another matrix with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,j,r,c,a[16][16],b[16][16];
public:
void get();
void copy();
};
void mca::get()
{
cout<<"Enter the number of Rows and Columns= ";
cin>>r>>c;
cout<<"\nEnter an elements in an Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
b[i][j]=a[i][j];
}
}
}
void mca::copy()
{
cout<<"\nContents in one Matrix copied into another Matrix is=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<" "<<b[i][j];
}
cout<<"\n";
}
}
void main()
{
clrscr();
mca m;
m.get();
m.copy();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to find multiplication of two matrix with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,l,l1,j,r,r1,c,c2,k,a[16][16],b[16][6],c1[16][16];
public:
void mul();
};
void mca::mul()
{
cout<<"Enter the number of Rows and Columns in a Matrix= ";
cin>>r>>c;
cout<<"\n";
cout<<"Enter the number of Rows and Columns for Second Matrix= ";
cin>>r1>>c2;
if(c==r1)
{
cout<<"\nEnter an Elements in First Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter an Elements in Second Matrix=\n ";
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
cin>>b[i][j];
}
}
cout<<"\nContents in First Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<" "<<a[i][j];
}
cout<<"\n";
}
cout<<"\nContents in Second Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<" "<<b[i][j];
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

cout<<"\n";
}
cout<<"\nMultiplication of an elements of a two matrices=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
c1[i][j]=0;
for(k=0;k<c;k++)
{
c1[i][j]= c1[i][j]+a[i][k] * b[k][j];
}
cout<<" "<<c1[i][j];
}
cout<<"\n";
}
}
else
{
cout<<"\nMultiplication is not possible";
}
}
void main()
{
clrscr();
mca m;
m.mul();
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to find the sum of diagonal elements of matrix with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,j,r,c,a[16][16],sum;
public:
void get();
void dia();
};
void mca::get()
{
cout<<"Enter the number of Rows and Columns= ";
cin>>r>>c;
cout<<"\nEnter an elements in an Matrix=\n ";
sum=0;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
if(i==j)
{
sum= sum + a[i][j];
}
}
}
}
void mca::dia()
{
cout<<"\nContents in Matrix=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<" "<<a[i][j];
}
cout<<"\n";
}
cout<<"\nSum of Diagonal elements is= "<<sum;
}
void main()
{
clrscr();
mca m;
m.get();
m.dia();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to find the sum of the elements of matrix with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,j,r,c,a[16][16],s;
public:
void get();
void sum();
};
void mca::get()
{
s=0;
cout<<"Enter the number of Rows and Columns in a Matrix= ";
cin>>r>>c;
cout<<"\nEnter an Elements in Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
s= s + a[i][j];
}
}
}
void mca::sum()
{
cout<<"\nContents in a Matrix=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<" "<<a[i][j];
}
cout<<"\n";
}
cout<<"\nSum of all elements of a Matrix= "<<s;
}
void main()
{
clrscr();
mca m;
m.get();
m.sum();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to find the subtraction two matrix with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,j,r,c,a[16][16],b[16][6],c1[16][16];
public:
void get();
void sub();
};
void mca::get()
{
cout<<"Enter the number of Rows and Columns in a Matrix= ";
cin>>r>>c;
cout<<"\nEnter an Elements in First Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter an Elements in Second Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>b[i][j];
}
}
}
void mca::sub()
{
c1[i][j]=0;
cout<<"\nSubtraction of an elements of a two matrices=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
c1[i][j]= a[i][j] - b[i][j];
cout<<" "<<c1[i][j];
}
cout<<"\n";
}
}

void main()
{
clrscr();

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

mca m;
m.get();
m.sub();
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to find the addition two matrix with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,j,r,c,a[16][16],b[16][6],c1[16][16];
public:
void get();
void sum();
};
void mca::get()
{
cout<<"Enter the number of Rows and Columns in a Matrix= ";
cin>>r>>c;
cout<<"\nEnter an Elements in First Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
cout<<"\nEnter an Elements in Second Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>b[i][j];
}
}
}
void mca::sum()
{
cout<<"\nSum of an elements of a two matrices=\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
c1[i][j]= a[i][j] + b[i][j];
cout<<" "<<c1[i][j];
}
cout<<"\n";
}
}
void main()
{
clrscr();
mca m;
m.get();

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

m.sum();
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to find the transpose of a matrix with classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,j,r,c,a[16][16],b[16][16];
public:
void get();
void trans();
};
void mca::get()
{
cout<<"Enter the number of Rows and Columns= ";
cin>>r>>c;
cout<<"\nEnter an elements in an Matrix=\n ";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cin>>a[i][j];
}
}
}
void mca::trans()
{
cout<<"\nContents in Matrix is =\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<" "<<a[i][j];
}
cout<<"\n";
}
cout<<"\nTranspose of an elements of Matrix is =\n";
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<" "<<a[j][i];
}
cout<<"\n";
}
}
void main()
{
clrscr();
mca m;
m.get();

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

m.trans();
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to find the factorial of a no with recursion in classes */

#include"iostream.h"
#include"conio.h"
class factorial
{
int p;
public:
int rec(int x)
{
if(x==1)
{
return(1);
}
else
{
p=x*rec(x-1);
return(p);
}
}
};
void main()
{
factorial g;
int a,fact;
clrscr();
cout<<"Enter Any No :- ";
cin>>a;
fact=g.rec(a);
cout<<"\n"<<"Factorial Is :- "<<fact;
getch();
}

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to check whether the given string is palindrome or not in


classes */

#include<iostream.h>
#include<conio.h>
#include<string.h>
class mca
{
int c,i,j,n;
char a[16],b[16],d[16];
public:
void palin();
};
void mca::palin()
{
cout<<"Enter the length of string = ";
cin>>n;
cout<<"\nEnter a String= ";
for(i=0;i<n;i++)
{
cin>>a[i];
}
strcpy(b,a);
strrev(a);
cout<<"\nString Reversed is= "<<a;
for(i=0;i<n;i++)
{
if(b[i]==a[i])
{
cout<<"\nString is Palidrome";
break;
}
else
{
cout<<"\nString is not Palidrome";
break;
}
}
}
void main()
{
clrscr();
mca m;
m.palin();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to print record of student having serial no, name, roll no &
dept.name using structure */

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
struct mca
{
int s_no,r_no;
char n[16],dept[6];
}s1[16];
void main()
{
clrscr();
int i,n;
cout<<"For how many students, you want to enter the data= ";
cin>>n;
cout<<"\nEnter the Student Record\n";
for(i=0;i<n;i++)
{
cout<<"\nEnter the Serial Number= ";
cin>>s1[i].s_no;
cout<<"\nEnter the Name of Student= ";
gets(s1[i].n);
cout<<"\nEnter the Roll Number= ";
cin>>s1[i].r_no;
cout<<"\nEnter the Department's Name= ";
cin>>s1[i].dept;
cout<<"\n"<<"@@@@@@@@@@@@@@@@@@@@@@@@@@*****STUDE
NT RECORD*****2@@@@@@@@@@@@@@@@@@@@@@@@@@";
cout<<"\nSerial No."<<"\t"<<"Name of Student"<<"\t\t"<<"Roll
Number"<<"\t"<<"Department's Name\n";
cout<<s1[i].s_no<<"\t\t\t"<<s1[i].n<<"\t\t"<<s1[i].r_no<<"\t\t"<<s1[i].dept<<"\n";
}
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT : -

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/* Write a program to print the following series */


1
2 3
4 5 6 ...........up to n

#include<iostream.h>
#include<conio.h>
class series
{
int i,j,n,s,x;
public:
void entery()
{
cout<<"Enter the value of Rows:- ";
cin>>n;
}
void counting()
{
x=0;
for(i=1;i<=n;i++)
{
for(s=n;s>=i;s--)
{
cout<<" ";
}
for(j=1;j<=i;j++)
{
cout<<j+x<<" ";
}
x=x+i;
cout<<"\n";
}
}
};
void main()
{
clrscr();
series p;
p.entery();
p.counting();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/* Write a program to print the following series */


*
* *
* * * ...........up to n
#include<iostream.h>
#include<conio.h>
class series
{
int i,j,n,s,x;
public:
void entery()
{
cout<<"Enter the value of Rows:- ";
cin>>n;
}
void star()
{
for(i=1;i<=n;i++)
{
for(s=n;s>=i;s--)
{
cout<<" ";
}
for(j=1;j<=i;j++)
{
cout<<"* ";
}
cout<<"\n";
}
}
};
void main()
{
clrscr();
series p;
p.entery();
p.star();
getch();
}
OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/* Write a program to print the pattern like if you enter 2 then it will show the
output 21012 with the help of classes */

#include<iostream.h>
#include<conio.h>
class mca
{
int i,j,n;
public:
void input()
{
cout<<"Enter Any Number :- ";
cin>>n;
}
void show()
{
for(i=n;i>=0;i--)
{
cout<<i;
}
for(j=1;j<=n;j++)
{
cout<<j;
}
}
};
void main()
{
clrscr();
mca p;
p.input();
p.show();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/* Write a program to print the pattern like if you enter 5678 then it will show the
output 5678 in new line each number with the help of classes */

#include<iostream.h>
#include<conio.h>
class patern
{
long int s,r,n;
public:
input()
{
cout<<"Enter Any Number :- ";
cin>>n;
}
show()
{
s=0;
while (n>0)
{
r=n%10;
s=s*10+r;
n=n/10;
}
while(s>1)
{
cout<<s%10<<"\n";
s=s/10;
}
}
};
main()
{
clrscr();
patern p;
p.input();
p.show();
getch();
}
OUTPUT :-

*******************************
Department Of Computer Application Page No …………….
Name : Prince Soni University Roll No :- 105682142962

/* Write a program to print the following pattern */


1+(1+2)+(1+2+3)+..........+up to n

#include<iostream.h>
#include<conio.h>
class mca
{
int i,j,s;
public:
int sum(int);
};
int mca::sum(int n1)
{
s=0;
for(i=1;i<=n1;i++)
{
cout<<"(";
for(j=1;j<=i;j++)
{
s=s+j;
cout<<j;
if(j!=i)
cout<<"+";
}
cout<<")";
if(i!=n1)
cout<<"+";
}
return s;
}
void main()
{
clrscr();
mca m;
int n,f;
cout<<"\n"<<"Enter the number= ";
cin>>n;
f=m.sum(n);
cout<<"\nSum of Even Number= "<<f;
getch();
}
OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/* Write a program to print the natural series */


1+2+3+4..........+up to n

#include<iostream.h>
#include<conio.h>
class mca
{
int i,s;
public:
int sum(int);
};
int mca::sum(int n1)
{
s=0;
for(i=1;i<=n1;i++)
{
cout<<i;
s=s+i;
if(i!=n1)
{
cout<<"+";
}
}
return s;
}
void main()
{
clrscr();
mca m;
int n,f;
cout<<"\n"<<"Enter the number= ";
cin>>n;
f=m.sum(n);
cout<<"\nSum of n Natural Number= "<<f;
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to addition of two objects of the same class */

#include<iostream.h>
#include<conio.h>
class mca
{
int a;
public:
void get(int);
void output();
void sum(mca,mca);
};
void mca::get(int c)
{
a=c;
}
void mca::sum(mca m,mca m1)
{
a= m.a + m1.a;
}
void mca::output()
{
cout<<a;
}

void main()
{
clrscr();
mca m,m1,m2;
m.get(11);
m1.get(5);
cout<<"\nEntered Element= ";
m.output();
cout<<"\nEntered Element= ";
m1.output();
cout<<"\nAddition of element of Two Classes= ";
m2.sum(m,m1);
m2.output();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to addition of two objects having minute & hours of the same
class */

#include<iostream.h>
#include<conio.h>
class mca
{
int hr,min;
public:
void get(int,int);
void time(mca,mca);
void output();
};
void mca::get(int h,int m)
{
hr=h;
min=m;
}
void mca::time(mca t1,mca t2)
{
hr= t1.hr + t2.hr;
if(hr>24)
{
hr = hr-24;
}
min= t1.min + t2.min;
if(min>60)
{
min = min-60;
}
}
void mca::output()
{
cout<<hr<<":"<<min;
}
void main()
{
clrscr();
mca m,m1,m2;
m.get(14,50);
m1.get(15,60);
cout<<"\nEntered Time= ";
m.output();
cout<<"\nEntered Time= ";
m1.output();
cout<<"\nActual Time= ";
m2.time(m,m1);
m2.output();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to check whether the given string is palindrome or not without
using library function in classes */

#include<iostream.h>
#include<conio.h>
#include<string.h>
class mca
{
int i,l,flag,j;
char a[20];
public:
void data();
};
void mca::data()
{
flag=0;
j=0;
cout<<"Enter String :- ";
cin>>a;
l=strlen(a);
for(i=0,j=l-1;i<=l/2;i++,j--)
{
if(a[i]==a[j])
{
continue;
}
else
{
flag=1;
}
}
if(flag==1)
{
cout<<"string is not palindrome"<<endl;
}
else
{
cout<<"string is palindrome"<<endl;
}
}
void main()
{
mca p;
clrscr();
p.data();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to compare two strings without using library function in classes
*/

#include<iostream.h>
#include<conio.h>
class mca
{
int i,d;
char a[20],b[20];
public:
void data();
};
void mca::data()
{
d=0;
cout<<"Enter First String = ";
cin>>a;
cout<<"Enter Secnd String = ";
cin>>b;
for(i=0;a[i]!='\0'||b[i]!='\0';i++)
{
if(a[i]==b[i])
{
continue;
}
else
{
d=1;
}
}
if(d==1)
{
cout<<"Both Strings Are Not Equal"<<endl;
}
else
{
cout<<"Both Strings Are Equal"<<endl;
}
}
void main()
{
mca p;
clrscr();
p.data();
getch();
}

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to check the whether the vowel present in a string or not */

#include<conio.h>
#include<iostream.h>
#include<string.h>
class mca
{
char a[20];
int i,d,count;
public:
void data();
};
void mca::data()
{
count=0;
cout<<"Enter any String = ";
cin.get(a,20);
d=strlen(a);
cout<<"string Length Is = "<<d<<endl;
for(i=0;i<d;i++)
{

if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u'||a[i]=='A'||a[i]=='E'||
a[i]=='I'||
a[i]=='O'||a[i]=='U')
{
count++;
}
}
cout<<"Total No Of Vowel In The Given String Is = "<<count<<endl;
}
void main()
{
mca p;
clrscr();
p.data();
getch();
}

OUTPUT :-

*******************************
Department Of Computer Application Page No …………….
Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to print the Fibonacci series using recursion */

#include<conio.h>
#include<iostream.h>
#include<string.h>
class mca
{
public:
int fib(int);
};
int mca::fib(int m)
{
if(m==1 || m==2 )
{
return(1);
}
else
{
return(fib(m-1)+fib(m-2));
}
}
void main()
{
mca p;
clrscr();
int n,i;
cout<<"Enter Any No = ";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<p.fib(i)<<" ";
}
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to print reverse of a string without using library function */

#include<iostream.h>
#include<conio.h>
class mca
{
char a[20],b[20];
int i,count,j;
public:
void data();
};
void mca::data()
{
count=0;
cout<<"Enter Any String = ";
cin.get(a,20);
for(i=0;a[i]!='\0';i++)
{
count++;
}
for(i=count-1,j=0;i>=0;i--,j++)
{
b[j]=a[i];
}
b[j]='\0';
cout<<"Reverse String Is = "<<b<<endl;
}
void main()
{
mca p;
clrscr();
p.data();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of default arguments */

#include<iostream.h>
#include<conio.h>
class mca
{
public:
void volume(int l=5,int h=2,int w=6);
};
void mca::volume(int l,int w,int h)
{
cout<<"Volume = "<<l*h*w<<endl;
}
void main()
{
mca p;
clrscr();
p.volume();
p.volume(4);
p.volume(5,10);
p.volume(2,3,4);
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of default constructor */

#include<iostream.h>
#include<conio.h>
class mca
{
int a,b;
public:
mca()
{
a=5;b=6;
cout<<a<<"\t"<<b<<endl;
}
};
void main()
{
clrscr();
mca p,q,r;
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of parameterized constructor */

#include<iostream.h>
#include<conio.h>
class mca
{
public:
mca(int a,int b)
{
cout<<a<<"\t"<<b<<endl;
}
};
void main()
{
clrscr();
mca p(1,2),q(3,4),r(5,6);
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of copy constructor */

#include<iostream.h>
#include<conio.h>
class mca
{
int i;
public:
mca(int a)
{
i=a;
}
mca(mca &x)
{
i=x.i;
}
void display()
{
cout<<" I is = "<<i<<endl;
}
};
void main()
{
clrscr();
mca p(100);
mca b(p);
mca c=p;
p.display();
b.display();
c.display();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of constructor & destructor */

#include<iostream.h>
#include<conio.h>
class mca
{
int i;
public:
mca()
{
cout<<"Its Constructor"<<endl;
}
~mca()
{
cout<<"Its Deconstructor";
getch();
}
};
void main()
{
clrscr();
mca p;
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of pointer to constant */

#include<iostream.h>
#include<conio.h>
class mca
{
public:
void show()
{
char s='a';
const char *ptr=&s;
//*ptr='b'; //not possible
cout<<"The Given Character Is = "<<s<<endl;
cout<<"The Pointer Content Is = "<<*ptr<<endl;
}
};
void main()
{
clrscr();
mca p;
p.show();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of constant pointer */

#include<iostream.h>
#include<conio.h>
class mca
{
public:
void show()
{
char s='a',m='c';
char * const ptr=&s;
cout<<"The Given Character Is = "<<s<<endl;
cout<<"The Pointer Content Is = "<<*ptr<<endl;
*ptr='b';
cout<<"The Pointer Content Is = "<<*ptr<<endl;
//ptr=&m //not possible
cout<<"The Given Character Is = "<<m<<endl;
cout<<"The Pointer Content Is = "<<*ptr<<endl;
}
};
void main()
{
clrscr();
mca p;
p.show();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of nested class */

#include<iostream.h>
#include<conio.h>
class mca
{
public:
int a,b;
class bca
{
public:
int c,d;
void show()
{
cout<<"c Is = "<<c<<endl;
cout<<"d Is = "<<d<<endl;
}
};
void show()
{
cout<<"a Is = "<<a<<endl;
cout<<"b Is = "<<b<<endl;
}
};
void main()
{
clrscr();
mca p;
p.a=5;p.b=10;
p.show();
mca::bca g;
g.c=15;g.d=20;
g.show();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of static data member & static member
function*/

#include<iostream.h>
#include<conio.h>
class mca
{
public:
static int b;
static add(int x)
{
b=b+x;
cout<<"The value of b in function is = "<<b<<endl;
}
};
int mca::b=5;
void main()
{
clrscr();
mca p;
cout<<"The value of b is = "<<p.b<<endl;
p.add(10);
mca::add(20);
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of friend function*/

#include<iostream.h>
#include<conio.h>
class frnd
{
int a;
public:
void data(int h)
{
a=h;
}
friend void display(frnd);
};
void display(frnd g)
{
cout<<"The value Of a Is = "<<g.a;
}
int main()
{
frnd p;
clrscr();
p.data(7);
display(p);
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of friend function act as a bridge between
two classes */

#include<iostream.h>
#include<conio.h>
class frnds;
class frnd
{
int a;
public:
void data(int h)
{
a=h;
}
friend void display(frnd,frnds);
};
class frnds
{
int b;
public:
void data1(int i)
{
b=i;
}
friend void display(frnd,frnds);
};
void display(frnd e,frnds f)
{
cout<<"Difference = "<<e.a-f.b;
}
void main()
{
frnd p;
clrscr();
p.data(10);
frnds t;
t.data1(3);
display(p,t);
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of single Inheritence */

#include<iostream.h>
#include<conio.h>
class base
{
public:
void data()
{
cout<<"Base Class Function"<<"\n";
}
};
class derived:public base
{
public:
void data1()
{
cout<<"Derived Class Function";
}
};
void main()
{
derived p;
clrscr();
p.data();
p.data1();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of Multilevel Inheritence */

#include<iostream.h>
#include<conio.h>
class abc
{
int a;
public:
void data(int x)
{
a=x;
}
void output()
{
cout<<"The Value Of a is = "<<a<<"\n";
}
};
class bcd:public abc
{
int b;
public:
void data1(int y)
{
b=y;
}
void output()
{
cout<<"The Value Of b is = "<<b<<"\n";
}
};
class cde:public bcd
{
int c;
public:
void data2(int z)
{
c=z;
}
void output()
{
abc::output();
bcd::output();
cout<<"The Value Of c is = "<<c<<"\n";
}
};
void main()
{
cde p;
clrscr();
p.data(5);

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

p.data1(10);
p.data2(15);
p.output();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of Multiple Inheritence */

#include<iostream.h>
#include<conio.h>
class abc
{
int a;
public:
void data(int x)
{
a=x;
}
void output()
{
cout<<"The Value Of a is = "<<a<<"\n";
}
};
class bcd
{
int b;
public:
void data1(int y)
{
b=y;
}
void output()
{
cout<<"The Value Of b is = "<<b<<"\n";
}
};
class cde:public bcd,public abc
{
int c;
public:
void data2(int z)
{
c=z;
}
void output()
{
abc::output();
bcd::output();
cout<<"The Value Of c is = "<<c<<"\n";
}
};
void main()
{
cde p;
clrscr();
p.data(5);

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

p.data1(10);
p.data2(15);
p.output();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

/ * Write a program to show the concept of Hierarchical Inheritence */

#include<iostream.h>
#include<conio.h>
class abc
{
int a;
public:
void data(int x)
{
a=x;
}
void output()
{
cout<<"The Value Of a is = "<<a<<"\n";
}
};
class bcd:public abc
{
int b;
public:
void data1(int y)
{
b=y;
}
void output()
{
abc::output();
cout<<"The Value Of b is = "<<b<<"\n";
}
};
class cde:public abc
{
int c;
public:
void data2(int z)
{
c=z;
}
void output()
{
abc::output();
cout<<"The Value Of c is = "<<c<<"\n";
}
};
void main()
{
bcd g;
cde p;
clrscr();

Department Of Computer Application Page No …………….


Name : Prince Soni University Roll No :- 105682142962

g.data(1);
g.data1(3);
p.data(4);
p.data2(5);
g.output();
p.output();
getch();
}

OUTPUT :-

*******************************

Department Of Computer Application Page No …………….

S-ar putea să vă placă și