0% found this document useful (0 votes)
8 views103 pages

Fibonacci Series Generation Program

The document contains 15 C++ programs that demonstrate various algorithms: 1. Two programs to generate the Fibonacci series using functions and classes. 2. Two programs to find the greatest common divisor (GCD) of two numbers using functions and classes. 3. A program to find the maximum and minimum of N numbers using functions. 4. A program to find the maximum and minimum of N numbers using classes. 5. Two programs to generate prime numbers using functions and classes. 6. Two programs to generate perfect divisors using functions and classes. 7. A program to generate both prime numbers and perfect divisors using functions. 8. A program to generate both prime numbers and perfect divisors using classes
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views103 pages

Fibonacci Series Generation Program

The document contains 15 C++ programs that demonstrate various algorithms: 1. Two programs to generate the Fibonacci series using functions and classes. 2. Two programs to find the greatest common divisor (GCD) of two numbers using functions and classes. 3. A program to find the maximum and minimum of N numbers using functions. 4. A program to find the maximum and minimum of N numbers using classes. 5. Two programs to generate prime numbers using functions and classes. 6. Two programs to generate perfect divisors using functions and classes. 7. A program to generate both prime numbers and perfect divisors using functions. 8. A program to generate both prime numbers and perfect divisors using classes
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

1.

Program to generate fibonacci series


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void fib(int);
int main()
{
clrscr();
int n;
cout<<"Enter the limit :";
cin>>n;
cout<<"The fibonacci series upto the limit "<<n<<" is"<<endl<<endl;
fib(n);
getch();
return 0;
}
void fib(int n)
{
int a=1,b=0,c=0 ;
for(int i=0;c<=n;i++)
{
cout<<c<<setw(4);
c=a+b;
a=b;
b=c;
}
cout<<endl<<endl<<"The number in the fibonacci series upto the limit
"<<n<<" is "<<i;
}
Output:
Enter the limit: 25
The fibonacci series upto the limit 25 is
0 1 1 2 3 5 8 13 21
The number in the fibonacci series upto the limit 25 is 9

2. Program to generate fibonacci series using class


#include<iostream.h>
#include<conio.h>
class fib
{
private:
int n;
public:
void read();
void fibo();
};
void fib::read()
{
cin>>n;
}
void fib::fibo()
{
int a=1,b=0,c=0,i;
cout<<"The fibonacci series upto the limit "<<n<<" is :";
for(i=0;c<=n;i++)
{
cout<<c<<" ";
c=a+b;
a=b;
b=c;
}
cout<<endl<<"The number of elements in the fibonacci series upto the
limit "<<n<<" is "<<i;
}
int main()
{
clrscr();
fib f;
cout<<"Enter the limit :";
[Link]();
[Link]();
getch();
return 0;
}

Output:
Enter the limit: 50
The fibonacci series upto the limit 50 is: 0 1 1 2 3 5 8 13 21 34
The number of elements in the fibonacci series upto the limit 50 is 10

3. Program to find GCD of two no


#include<iostream.h>
#include<conio.h>
int fun(int,int);
int main()
{
clrscr();
int a,b;
cout<<"Enter the two numbers : ";
cin>>a>>b;
cout<<"Gcd of "<<a<<" and "<<b<<" is "<<fun(a,b);
getch();
return 0;
}
int fun(int x, int y)
{
int r;
while(y!=0)
{
r=x%y;
x=y;
y=r;
}
return (x);
}
Output:
Enter the two numbers: 21 7
Gcd of 21 and 7 is 7

4. Program to find GCD of two no using class


#include<iostream.h>
#include<conio.h>
class gcd
{
private:
int a,b,k,p,q;
public:
void read();
void fun();
void display();
};
void gcd::read()
{
cout<<"Enter the two numbers : ";
cin>>a>>b;
p=a;
q=b;
}
void gcd::fun()
{
int r;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
k=a;
}
void gcd::display()
{
cout<<"Gcd of "<<p<<" and "<<q<<" is "<<k;
}
int main()
{
clrscr();
gcd g;
[Link]();
[Link]();
[Link]();

getch();
return 0;
}
Output:
Enter the two numbers: 52 12
Gcd of 52 and 12 is 4

5. Program to find maximum and minmum of N numbers


#include<iostream.h>
#include<conio.h>
void mm(int,int);
int main()
{
clrscr();
int n,in;
cout<<"Enter the input number limit: ";
cin>>n;
cout<<"Enter the numbers: "<<endl;
cin>>in;
mm(in,n);
getch();
return 0;
}
void mm(int in,int n)
{
int max=in;
int min=in;
for(int i=0;i<n-1;i++)
{
cin>>in;
if(min>in)
{
min=in;
}
else if(max<in)
{
max=in;
}
}
cout<<"Maximum number is: "<<max<<endl;
cout<<"Minimum number is: "<<min;
}
Output:
Enter the input number limit: 5
Enter the numbers: 9 4 7 8-5
Maximum number is: 9
Minimum number is: -5

6. Program to find maximum and minmum of N numbers using class


#include<iostream.h>
#include<conio.h>
class mm
{
private:
int i,l,a[10],mx,mn;
public:
void read();
void fun();
void dis()
{
cout<<"Maximum number is "<<mx<<endl;
cout<<"Minimum number is "<<mn<<endl;
}
};
void mm::read()
{
cout<<"Enter the limit : ";
cin>>l;
cout<<"Enter "<<l<<" numbers : ";
for(i=0;i<l;i++)
cin>>a[i];
}
void mm::fun()
{
mx=a[0];
mn=a[0];
for(int i=0;i<l;i++)
{
if(mx<a[i])
mx=a[i];
if(mn>a[i])
mn=a[i];
}
dis();
}
int main()
{
mm obj;
clrscr();
[Link]();

[Link]();
getch();
return 0;
}
Output:
Enter the limit: 8
Enter 8 numbers: -9 0 2 7 -99 66 43 -101
Maximum number is: 66
Minimum number is: -101

7. Program to generate prime numbers


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
void prime(int);
int main()
{
clrscr();
int n;
cout<<"Enter the limit : ";
cin>>n;
cout<<endl<<"The prime numbers up to "<<n<<" are: ";
prime(n);
getch();
return 0;
}
void prime(int n)
{
int c=0,k,j;
for(int i=1;i<=n;i++)
{
k=sqrt(i);
for(j=2;j<=k;j++)
if(i%j==0)
break;
if(j>k)
{
cout<<i<<setw(4);
c++;
}
}
cout<<"\n\nThe number of elements in the seris up to "<<n<<" is "<<c;
}
Output:
Enter the limit : 26
The prime numbers up to 26 are: 1 2 3 5 7 11 13 17 19 23
The number of elements in the seris up to 26 is 10

8. Program to generate prime numbers using class


#include<iostream.h>
#include<conio.h>
#include<math.h>
class cprime
{
private:
int n;
public:
cprime(){}
~cprime(){}
void read()
{
cin>>n;
}
void prime();
};
void cprime::prime()
{
int c=0,k,j;
cout<<endl<<"Prime numbers upto the limit "<<n<<" are :" ;
for(int i=1;i<=n;i++)
{
k=sqrt(i);
for(j=2;j<=k;j++)
if(i%j==0)
break;
if(j>k)
{
cout<<" "<<i;
c++;
}
}
cout<<"\n\nThe number of elements in the seris up to "<<n<<" is "<<c;
}
int main()
{
clrscr();
cprime p;
cout<<"Enter the limit : ";
[Link]();
[Link]();
getch();
return 0;
}

Output:
Enter the limit : 30
Prime numbers upto the limit 30 are : 1 2 3 5 7 11 13 17 19 23 29
The number of elements in the seris up to 30 is 11

9. Program to generate perfect divisors


#include<iostream.h>
#include<conio.h>
#include<math.h>
void per(int);
void main()
{
int num,sum,i,n;
clrscr();
cout<<"Enter the limit:";
cin>>num;
per(num);
getch();
}
void per(int num)
{
int sum,c=0;
cout<<endl<<"Perfect numbers are: ";
for(int n=2;n<=num;n++)
{
sum=1;
for(int i=2;i<sqrt(n);i++)
{
if(n%i==0)
sum=sum+i+n/i;
}
if(sum==n)
{
cout<<" "<<sum;
c++;
}
}
cout<<"\n\nThe number of elements in the series up to "<<num<<" is : "<<c;
}
Output:
Enter the limit:50
Perfect numbers are: 6 28
The number of elements in the series up to 50 is : 2

10. Program to generate perfect divisors using class


#include<iostream.h>
#include<math.h>
#include<conio.h>
class perf
{
private:
int n,i,sum;
public:
perf(){}
~perf(){}
void read()
{
cin>>n;
}
void dis();
};
void perf::dis()
{
int sum,c=0;
cout<<endl<<"Perfect numbers are: ";
for(int i=2;i<=n;i++)
{
sum=1;
for(int j=2;j<sqrt(i);j++)
{
if(i%j==0)
sum=sum+j+i/j;
}
if(sum==i)
{
cout<<" "<<sum;
c++;
}
}
cout<<"\n\nThe number of elements in the series up to "<<n<<" is : "<<c;
}
int main()
{
clrscr();
perf p;
cout<<"Enter the limit:";
[Link]();

[Link]();
getch();
return 0;
}
Output:
Enter the limit: 500
Perfect numbers are: 6 28 496
The number of elements in the series up to 500 is: 3

11. Program to generate prime and perfect divisors


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
void perpri(int);
int main()
{
clrscr();
int n;
cout<<"Enter the limit : ";
cin>>n;
perpri(n);
getch();
return 0;
}
void perpri(int n)
{
int c=0,k,j,d[5],x=0,sum;
cout<<"\nPrime numbers up to the limit "<<n<<" are: ";
for(int i=1;i<=n;i++)
{
k=sqrt(i);
sum=1;
for(j=2;j<=k;j++)
if(i%j==0)
sum+=j+i/j;
if(sum==i&&i!=1)
{
d[c]=i;
c++;
}
if(sum==1)
{
cout<<i<<setw(4);
x++;
}
}
cout<<"\n\nThe number of elements in the prime series up to "<<n<<" is
"<<x;
cout<<"\n\nPerfect divisors up to the limit "<<n<<" are: ";
for(i=0;i<c;i++)
cout<<d[i]<<setw(4);

cout<<"\n\nThe number of elements in the perfect divisors series up to


"<<n<<" is "<<c;
}
Output:
Enter the limit : 55
Prime numbers up to the limit 55 are: 1 2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53
The number of elements in the prime series up to 55 is 17
Perfect divisors up to the limit 55 are: 6 28
The number of elements in the perfect divisors series up to 55 is 2

12. Program to generate prime and perfect divisors using class


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
class pp
{
private:
int n;
public:
pp(){}
~pp(){}
int c,x,prime[100],per[10];
void read()
{
cin>>n;
}
void perpri();
void display();
};
void pp::perpri()
{
int k,sum;
c=0;x=0;
for(int i=1;i<=n;i++)
{
k=sqrt(i);
sum=1;
for(int j=2;j<=k;j++)
if(i%j==0)
sum+=j+i/j;
if(sum==i&&i!=1)
{
per[c]=i;
c++;
}
if(sum==1)
{
prime[x]=i;
x++;
}
}
}

void pp::display()
{
cout<<"\nPrime numbers up to the limit "<<n<<" are: ";
for(int i=0;i<x;i++)
cout<<prime[i]<<setw(4);
cout<<"\n\nThe number of elements in the prime series up to "<<n<<" is
"<<x;
cout<<"\n\nPerfect divisors up to the limit "<<n<<" are: ";
for(i=0;i<c;i++)
cout<<per[i]<<setw(4);
cout<<"\n\nThe number of elements in the perfect divisors series up to
"<<n<<" is "<<c;
}
int main()
{
clrscr();
pp p1;
cout<<"Enter the limit : ";
[Link]();
[Link]();
[Link]();
getch();
return 0;
}
Output:
Enter the limit: 40
Prime numbers up to the limit 40 are: 1 2 3 5 7 11 13 17 19 23 29
31 37
The number of elements in the prime series up to 40 is 13
Perfect divisors up to the limit 40 are: 6 28
The number of elements in the perfect divisors series up to 40 is 2

13. Program to sort the given N numbers

#include<iostream.h>
#include<conio.h>
int a[25];
void read(int);
void display(int);
void srt(int);
int main()
{
clrscr();
int n;
cout<<"Enter the limit value : ";
cin>>n;
read(n);
srt(n);
display(n);
getch();
return 0;
}
void read(int n)
{
cout<<"Enter "<<n<<" numbers to sort: ";
for(int i=0;i<n;i++)
cin>>a[i];
}
void srt(int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
{
if(a[i] < a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
void display(int n)
{
cout<<"Sorted array in ascending order is: ";

for(int i=0;i<n;i++)
cout<<a[i]<<" ";
}
Output:
Enter the limit value: 5
Enter 5 numbers to sort: 2 1 6 -21 0
Sorted array in ascending order is: -21 0 1 2 6

14. Program to sort the given N numbers using class

#include<iostream.h>
#include<conio.h>
class sort
{
private:
int a[10],i,j,n;
public:
void read();
void display();
void srt();
};
void sort::read()
{
cin>>n;
cout<<"Enter "<<n<<" numbers to sort: ";
for(i=0;i<n;i++)
cin>>a[i];
}
void sort::srt()
{
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
if(a[i] < a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
void sort::display()
{
cout<<"Sorted array in ascending order is: ";
for(i=0;i<n;i++)
cout<<a[i]<<" ";
}
int main()
{
clrscr();
cout<<"Enter the limit value : ";
sort st;

[Link]();
[Link]();
[Link]();
getch();
return 0;
}
Output:
Enter the limit value: 7
Enter 7 numbers to sort: 3 2 -66 -444 9 100 22
Sorted array in ascending order is: -444 -66 2 3 9 22 100

15. Program to sort the given N names


#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
char name[10][25];
void read(int);
void sort(int);
void display(int);
int main()
{
clrscr();
int n;
cout<<"Enter the number of names to be sorted:";
cin>>n;
read(n);
sort(n);
display(n);
getch();
return 0;
}
void read(int n)
{
int j=1;
for(int i=0;i<n;i++)
{
cout<<"Enter name "<<j++<<" ";
cin>>name[i];
name[i][0]= toupper(name[i][0]) ;
}
}
void sort(int n)
{
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(strcmp(name[j],name[i])<0)
{
char temp[25];
strcpy(temp,name[j]);
strcpy(name[j],name[i]);
strcpy(name[i],temp);
}
}

void display(int n)
{
cout<<"Names after sorting:"<<endl;
for(int i=0;i<n;i++)
cout<<endl<<name[i];
}
Output:
Enter the number of names to be sorted:5
Enter name 1: manjesh
Enter name 2: nagaraju
Enter name 3: soma
Enter name 4: dilip
Enter name 5: manju
Names after sorting:
Dilip
Manjesh
Manju
Nagaraju
Soma

16. Program to sort the given N names using class


#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
class names
{
private:
char name[10][25];
int n;
public:
void read();
void sort();
void display();
};
void names::read()
{
cin>>n;
cout<<endl;
for(int i=0;i<n;i++)
{
int j=i;
cout<<"Enter name "<<j+1<<" : ";
cin>>name[i];
name[i][0]= toupper(name[i][0]) ;
}
}
void names::sort()
{
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(strcmp(name[j],name[i])<0)
{
char temp[25];
strcpy(temp,name[j]);
strcpy(name[j],name[i]);
strcpy(name[i],temp);
}
}
void names::display()
{

int i;
for(i=0;i<n;i++)
cout<<endl<<name[i];
}
int main()
{
clrscr();
names st;
cout<<"Enter the number of names to be sorted:";
[Link]();
[Link]();
cout<<endl<<"Sorted names:"<<endl;
[Link]();
getch();
return 0;
}
Output:
Enter the number of names to be sorted:6
Enter name
Enter name
Enter name
Enter name
Enter name
Enter name

1: manjunath
2: prashanth
3: manjesh
4: dilip
5: soma
6: nagaraj

Sorted names:
Dilip
Manjesh
Manjunath
Nagaraj
Prashanth
Soma

17. Program to find the roots of quadratic equation


#include<iostream.h>
#include<conio.h>
#include<math.h>
float a,b,c,k;
void cal();
void img();
void equal();
void distinct();
void linear();
int main()
{
clrscr();
cout<<"Enter the coefficients of the a,b,c: ";
cin>>a>>b>>c;
k=b*b-4*a*c;
cal();
getch();
return 0;
}
void cal()
{
if(a==0)
linear();
else
if(k>0)
distinct();
else
if(k==0)
equal();
else
img();
}
void linear()
{
cout<<endl<<"The given equation is linear."<<endl<<"Root is: "<<(-c/b);
}
void equal()
{
cout<<endl<<"The roots are real and equal"<<endl;
cout<<endl<<"Root 1 is: "<<-b/(2*a);
cout<<endl<<"Root 2 is: "<<-b/(2*a);
}
void distinct()
{

cout<<endl<<"The roots are real and distinct"<<endl;


cout<<endl<<"Root 1 is: "<<(-b+sqrt(k))/(2*a);
cout<<endl<<"Root 2 is: "<<(-b-sqrt(k))/(2*a);
}
void img()
{
float m,n;
cout<<endl<<"The roots are complex"<<endl;
m=-b/(2*a);
n=sqrt(fabs(k))/(2*a);
cout<<endl<<"Root 1 is: "<<m<<"+i"<<n;
cout<<endl<<"Root 2 is: "<<m<<"-i"<<n;
}
Output:
Enter the coefficients of the a, b, c: 0 2 3
The given equation is linear.
Root is: -1.5
Enter the coefficients of the a, b, c: 1 2 1
The roots are real and equal
Root 1 is: -1
Root 2 is: -1
Enter the coefficients of the a, b, c: 1 4 2
The roots are real and distinct
Root 1 is: -0.585786
Root 2 is: -3.414214
Enter the coefficients of the a, b, c: 4 2 3
The roots are complex
Root 1 is: -0.25+i0.829156
Root 2 is: -0.25-i0.829156

18. Program to find the roots of quadratic equation using class


#include<iostream.h>
#include<conio.h>
#include<math.h>
class quad
{
private:
float a,b,c,k;
public:
quad(){}
~quad(){}
void read()
{
cin>>a>>b>>c;
k=b*b-4*a*c;
}
void cal();
void img();
void equal();
void distinct();
void linear();
};
void quad::cal()
{
if(a==0)
linear();
else
if(k>0)
distinct();
else
if(k==0)
equal();
else
img();
}
void quad::linear()
{
cout<<endl<<"The given equation is linear."<<endl<<"Root is: "<<(-c/b);
}
void quad::equal()
{
cout<<endl<<"The roots are real and equal"<<endl;

cout<<endl<<"Root 1 is: "<<-b/(2*a);


cout<<endl<<"Root 2 is: "<<-b/(2*a);
}
void quad::distinct()
{
cout<<endl<<"The roots are real and distinct"<<endl;
cout<<endl<<"Root 1 is: "<<(-b+sqrt(k))/(2*a);
cout<<endl<<"Root 2 is: "<<(-b-sqrt(k))/(2*a);
}
void quad::img()
{
float m,n;
cout<<endl<<"The roots are complex"<<endl;
m=-b/(2*a);
n=sqrt(fabs(k))/(2*a);
cout<<endl<<"Root 1 is: "<<m<<"+i"<<n;
cout<<endl<<"Root 2 is: "<<m<<"-i"<<n;
}
int main()
{
clrscr();
quad q;
cout<<"Enter the coefficients of the a,b,c: ";
[Link]();
[Link]();
getch();
return 0;
}

Output:
Enter the coefficients of the a, b, c: 0 2 4
The given equation is linear.
Root is: -2
Enter the coefficients of the a, b, c: 2 4 2
The roots are real and equal
Root 1 is: -1
Root 2 is: -1
Enter the coefficients of the a, b, c: 2 4 -3
The roots are real and distinct
Root 1 is: 0.581139
Root 2 is: -2.581139
Enter the coefficients of the a,b,c: - 2 5 -6
The roots are complex
Root 1 is: -4.203895e-45+i9.55142e-19
Root 2 is: -4.203895e-45-i9.55142e-19

19. rogram to find the value of sine and cosine series


#include<iostream.h>
#include<conio.h>
#include<math.h>
float func(float,float,int);
int main()
{
int i,p;
float deg,x,y,m;
clrscr();
cout<<"Enter the degree : ",
cin>>deg;
cout<<endl<<"Enter the accuracy : ";
cin>>m;
x=3.14*deg/180;
cout<<endl<<"sin("<<deg<<")="<<func(x,m,1);
cout<<endl<<"cos("<<deg<<")="<<fabs(func(x,m,0));
getch();
return 0;
}
float func(float x,float a,int p)
{
int i;
float b=0,sum=0;
long int fact=1;
for(i=p;;i+=2)
{
sum+=pow(x,i)*pow(-1,i/2)/fact;
fact*=(i+1)*(i+2);
if(fabs(sum-b)<a)
break;
b=sum;
}
return(b);
}
Output:
Enter the degree: 48
Enter the accuracy: 0.0001
sin(48)=0.742917
cos(48)=0.66944

20. Program to find the value of sine and cosine series using class
#include<iostream.h>
#include<conio.h>
#include<math.h>
class sincos
{
private:
int i,p;
float deg,x,y,m;
public:
void read();
float sincs(int);
void display()
{
cout<<endl<<"sin("<<deg<<")="<<sincs(1);
cout<<endl<<endl<<"cos("<<deg<<")="<<sincs(0);
}
};
void sincos::read()
{
cout<<"Enter the degree : ",
cin>>deg;
cout<<endl<<"Enter the accuracy : ";
cin>>m;
x=3.14*deg/180;
}
float sincos::sincs(int k)
{
float b=0,sum=0;
long int fact=1;
for(int i=k;;i+=2)
{
sum+=pow(x,i)*pow(-1,i/2)/fact;
fact*=(i+1)*(i+2);
if(fabs(sum-b)<m)
break;
b=sum;
}
return(sum);
}
int main()
{
clrscr();

sincos s;
[Link]();
[Link]();
getch();
return 0;
}
Output:
Enter the degree: 87
Enter the accuracy: 0.0001
sin(87)=0.998589
cos(87)=0.053104

21. Program to add and subtract two matrices


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void add(int m1[20][20],int m2[20][20],int r1,int c1);
void sub(int m1[20][20],int m2[20][20],int r1,int c1);
int main()
{
int m1[20][20],m2[20][20],r1,c1,r2,c2;
clrscr();
cout<<"Enter order of matrix 1 : ";
cin>>r1>>c1;
cout<<"Enter order of matrix 2 : ";
cin>>r2>>c2;
if(r1!=r2||c1!=c2)
{
cout<<"operation not possiable";
}
else
{
cout<<endl<<"Enter first matrix "<<endl;
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
cin>>m1[i][j];
cout<<endl<<"Enter second matrix "<<endl;
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
cin>>m2[i][j];
cout<<endl<<"Matrix after addition"<<endl;
add(m1,m2,r1,c1);
cout<<endl<<endl<<"Matrix after subtraction"<<endl;
sub(m1,m2,r1,c1);
}
getch();
return 0;
}
void add(int m1[20][20],int m2[20][20],int r1,int c1)
{
int a[20][20];
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
a[i][j]=m1[i][j]+m2[i][j];
for(i=0;i<r1;i++)
{

cout<<endl;
for(int j=0;j<c1;j++)
cout<<setw(4)<<a[i][j];
}
}
void sub(int m1[20][20],int m2[20][20],int r1,int c1)
{
int s[20][20];
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
s[i][j]=m1[i][j]-m2[i][j];
for(i=0;i<r1;i++)
{
cout<<endl;
for(int j=0;j<c1;j++)
cout<<setw(4)<<s[i][j];
}
}
Output:
Enter order of matrix 1: 3 6
Enter order of matrix 2: 2 3
Operation not possible
Enter order of matrix 1: 2 5
Enter order of matrix 2: 2 5
Enter elements of first matrix:
12478
65890
Enter elements of second matrix:
34587
21456
Matrix after addition
4 6 9 15 15
8 6 12 14 6
Matrix after subtraction
-2 -2 -1 -1 1
4 4 4 4 -6

22. Program to add and subtract two matrices using class

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
class matrix
{
private:
int r,c,m[10][10];
public:
matrix(){}
~matrix(){}
void read()
{
cin>>r>>c;
}
void mat();
int con(matrix,matrix);
void add(matrix,matrix);
void sub(matrix,matrix);
void dis()
{
for(int i=0;i<r;i++)
{
cout<<endl;
for(int j=0;j<c;j++)
cout<<setw(4)<<m[i][j];
}
}
};
int matrix::con(matrix x,matrix y)
{
return((x.r==y.r&&x.c==y.c)?1:0);
}
void matrix::mat()
{
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
cin>>m[i][j];
}
void matrix::add(matrix x, matrix y)
{
r=x.r;

c=x.c;
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
m[i][j]=x.m[i][j]+y.m[i][j];
}
void matrix::sub(matrix x, matrix y)
{
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
m[i][j]=x.m[i][j]-y.m[i][j];
}
int main()
{
clrscr();
matrix m1,m2,a;
cout<<"Enter order of matrix 1 : ";
[Link]();
cout<<"Enter order of matrix 2 : ";
[Link]();
if([Link](m1,m2))
{
cout<<"Enter elements of first matrix:"<<endl;
[Link]();
cout<<"Enter elements of second matrix:"<<endl;
[Link]();
cout<<endl<<"Matrix after addition"<<endl;
[Link](m1,m2);
[Link]();
cout<<endl<<"Matrix after subtraction"<<endl;
[Link](m1,m2);
[Link]();
}
else
cout<<"operation not possiable";
getch();
return 0;
}

Output:
Enter order of matrix 1: 2 3
Enter order of matrix 2: 3 2
Operation not possiable
Enter order of matrix 1: 3 4
Enter order of matrix 2: 3 4
Enter first matrix
1425
6254
3978
Enter second matrix
0247
9145
9486
Matrix after addition
1 6 6 12
15 3 9 9
12 13 15 14
Matrix after subtraction
1 2 -2 -2
-3 1 1 -1
-6 5 -1 2

23. Program to multiply two matrices


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void multi(int m1[20][20],int m2[20][20],int r1,int c1,int r2,int c2);
int main()
{
int m1[20][20],m2[20][20],r1,r2,c1,c2;
clrscr();
cout<<"Enter the order of first matrix : ";
cin>>r1>>c1;
cout<<"Enter the order of second matrix : ";
cin>>r2>>c2;
if(c1!=r2)
{
cout<<endl<<"Multiplication not possible"<<endl;
}
else
{
cout<<endl<<"Enter first matrix "<<endl;
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
cin>>m1[i][j];
cout<<endl<<"Enter second matrix "<<endl;
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
cin>>m2[i][j];
multi(m1,m2,r1,r2,c1,c2);
}
getch();
return 0;
}
void multi(int m1[20][20],int m2[20][20],int r1,int c1,int r2,int c2)
{
int add[20][20];
cout<<"Matrix after multiplication :"<<endl;
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
{
add[i][j]=0;
for(int k=0;k<r2;k++)
add[i][j]+=m1[i][k]*m2[k][j];
}
for(i=0;i<r1;i++)

{
cout<<endl;
for(int j=0;j<c2;j++)
cout<<setw(4)<<add[i][j];
}
}
Output:
Enter the order of first matrix: 2 3
Enter the order of second matrix: 3 3
Enter first matrix
125
625
Enter second matrix
147
625
123
Matrix after multiplication :
18 18 32
23 38 67
Enter the order of first matrix: 3 5
Enter the order of second matrix: 6 5
Multiplication not possible

24. Program to multiply two matrices using class


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
class matrix
{
private:
int r,c,m[10][10];
public:
matrix(){}
~matrix(){}
void read()
{
cin>>r>>c;
}
void mat();
int con(matrix x, matrix y);
void mul(matrix x,matrix y);
};
int matrix::con(matrix x,matrix y)
{
return((x.c!=y.r)?0:1);
}
void matrix::mat()
{
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
cin>>m[i][j];
}
void matrix::mul(matrix x, matrix y)
{
for(int i=0;i<x.r;i++)
for(int j=0;j<y.c;j++)
{
m[i][j]=0;
for(int k=0;k<x.c;k++)
m[i][j]+=x.m[i][k]*y.m[k][j];
}
for(i=0;i<x.r;i++)
{
cout<<endl;

for(j=0;j<y.c;j++)
cout<<setw(4)<<m[i][j];
}
}
int main()
{
clrscr();
matrix m1,m2,a;
cout<<"Enter order of matrix 1 : ";
[Link]();
cout<<"Enter order of matrix 2 : ";
[Link]();
if([Link](m1,m2))
{
cout<<"Enter elements of first matrix:"<<endl;
[Link]();
cout<<"Enter elements of second matrix:"<<endl;
[Link]();
cout<<endl<<"Matrix after multiplication"<<endl;
[Link](m1,m2);
}
else
cout<<"Multiplication not possiable";
getch();
return 0;
}

Output:
Enter order of matrix 1: 3 3
Enter order of matrix 2: 3 2
Enter elements of first matrix:
245
624
351
Enter elements of second matrix:
124
325
Matrix after multiplication
28 41
22 38
25 26
Enter order of matrix 1: 2 5
Enter order of matrix 2: 2 5
Multiplication not possiable

25. Program to sort row elements in the matrix


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void sort(int a[20][20],int r,int c);
int main()
{
int m1[20][20],r,c;
clrscr();
cout<<"Enter order of the matrix : ";
cin>>r>>c;
cout<<endl<<"Enter matrix elements "<<endl;
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
cin>>m1[i][j];
cout<<endl<<"Matrix after sorting row elements"<<endl;
sort(m1,r,c);
getch();
return 0;
}
void sort(int a[20][20],int r,int c)
{
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
for(int k=j+1;k<c;k++)
if(a[i][j]>a[i][k])
{
int temp;
temp=a[i][j];
a[i][j]=a[i][k];
a[i][k]=temp;
}
for(i=0;i<r;i++)
{
cout<<endl;
for(int j=0;j<c;j++)
cout<<setw(4)<<a[i][j];
}
}

Output:
Enter order of the matrix: 3 5
Enter matrix elements
2 4 -99 6 8
6 1 0 9 -12
10 6 4 -11 9
Matrix after sorting row elements
-99 2 4 6 8
-12 0 1 6 9
-11 4 6 9 10

26. Program to sort row elements in the matrix usig class


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class mat
{
private:
int m1[20][20],r,c;
public:
mat(){}
~mat(){}
void order()
{
cin>>r>>c;
}
void read();
void sort();
void dis();
};
void mat::read()
{
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
cin>>m1[i][j];
}
void mat::sort()
{
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
for(int k=j+1;k<c;k++)
if(m1[i][j]>m1[i][k])
{
int temp;
temp=m1[i][j];
m1[i][j]=m1[i][k];
m1[i][k]=temp;
}
}
void mat::dis()
{
for(int i=0;i<r;i++)
{

cout<<endl;
for(int j=0;j<c;j++)
cout<<setw(4)<<m1[i][j];
}
}
int main()
{
clrscr();
mat m;
cout<<"Enter order of the matrix : ";
[Link]();
cout<<endl<<"Enter matrix elements "<<endl;
[Link]();
cout<<endl<<"Matrix after sorting row elements"<<endl;
[Link]();
[Link]();
getch();
return 0;
}
Output:
Enter order of the matrix : 4 3
Enter matrix elements
-99
0
4
17

4 6
8 -2
3 6
4 -52

Matrix after sorting row elements


-99
-2
3
-52

4 6
0 8
4 6
4 17

27. Program to find the transpose of a matrix, sum of principle and

secondary diagonal elements


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int m1[10][10];
void read(int,int);
void trans(int,int);
void psdiag(int);
int main()
{
int m,n;
clrscr();
cout<<"Enter order of matrix : " ;
cin>>m>>n;
cout<<endl<<"Enter matrix elements : "<<endl;
read(m,n);
cout<<endl<<"Transpose of a matrix ";
trans(m,n);
if(m==n)
psdiag(m);
else
cout<<endl<<endl<<"Not possible to find the sum of principle and
secondary diagonal.";
getch();
return 0;
}
void read(int a,int b)
{
for(int i=0;i<a;i++)
for(int j=0;j<b;j++)
cin>>m1[i][j];
}
void trans(int a,int b)
{
for(int i=0;i<b;i++)
{
cout<<endl<<endl;
for(int j=0;j<a;j++)
cout<<setw(4)<<m1[j][i];
}
}

void psdiag(int a)
{
int sum=0,j;
for(int i=0;i<a;i++)
sum+=m1[i][i];
cout<<endl<<endl<<"The sum of principal diagonal elements is = "<<sum;
sum=0;
for(i=0,j=a-1;i<a;i++,j--)
sum+=m1[i][j];
cout<<endl<<endl<<"The sum of secondary diagonal elements is =
"<<sum;
}
Output:
Enter order of matrix: 3 4
Enter matrix elements:
245
625
145
698
Transpose of a matrix
2 2 5
4 5 6
5 1 9
6 4 8
Not possible to find the sum of principle and secondary diagonal.
Enter order of matrix: 3 3
Enter matrix elements:
123
456
789
Transpose of a matrix
1 4 7
2 5 8
3 6 9
The sum of principal diagonal elements is = 15
The sum of secondary diagonal elements is = 15

28. Program to find the transpose of a matrix, sum of principle and


secondary diagonal elements using class
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class trans
{
private:
int m1[10][10],m,n;
public:
trans(){}
~trans(){}
void readord()
{
cin>>m>>n;
}
void readmat();
void tra();
void psdiag();
};
void trans::readmat()
{
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>m1[i][j];
}
void trans::tra()
{
for(int i=0;i<n;i++)
{
cout<<endl<<endl;
for(int j=0;j<m;j++)
cout<<setw(4)<<m1[j][i];
}
}
void trans::psdiag()
{
int sum=0,j;
if(m==n)
{
for(int i=0;i<m;i++)
sum+=m1[i][i];
cout<<endl<<endl<<"The sum of principal diagonal elements is =
"<<sum;
sum=0;

for(i=0,j=m-1;i<m;i++,j--)
sum+=m1[i][j];
cout<<endl<<endl<<"The sum of secondary diagonal elements is =
"<<sum;
}
else
cout<<endl<<endl<<"Not possible to find the sum of principle and
secondary diagonal.";
}
int main()
{
trans t;
clrscr();
cout<<"Enter order of matrix : " ;
[Link]();
cout<<endl<<"Enter matrix elements : "<<endl;
[Link]();
cout<<endl<<"Transpose of a matrix ";
[Link]();
[Link]();
getch();
return 0;
}

Output:
Enter order of matrix: 3 4
Enter matrix elements:
1253
1254
9258
Transpose of a matrix
1 1 9
2 2 2
5 5 5
3 4 8
Not possible to find the sum of principle and secondary diagonal.
Enter order of matrix: 4 4
Enter matrix elements:
2648
6254
6984
3165
Transpose of a matrix
2
6
4
8

6
2
5
4

6
9
8
4

3
1
6
5

The sum of principal diagonal elements is = 17


The sum of secondary diagonal elements is = 25

29. Program to find given matrix is symmetric or skew symmetric

#include<iostream.h>
#include<conio.h>
int m1[10][10];
int sym(int);
int skw(int);
int main()
{
int m,n;
clrscr();
cout<<"Enter order of matrix : " ;
cin>>m>>n;
if(m==n)
{
cout<<"Enter matrix elements : "<<endl;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>m1[i][j];
if(sym(m))
cout<<"Matrix is symmetric"<<endl;
else
if(skw(m))
cout<<"Matrix is skew symmetric"<<endl;
else
cout<<"Matrix is neither symmetric nor skew symmetric"<<endl;
}
else
cout<<"Not a square matrix";
getch();
return 0;
}
int sym(int c)
{
for(int i=0;i<c;i++)
for(int j=0;j<c;j++)
if(m1[i][j]!=m1[j][i])
return 0;
return 1;
}
int skw(int c)
{
for(int i=0;i<c;i++)
for(int j=0;j<c;j++)

if(m1[i][j]!=-m1[j][i])
return 0;
return 1;
}
Output:
Enter order of matrix: 2 4
Not a square matrix
Enter order of matrix: 4 4
Enter matrix elements:
1234
2567
3608
4789
Matrix is symmetric
Enter order of matrix: 3 3
Enter matrix elements:
0 2 -3
-2 0 4
3 -4 0
Matrix is skew symmetric
Enter order of matrix : 4 4
Enter matrix elements :
1234
6254
6548
3549
Matrix is neither symmetric nor skew symmetric

30.

Program to find given matrix is symmetric or skew symmetric using


class
#include<iostream.h>
#include<conio.h>
class sksy
{
private:
int m1[10][10],m,n;
public:
sksy(){}
~sksy(){}
int read()
{
cin>>m>>n;
return(m==n?1:0);
}
void readmat();
int sym();
int skw();
};
void sksy::readmat()
{
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
cin>>m1[i][j];
}
int sksy::sym()
{
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if(m1[i][j]!=m1[j][i])
return 0;
return 1;
}
int sksy::skw()
{
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
if(m1[i][j]!=-m1[j][i])
return 0;
return 1;
}
int main()
{

clrscr();
sksy s;
cout<<"Enter order of matrix : " ;
if([Link]())
{
cout<<"Enter matrix elements : "<<endl;
[Link]();
if([Link]())
cout<<"Matrix is symmetric"<<endl;
else
if([Link]())
cout<<"Matrix is skew symmetric"<<endl;
else
cout<<"Matrix is neither symmetric nor skew symmetric"<<endl;
}
else
cout<<"Not a square matrix";
getch();
return 0;
}

Output:
Enter order of matrix: 2 6
Not a square matrix
Enter order of matrix: 3 3
Enter matrix elements:
123
254
346
Matrix is symmetric
Enter order of matrix: 4 4
Enter matrix elements:
0 -2 3 4
2 0 -5 6
-3 5 0 7
-4 -6 -7 0
Matrix is skew symmetric
Enter order of matrix: 4 4
Enter matrix elements:
2458
6247
9248
6847
Matrix is neither symmetric nor skew symmetric

31. Program to perform addition, subtraction, multiplication and


division of two complex numbers
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<iomanip.h>
class complex
{
private:
float r,im;
public:
void read()
{
cin>>r>>im;
}
void dis();
complex add(complex);
complex sub(complex);
complex mul(complex);
complex div(complex);
};
void complex::dis()
{
if(im>0)
cout<<setw(3)<<r<<"+i"<<im;
else
cout<<setw(3)<<r<<"-i"<<fabs(im);
}
complex complex::add(complex a)
{
complex b;
b.r=r+a.r;
[Link]=im+[Link];
return (b);
}
complex complex::sub(complex a)
{
complex b;
b.r=r-a.r;
[Link]=[Link];
return (b);
}

complex complex::mul(complex a)
{
complex b;
b.r=(r*a.r)-(im*[Link]);
[Link]=(r*a.r)+(im*[Link]);
return (b);
}
complex complex::div(complex a)
{
complex b;
b.r=((r*a.r)+(im*[Link]))/((a.r*a.r)+([Link]*[Link]));
[Link]=((r*a.r)-(im*[Link]))/((a.r*a.r)+([Link]*[Link]));
return (b);
}
int main()
{
complex c1,c2,c3;
clrscr();
cout<<"Enter the real and imaginary part first complex number : ";
[Link]();
cout<<endl<<"Enter the real and imaginary part second complex number : ";
[Link]();
c3=[Link](c2);
cout<<endl<<"Addition of two complex number is :";
[Link]();
c3=[Link](c2);
cout<<endl<<endl<<"Subtration of two complex number is :";
[Link]();
c3=[Link](c2);
cout<<endl<<endl<<"Multiplication of two complex number is :";
[Link]();
c3=[Link](c2);
cout<<endl<<endl<<"Division of two complex number is :";
[Link]();
getch();
return 0;
}

Output:
Enter the real and imaginary part first complex number: 3 4
Enter the real and imaginary part second complex number: 2 9
Addition of two complex number is: 5+i13
Subtration of two complex number is: 1-i5
Multiplication of two complex number is:-30+i42
Division of two complex number is: 0.494118-i0.352941

32. Program to perform addition, subtraction, multiplication and


division of two complex numbers using operator overloading
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<iomanip.h>
class complex
{
private:
float r,im;
public:
void read()
{
cin>>r>>im;
}
void dis();
complex operator+(complex);
complex operator-(complex);
complex operator*(complex);
complex operator/(complex);
};
void complex::dis()
{
if(im>0)
cout<<setw(3)<<r<<"+i"<<im;
else
cout<<setw(3)<<r<<"-i"<<fabs(im);
}
complex complex::operator+(complex a)
{
complex b;
b.r=r+a.r;
[Link]=im+[Link];
return (b);
}
complex complex::operator-(complex a)
{
complex b;
b.r=r-a.r;
[Link]=[Link];
return (b);
}

complex complex::operator*(complex a)
{
complex b;
b.r=(r*a.r)-(im*[Link]);
[Link]=(r*a.r)+(im*[Link]);
return (b);
}
complex complex::operator/(complex a)
{
complex b;
b.r=((r*a.r)+(im*[Link]))/((a.r*a.r)+([Link]*[Link]));
[Link]=((r*a.r)-(im*[Link]))/((a.r*a.r)+([Link]*[Link]));
return (b);
}
int main()
{
complex c1,c2,c3;
clrscr();
cout<<"Enter the real and imaginary part first complex number : ";
[Link]();
cout<<endl<<"Enter the real and imaginary part second complex number : ";
[Link]();
c3=c1+c2;
cout<<endl<<"Addition of two complex number is :";
[Link]();
c3=c1-c2;
cout<<endl<<endl<<"Subtration of two complex number is :";
[Link]();
c3=c1*c2;
cout<<endl<<endl<<"Multiplication of two complex number is :";
[Link]();
c3=c1/c2;
cout<<endl<<endl<<"Division of two complex number is :";
[Link]();
getch();
return 0;
}

Output:
Enter the real and imaginary part first complex number: 5 -7
Enter the real and imaginary part second complex number: 2 6
Addition of two complex number is: 7-i1
Subtration of two complex number is: 3-i13
Multiplication of two complex number is: 52-i32
Division of two complex number is:-0.8+i1.3

33. Program to perform addition and subtraction of two times


#include<iostream.h>
#include<conio.h>
#include<math.h>
class time
{
private:
int hr,mi,se,m,n;
public:
void read();
void dis();
time add(time);
time sub(time);
};
void time::read()
{
cin>>hr>>mi>>se;
}
void time::dis()
{
cout<<hr<<":"<<mi<<":"<<se;
}
time time::add(time t2)
{
time t;
m=se+[Link];
n=mi+[Link]+m/60;
[Link]=m%60;
[Link]=n%60;
[Link]=(hr+[Link]+n/60);
return(t);
}
time time::sub(time t2)
{
time t;
int p;
m=se+(hr*60*60)+(mi*60);
n=[Link]+([Link]*60*60)+([Link]*60);
p=abs(m-n);
[Link]=p%60;
[Link]=(p%3600)/60;

[Link]=(p/3600);
return(t);
}
int main()
{
time t1,t2,t3;
clrscr();
cout<<"Enter the first time in hr:min:sec = ";
[Link]();
cout<<endl<<"Enter the second time in hr:min:sec = ";
[Link]();
t3=[Link](t2);
cout<<endl<<"Addition of two times in hr:min:sec = ";
[Link]();
t3=[Link](t2);
cout<<endl<<"Difference of two times in hr:min:sec = ";
[Link]();
getch();
return 0;
}
Output:
Enter the first time in hr: min: sec = 5 23 41
Enter the second time in hr: min: sec = 2 12 28
Addition of two times in hr: min: sec = 7:36:9
Difference of two times in hr: min: sec = 3:11:13

34.

Program to perform addition and subtraction of two times operator


overloading
#include<iostream.h>
#include<conio.h>
#include<math.h>
class time
{
private:
int hr,mi,se,m,n;
public:
void read();
void dis();
friend time operator+(time,time);
friend time operator-(time,time);
};
void time::read()
{
cin>>hr>>mi>>se;
}
void time::dis()
{
cout<<hr<<":"<<mi<<":"<<se;
}
time operator+(time t1,time t2)
{
int m,n;
time t;
m=[Link]+[Link];
n=[Link]+[Link]+m/60;
[Link]=m%60;
[Link]=n%60;
[Link]=([Link]+[Link]+n/60);
return(t);
}
time operator-(time t1,time t2)
{
time t;
int p,m,n;
m=[Link]+([Link]*60*60)+([Link]*60);
n=[Link]+([Link]*60*60)+([Link]*60);
p=abs(m-n);

[Link]=p%60;
[Link]=(p%3600)/60;
[Link]=(p/3600);
return(t);
}
int main()
{
time t1,t2,t3;
clrscr();
cout<<"Enter the first time in hr:min:sec = ";
[Link]();
cout<<endl<<"Enter the second time in hr:min:sec = ";
[Link]();
t3=t1+t2;
cout<<endl<<"Addition of two times in hr:min:sec = ";
[Link]();
t3=t1-t2;
cout<<endl<<"Difference of two times in hr:min:sec = ";
[Link]();
getch();
return 0;
}
Output:
Enter the first time in hr: min: sec = 9 48 52
Enter the second time in hr: min: sec = 6 21 36
Addition of two times in hr: min: sec = 16:10:28
Difference of two times in hr: min: sec = 3:27:16

35. Program to perform handling of student record


#include<iostream.h>
#include <stdlib.h>
#include<conio.h>
#include <ctype.h>
#include <string.h>
void read();
void dis_rec();
class student
{
private:
char name[20];
int rol_no,tot,sub[4];
public:
student(){}
~student(){}
void read_rec();
void dis_data(int);
int operator==(char c[]);
int operator==(int);
int operator>(student);
int operator<(student);
};
int student::operator==(char c[])
{
return(strcmp(name,c)==0?1:0);
}
int student::operator==(int t)
{
return((rol_no==t)?1:0);
}
int student::operator>(student k)
{
return((strcmp(name,[Link])>0)?1:0);
}
int student::operator<(student k)
{
return((tot<[Link])?1:0);
}

void student::read_rec()
{
read();
gotoxy(35,10);cin>>name;
name[0]=toupper(name[0]);
gotoxy(35,11);cin>>rol_no;
gotoxy(35,12);cin>>sub[0];
gotoxy(35,13);cin>>sub[1];
gotoxy(35,14);cin>>sub[2];
tot=sub[0]+sub[1]+sub[2];
gotoxy(35,15);cout<<tot;
}
void line(int k)
{
for(int i=0;i<k;i++)
cout<<"-";
}
int menu()
{
int k;
clrscr();
gotoxy(20,2);line(35);
gotoxy(28,4);cout<<" STUDENT RECORD ";
gotoxy(20,6);line(35);
gotoxy(22,8);cout<<"1 Create record";
gotoxy(22,9);cout<<"2 Display all record";
gotoxy(22,10);cout<<"3 Sort by name";
gotoxy(22,11);cout<<"4 Sort by total marks";
gotoxy(22,12);cout<<"5 Add record";
gotoxy(22,13);cout<<"6 Edit record";
gotoxy(22,14);cout<<"7 Search record by roll number";
gotoxy(22,15);cout<<"8 Search record by name";
gotoxy(22,16);cout<<"9 Delete record ";
gotoxy(21,17);cout<<"10 Exit";
gotoxy(20,19);line(35);
gotoxy(22,21);cout<<"Enter your choice : ";
cin>>k;
return (k);
}
void read()
{
gotoxy(20,8);line(35);

gotoxy(22,10);cout<<"Name
: ";
gotoxy(22,11);cout<<"Roll number : ";
gotoxy(22,12);cout<<"Subject 1 : ";
gotoxy(22,13);cout<<"Subject 2 : ";
gotoxy(22,14);cout<<"Subject 3 : ";
gotoxy(22,15);cout<<"Total
:";
gotoxy(20,17);line(35);
}
void dis_rec()
{
gotoxy(2,2);line(78);
gotoxy(4,4);cout<<"Rollno.";
gotoxy(16,4);cout<<"Name";
gotoxy(34,4);cout<<"Sub1";
gotoxy(44,4);cout<<"Sub2";
gotoxy(54,4);cout<<"Sub3";
gotoxy(64,4);cout<<"Total";
gotoxy(2,6);line(78);
}
void student::dis_data(int i)
{
gotoxy(7,8+i);cout<<rol_no;
gotoxy(17,8+i);cout<<name;
gotoxy(35,8+i);cout<<sub[0];
gotoxy(45,8+i);cout<<sub[1];
gotoxy(55,8+i);cout<<sub[2];
gotoxy(65,8+i);cout<<tot;
}
int main()
{
clrscr();
student st[10];
int n=0;
for(;;)
{
switch(menu())
{
case 1:clrscr();
gotoxy(22,12);cout<<"Enter the number of student : ";
cin>>n;
for(int i=0;i<n;i++)
{
clrscr();

gotoxy(22,6);cout<<"Enter the record of student "<<i+1;


st[i].read_rec();
gotoxy(22,19);cout<<"Press any key to cont.... ";
getch();
}
break;
case 2:clrscr();
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
dis_rec();
for(int k=0;k<n;k++)
st[k].dis_data(k);
gotoxy(2,9+k);line(78);
gotoxy(22,11+k);cout<<"Press any key to cont.... ";
getch();
break;
case 3:clrscr();
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
dis_rec();
for(k=0;k<n;k++)
for(int j=k+1;j<n;j++)
{
student s;
if(st[k]>st[j])
{
s=st[k];
st[k]=st[j];
st[j]=s;
}
}
for(k=0;k<n;k++)

st[k].dis_data(k);
gotoxy(2,9+k);line(78);
gotoxy(22,11+k);cout<<"Press any key to cont.... ";
getch();
break;
case 4:clrscr();
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
dis_rec();
for(k=0;k<n;k++)
for(j=k+1;j<n;j++)
{
student s;
if(st[k]<st[j])
{
s=st[k];
st[k]=st[j];
st[j]=s;
}
}
for(k=0;k<n;k++)
st[k].dis_data(k);
gotoxy(2,9+k);line(78);
gotoxy(22,11+k);cout<<"Press any key to cont.... ";
getch();
break;
case 5: clrscr();
for(i=n;;i++)
{
clrscr();
char s;
n++;
gotoxy(22,6);cout<<"Enter the record of student "<<i+1;
st[i].read_rec();
gotoxy(22,19);cout<<"Do you want to add one more
record(y/n):";
cin>>s;
if(s=='n')

break;
gotoxy(22,20);cout<<"Press any key to cont.... ";
getch();
}
break;
case 6:clrscr();
char name1[15],r;
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
gotoxy(22,6);cout<<"Enter the name of the student:";
cin>>name1;
name1[0]=toupper(name1[0]);
for(i=0;i<n;i++)
if(st[i]==name1)
{
clrscr();
dis_rec();
st[i].dis_data(0);
gotoxy(2,10);line(78);
gotoxy(22,12);cout<<"Do you want to edit this record?(y/n):";
cin>>r;
if(r=='y')
{
clrscr();
gotoxy(22,6);cout<<"Enter the record of student
"<<name1;
st[i].read_rec();
gotoxy(22,19);cout<<"Press any key to cont.... ";
getch();
break;
}
if(r=='n')
break;
}
if(i==n)
{
clrscr();
gotoxy(22,12);cout<<"The record is not found";
gotoxy(22,14);cout<<"Press any key to continue...";

getch();
break;
}
break;
case 7:clrscr();
int m;
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
gotoxy(22,12);cout<<"Enter the rollno of the student:";
cin>>m;
for(i=0;i<n;i++)
if(st[i]==m)
{
clrscr();
dis_rec();
k=0;
st[i].dis_data(k);
gotoxy(2,10);line(78);
gotoxy(22,14);cout<<"Press any key to cont.... ";
getch();
break;
}
if(i==n)
{
clrscr();
gotoxy(22,12);cout<<"The record is not found";
gotoxy(22,14);cout<<"Press any key to continue...";
getch();
break;
}
break;
case 8:clrscr();
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;

}
else
gotoxy(22,12);cout<<"Enter the name of the student:";
cin>>name1;
name1[0]=toupper(name1[0]);
for(i=0;i<n;i++)
if(st[i]==name1)
{
clrscr();
dis_rec();
k=0;
st[i].dis_data(k);
gotoxy(2,10);line(78);
gotoxy(22,14);cout<<"Press any key to cont.... ";
getch();
break;
}
if(i==n)
{
clrscr();
gotoxy(22,12);cout<<"The record is not found";
gotoxy(22,14);cout<<"Press any key to continue...";
getch();
break;
}
break;
case 9:clrscr();
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
gotoxy(22,12);cout<<"Enter the name of the student:";
cin>>name1;
name1[0]=toupper(name1[0]);
for(i=0;i<n;i++)
if(st[i]==name1)
{
clrscr();
dis_rec();
k=0;
st[i].dis_data(k);

gotoxy(2,10);line(78);
gotoxy(22,15);cout<<"Do you want to delete this record?
(y/n):";
cin>>r;
if(r=='y')
{
clrscr();
for(k=i;k<n;k++)
// if((k+1)<n)
st[k]=st[k+1];
n--; i--;
gotoxy(22,10);cout<<"The record is deleted "<<name1;
gotoxy(22,14);cout<<"Press any key to cont.... ";
getch();
break;
}
if(r=='n')
break;
}
if(i==n)
{
clrscr();
gotoxy(22,12);cout<<"The record is not found";
gotoxy(22,14);cout<<"Press any key to continue...";
getch();
break;
}
break;
case 10: exit(0);
default:
gotoxy(22,38); cout<<"Enter correct choice between 1 to 10";
gotoxy(22,40); cout<<"Press any key to continue";
break;
}
}
return (0);
}

Output:
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
---------------------------------------Enter your choice: 1
Enter the number of student: 3
Enter the record of student 1
--------------------------------------------------Name
: manjesh
Roll number: 1
Subject 1 :19
Subject 2 :12
Subject 3 :15
Total
:46
--------------------------------------------------Press any key to cont....
Enter the record of student 2
--------------------------------------------------Name
: soma
Roll number: 2
Subject 1 :21
Subject 2 :10
Subject 3 :13
Total
: 44
--------------------------------------------------Press any key to cont....

Enter the record of student 3


--------------------------------------------------Name
: dilip
Roll number: 3
Subject 1 :10
Subject 2 :10
Subject 3 :10
Total
: 30
--------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
---------------------------------------Enter your choice: 2
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjesh
19
12
15
46
2
Soma
21
10
13
44
3
Dilip
10
10
10
30
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record

6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
--------------------------------------------------Enter your choice : 3
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------3
Dilip
10
10
10
30
1
Manjesh
19
12
15
46
2
Soma
21
10
13
44
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
--------------------------------------------------Enter your choice: 4
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjesh
19
12
15
46
2
Soma
21
10
13
44
3
Dilip
10
10
10
30
-----------------------------------------------------------------------------Press any key to cont....

--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
---------------------------------------Enter your choice : 5
Enter the record of student 4
--------------------------------------------------Name
: nagaraju
Roll number: 4
Subject 1 :12
Subject 2 :12
Subject 3 :12
Total
: 36
--------------------------------------------------Do you want to add one more record(y/n): y
Enter the record of student 5
--------------------------------------------------Name
: manju
Roll number: 5
Subject 1 :11
Subject 2 :11
Subject 3 :11
Total
: 33
--------------------------------------------------Do you want to add one more record(y/n): n
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjesh
19
12
15
46
2
Soma
21
10
13
44
3
Dilip
10
10
10
30
4
Nagaraj
12
12
12
36
5
Manju
11
11
11
33
------------------------------------------------------------------------------

Press any key to cont....


--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
--------------------------------------------------Enter your choice : 6
Enter the name of the student: manjesh
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjesh
19
12
15
46
-----------------------------------------------------------------------------Do you want to edit this record?(y/n):y
Enter the record of student Manjesh
--------------------------------------------------Name
: manjeshkumar
Roll number: 1
Subject 1 :20
Subject 2 :20
Subject 3 :20
Total
: 60
--------------------------------------------------Press any key to cont....
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjeshkumar 20
20
20
60
2
Soma
21
10
13
44
3
Dilip
10
10
10
30

4
Nagaraj
12
12
12
36
5
Manju
11
11
11
33
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
--------------------------------------------------Enter your choice: 7
Enter the rollno of the student: 4
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------4
Nagaraj
12
12
12
36
-----------------------------------------------------------------------------Press any key to cont....
Enter the rollno of the student:9
The record is not found
Press any key to continue...
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record

7 Search record by roll number


8 Search record by name
9 Delete record
10 Exit
--------------------------------------------------Enter your choice : 8
Enter the name of the student:dilip
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------3
Dilip
10
10
10
30
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
---------------------------------------Enter your choice : 9
Enter the name of the student: dilip
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------3
Dilip
10
10
10
30
-----------------------------------------------------------------------------Do you want to delete this record? (y/n):y
The record Dilip is deleted
Press any key to cont....
------------------------------------------------------------------------------

Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjeshkumar 20
20
20
60
2
Soma
21
10
13
44
4
Nagaraj
12
12
12
36
5
Manju
11
11
11
33
-----------------------------------------------------------------------------Press any key to cont....
Enter the name of the student:soma
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------2
Soma
21
10
13
44
-----------------------------------------------------------------------------Do you want to delete this record?(y/n):n
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjeshkumar 20
20
20
60
2
Soma
21
10
13
44
4
Nagaraj
12
12
12
36
5
Manju
11
11
11
33
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
----------------------------------------------------Enter your choice : 10
36. Program to perform handling of student record using inheritance

#include<iostream.h>
#include <stdlib.h>
#include<conio.h>
#include <ctype.h>
#include <string.h>
void read();
void dis_rec();
class record
{
protected:
int rol_no,tot,sub[4];
char name[20];
public:
record(){}
~record(){}
void read_rec();
void dis_data(int);
};
class student:public record
{
public:
student(){}
~student(){}
int operator==(char c[]);
int operator==(int);
int operator>(student);
int operator<(student);
};
int student::operator==(char c[])
{
return(strcmp(name,c)==0?1:0);
}
int student::operator==(int t)
{
return((rol_no==t)?1:0);
}
int student::operator>(student k)
{
return((strcmp(name,[Link])>0)?1:0);
}

int student::operator<(student k)
{
return((tot<[Link])?1:0);
}
void record::read_rec()
{
read();
gotoxy(35,10);cin>>name;
name[0]=toupper(name[0]);
gotoxy(35,11);cin>>rol_no;
gotoxy(35,12);cin>>sub[0];
gotoxy(35,13);cin>>sub[1];
gotoxy(35,14);cin>>sub[2];
tot=sub[0]+sub[1]+sub[2];
gotoxy(35,15);cout<<tot;
}
void line(int k)
{
for(int i=0;i<k;i++)
cout<<"-";
}
int menu()
{
int k;
clrscr();
gotoxy(20,2);line(35);
gotoxy(28,4);cout<<" STUDENT RECORD ";
gotoxy(20,6);line(35);
gotoxy(22,8);cout<<"1 Create record";
gotoxy(22,9);cout<<"2 Display all record";
gotoxy(22,10);cout<<"3 Sort by name";
gotoxy(22,11);cout<<"4 Sort by total marks";
gotoxy(22,12);cout<<"5 Add record";
gotoxy(22,13);cout<<"6 Edit record";
gotoxy(22,14);cout<<"7 Search record by roll number";
gotoxy(22,15);cout<<"8 Search record by name";
gotoxy(22,16);cout<<"9 Delete record ";
gotoxy(21,17);cout<<"10 Exit";
gotoxy(20,19);line(35);
gotoxy(22,21);cout<<"Enter your choice : ";
cin>>k;
return (k);

}
void read()
{
gotoxy(20,8);line(35);
gotoxy(22,10);cout<<"Name
: ";
gotoxy(22,11);cout<<"Roll number : ";
gotoxy(22,12);cout<<"Subject 1 : ";
gotoxy(22,13);cout<<"Subject 2 : ";
gotoxy(22,14);cout<<"Subject 3 : ";
gotoxy(22,15);cout<<"Total
:";
gotoxy(20,17);line(35);
}
void dis_rec()
{
gotoxy(2,2);line(78);
gotoxy(4,4);cout<<"Rollno.";
gotoxy(16,4);cout<<"Name";
gotoxy(34,4);cout<<"Sub1";
gotoxy(44,4);cout<<"Sub2";
gotoxy(54,4);cout<<"Sub3";
gotoxy(64,4);cout<<"Total";
gotoxy(2,6);line(78);
}
void record::dis_data(int i)
{
gotoxy(7,8+i);cout<<rol_no;
gotoxy(17,8+i);cout<<name;
gotoxy(35,8+i);cout<<sub[0];
gotoxy(45,8+i);cout<<sub[1];
gotoxy(55,8+i);cout<<sub[2];
gotoxy(65,8+i);cout<<tot;
}
int main()
{
clrscr();
student st[10];
int n=0;
for(;;)
{
switch(menu())
{
case 1:clrscr();

gotoxy(22,12);cout<<"Enter the number of student : ";


cin>>n;
for(int i=0;i<n;i++)
{
clrscr();
gotoxy(22,6);cout<<"Enter the record of student "<<i+1;
st[i].read_rec();
gotoxy(22,19);cout<<"Press any key to cont.... ";
getch();
}
break;
case 2:clrscr();
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
dis_rec();
for(int k=0;k<n;k++)
st[k].dis_data(k);
gotoxy(2,9+k);line(78);
gotoxy(22,11+k);cout<<"Press any key to cont.... ";
getch();
break;
case 3:clrscr();
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
dis_rec();
for(k=0;k<n;k++)
for(int j=k+1;j<n;j++)
{
student s;
if(st[k]>st[j])
{
s=st[k];

st[k]=st[j];
st[j]=s;
}
}
for(k=0;k<n;k++)
st[k].dis_data(k);
gotoxy(2,9+k);line(78);
gotoxy(22,11+k);cout<<"Press any key to cont.... ";
getch();
break;
case 4:clrscr();
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
dis_rec();
for(k=0;k<n;k++)
for(j=k+1;j<n;j++)
{
student s;
if(st[k]<st[j])
{
s=st[k];
st[k]=st[j];
st[j]=s;
}
}
for(k=0;k<n;k++)
st[k].dis_data(k);
gotoxy(2,9+k);line(78);
gotoxy(22,11+k);cout<<"Press any key to cont.... ";
getch();
break;
case 5: clrscr();
for(i=n;;i++)
{
clrscr();
char s;
n++;

gotoxy(22,6);cout<<"Enter the record of student "<<i+1;


st[i].read_rec();
gotoxy(22,19);cout<<"Do you want to add one more
record(y/n):";
cin>>s;
if(s=='n')
break;
gotoxy(22,20);cout<<"Press any key to cont.... ";
getch();
}
break;
case 6:clrscr();
char name1[15],r;
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
gotoxy(22,6);cout<<"Enter the name of the student:";
cin>>name1;
name1[0]=toupper(name1[0]);
for(i=0;i<n;i++)
if(st[i]==name1)
{
clrscr();
dis_rec();
st[i].dis_data(0);
gotoxy(2,10);line(78);
gotoxy(22,12);cout<<"Do you want to edit this record?(y/n):";
cin>>r;
if(r=='y')
{
clrscr();
gotoxy(22,6);cout<<"Enter the record of student
"<<name1;
st[i].read_rec();
gotoxy(22,19);cout<<"Press any key to cont.... ";
getch();
break;
}
if(r=='n')
break;

}
if(i==n)
{
clrscr();
gotoxy(22,12);cout<<"The record is not found";
gotoxy(22,14);cout<<"Press any key to continue...";
getch();
break;
}
break;
case 7:clrscr();
int m;
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
gotoxy(22,12);cout<<"Enter the rollno of the student:";
cin>>m;
for(i=0;i<n;i++)
if(st[i]==m)
{
clrscr();
dis_rec();
k=0;
st[i].dis_data(k);
gotoxy(2,10);line(78);
gotoxy(22,14);cout<<"Press any key to cont.... ";
getch();
break;
}
if(i==n)
{
clrscr();
gotoxy(22,12);cout<<"The record is not found";
gotoxy(22,14);cout<<"Press any key to continue...";
getch();
break;
}
break;
case 8:clrscr();

if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
gotoxy(22,12);cout<<"Enter the name of the student:";
cin>>name1;
name1[0]=toupper(name1[0]);
for(i=0;i<n;i++)
if(st[i]==name1)
{
clrscr();
dis_rec();
k=0;
st[i].dis_data(k);
gotoxy(2,10);line(78);
gotoxy(22,14);cout<<"Press any key to cont.... ";
getch();
break;
}
if(i==n)
{
clrscr();
gotoxy(22,12);cout<<"The record is not found";
gotoxy(22,14);cout<<"Press any key to continue...";
getch();
break;
}
break;
case 9:clrscr();
if(n==0)
{
gotoxy(22,12);cout<<"No record found"<<endl;
gotoxy(22,14);cout<<"Press any key to continue... ";
getch();
break;
}
else
gotoxy(22,12);cout<<"Enter the name of the student:";
cin>>name1;
name1[0]=toupper(name1[0]);
for(i=0;i<n;i++)

if(st[i]==name1)
{
clrscr();
dis_rec();
k=0;
st[i].dis_data(k);
gotoxy(2,10);line(78);
gotoxy(22,15);cout<<"Do you want to delete this record?
(y/n):";
cin>>r;
if(r=='y')
{
clrscr();
for(k=i;k<n;k++)
// if((k+1)<n)
st[k]=st[k+1];
n--; i--;
gotoxy(22,10);cout<<"The record is deleted "<<name1;
gotoxy(22,14);cout<<"Press any key to cont.... ";
getch();
break;
}
if(r=='n')
break;
}
if(i==n)
{
clrscr();
gotoxy(22,12);cout<<"The record is not found";
gotoxy(22,14);cout<<"Press any key to continue...";
getch();
break;
}
break;
case 10: exit(0);
default:
gotoxy(22,38); cout<<"Enter correct choice between 1 to 10";
gotoxy(22,40); cout<<"Press any key to continue";
break;
}
}
return (0);
}
Output:

--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
---------------------------------------Enter your choice: 1
Enter the number of student: 3
Enter the record of student 1
--------------------------------------------------Name
: manjesh
Roll number: 1
Subject 1 :19
Subject 2 :12
Subject 3 :15
Total
:46
--------------------------------------------------Press any key to cont....
Enter the record of student 2
--------------------------------------------------Name
: soma
Roll number: 2
Subject 1 :21
Subject 2 :10
Subject 3 :13
Total
: 44
--------------------------------------------------Press any key to cont....

Enter the record of student 3

--------------------------------------------------Name
: dilip
Roll number: 3
Subject 1 :10
Subject 2 :10
Subject 3 :10
Total
: 30
--------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
---------------------------------------Enter your choice: 2
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjesh
19
12
15
46
2
Soma
21
10
13
44
3
Dilip
10
10
10
30
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record

7 Search record by roll number


8 Search record by name
9 Delete record
10 Exit
--------------------------------------------------Enter your choice : 3
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------3
Dilip
10
10
10
30
1
Manjesh
19
12
15
46
2
Soma
21
10
13
44
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
--------------------------------------------------Enter your choice: 4
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjesh
19
12
15
46
2
Soma
21
10
13
44
3
Dilip
10
10
10
30
-----------------------------------------------------------------------------Press any key to cont....

---------------------------------------------------

STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
---------------------------------------Enter your choice : 5
Enter the record of student 4
--------------------------------------------------Name
: nagaraju
Roll number: 4
Subject 1 :12
Subject 2 :12
Subject 3 :12
Total
: 36
--------------------------------------------------Do you want to add one more record(y/n): y
Enter the record of student 5
--------------------------------------------------Name
: manju
Roll number: 5
Subject 1 :11
Subject 2 :11
Subject 3 :11
Total
: 33
--------------------------------------------------Do you want to add one more record(y/n): n
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjesh
19
12
15
46
2
Soma
21
10
13
44
3
Dilip
10
10
10
30
4
Nagaraj
12
12
12
36
5
Manju
11
11
11
33
-----------------------------------------------------------------------------Press any key to cont....

--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
--------------------------------------------------Enter your choice : 6
Enter the name of the student: manjesh
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjesh
19
12
15
46
-----------------------------------------------------------------------------Do you want to edit this record?(y/n):y
Enter the record of student Manjesh
--------------------------------------------------Name
: manjeshkumar
Roll number: 1
Subject 1 :20
Subject 2 :20
Subject 3 :20
Total
: 60
--------------------------------------------------Press any key to cont....
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjeshkumar 20
20
20
60
2
Soma
21
10
13
44
3
Dilip
10
10
10
30
4
Nagaraj
12
12
12
36

5
Manju
11
11
11
33
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
--------------------------------------------------Enter your choice: 7
Enter the rollno of the student: 4
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------4
Nagaraj
12
12
12
36
-----------------------------------------------------------------------------Press any key to cont....
Enter the rollno of the student:9
The record is not found
Press any key to continue...
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number

8 Search record by name


9 Delete record
10 Exit
--------------------------------------------------Enter your choice : 8
Enter the name of the student:dilip
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------3
Dilip
10
10
10
30
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
---------------------------------------Enter your choice : 9
Enter the name of the student: dilip
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------3
Dilip
10
10
10
30
-----------------------------------------------------------------------------Do you want to delete this record? (y/n):y
The record Dilip is deleted
Press any key to cont....
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total

-----------------------------------------------------------------------------1
Manjeshkumar 20
20
20
60
2
Soma
21
10
13
44
4
Nagaraj
12
12
12
36
5
Manju
11
11
11
33
-----------------------------------------------------------------------------Press any key to cont....
Enter the name of the student:soma
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------2
Soma
21
10
13
44
-----------------------------------------------------------------------------Do you want to delete this record?(y/n):n
-----------------------------------------------------------------------------Rollno. Name
Sub1
Sub2
Sub3
Total
-----------------------------------------------------------------------------1
Manjeshkumar 20
20
20
60
2
Soma
21
10
13
44
4
Nagaraj
12
12
12
36
5
Manju
11
11
11
33
-----------------------------------------------------------------------------Press any key to cont....
--------------------------------------------------STUDENT RECORD
--------------------------------------------------1 Create record
2 Display all record
3 Sort by name
4 Sort by total marks
5 Add record
6 Edit record
7 Search record by roll number
8 Search record by name
9 Delete record
10 Exit
----------------------------------------------------Enter your choice : 10

You might also like