Professional Documents
Culture Documents
A PALINDROME OR NOT.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char a[100],ch;
int l,i,j=0;
do
{
cout<<"\n Enter a string:";
gets(a);
l=strlen(a);
for(i=0;i<l;i++)
{
if(a[i]!=a[l-1-i])
{
j=1;
break;
}
}
if(j==0)
{
cout<<"\n PALINDROME";
}
else
{
cout<<"\n NOT PALINDROME";
}
cout<<"\n Do u want to Enter more strings(Y/N):";
cin>>ch;
if(ch=='n'||ch=='N')
{
cout<<"ABORTING....";
getch();
} }
while(ch=='Y'||ch=='y');
getch();
}
QUESTION : ANSWER THE QUESTIONS (I) TO (IV)
BASED ON THE FOLLOWING:
class PRODUCT
{
int Code;
char Item[20];
protected:
float Qty;
public: PRODUCT();
void GetIn();
void Show();
};
class WHOLESALER
{ int WCode;
protected:
char Manager[20];
public:
WHOLESALER();
void Enter();
void Display();
};
class SHOWROOM : public PRODUCT, private
WHOLESALER
{
char Name[20],City[20];
public: SHOWROOM();
void Input();
void View();
};
CODING
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int l,i,j,k=0,a[100],z[50],c=0,t[50],d=0;
cout<<"\n Enter array limit: ";
cin>>l;
cout<<"\n Enter numbers in the array:\n";
for(i=0;i<l;i++)
cin>>a[i];
for(i=0;i<l;i++)
{
for(j=0;j<l;j++)
{
if(a[i]==a[j])
k++;
}
if(k>1)
{
z[c]=a[i];
c++;
}
k=0;
}
for(i=0;i<l;i++)
{
for(j=0;j<c;j++)
{
if(a[i]==z[j])
a[i]=0;
}
}
for(i=0;i<l;i++)
{
if(a[i]==0)
{
t[d]=a[i];
d++;
}
}
for(i=0;i<l;i++)
{
if(a[i]!=0)
{
t[d]=a[i];
d++;
}
}
cout<<"\n";
cout<<"The result is :";
for(i=0;i<d;i++)
{
cout<<t[i]<<" ";
}
getch();
}
QUESTION : PROGRAM ON MATRIX
#include <iostream.h>
#include <conio.h>
#include <process.h>
#include <stdio.h>
class Aninda
{
private:
int a[10][10],b[10][10],c[10][10],m,n,o,p,i,j,k;
public:
void matrix()
{
cout<<"\n enter the rows and columns of 1st matrix:";
cin>>m>>n;
cout<<"\n enter the rows and columns of 2nd matrix:";
cin>>o>>p;
if(m==o && n==p)
{
cout<<"\n congrats... sum,difference,products of matrix is
possible...\n ";
}
else
{
cout<<"\n alas... sum,difference,products of matrix is not
possible...\n start again...";
exit(0);
}
cout<<"enter the elements of 1st "<<m<<" * "<<n<<"
matrix..\n";
for( i=0;i<m;i++)
{
for( j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"enter the elements of 2nd "<<o<<" * "<<p<<"
matrix..\n";
for( i=0;i<o;i++)
{
for(j=0;j<p;j++)
{
cin>>b[i][j] ;
}
}
}
void sum()
{
for( i=0;i<m;i++)
{
for( j=0;j<n;j++)
{
c[i][j]=(a[i][j]+b[i][j]);
}
}
cout<<"\n the sum of matrices is :\n";
for( i=0;i<m;i++)
{
for( j=0;j<n;j++)
{
cout<<c[i][j]<<" ";
}
cout<<endl;
}
}
void difference()
{
for( i=0;i<m;i++)
{
for( j=0;j<n;j++)
{
c[i][j]=a[i][j]-b[i][j];
}
}
cout<<"\n the differences of matrices is :\n";
for( i=0;i<m;i++)
{
for( j=0;j<n;j++)
{
cout<<c[i][j]<<" ";
}
cout<<endl;
}
}
void product()
{
if(n==p)
{
cout<<"\n Matrices can be multiplied.";
}
else
{
cout<<"\n Matrices cannot be multiplied...";
cout<<"starting again...press any key..";
getch();
product();
}
for(i=0;i<m;i++)
{
for(j=0;j<p;j++)
{
c[i][j]=0;
for( k=0;k<n;k++)
{
c[i][j]+=(a[i][k]*b[k][j]);
}
}
}
cout<<"\n the product of matrices is :\n";
for( i=0;i<m;i++)
{
for( j=0;j<p;j++)
{
cout<<c[i][j]<<" ";
}
cout<<endl;
}
}
void rowcolumn()
{ int s,s1;
cout<<"FOR MATRIX 1..\n" ;
for(i=0;i<m;i++)
{
s=0;
for(j=0;j<n;j++)
{
s=s+a[i][j];
}
cout<<"\n Sum of row"<<(i+1)<<"is:"<<s;
}
cout<<"\n \n FOR MATRIX 2..\n" ;
for(i=0;i<o;i++)
{
s1=0;
for( j=0;j<p;j++)
{
s1=s1+b[i][j];
}
cout<<"\n Sum of row"<<(i+1)<<"is:"<<s1;
}
}
};
void main()
{
int g ;
Aninda R;
cout<<" \n \n ....MATRIX OPERATION MENU.....\t \t " ;
while(1)
{
cout<<"\n 1.Sum of two matrices..";
cout<<"\n 2.Differences of matrices...";
cout<<"\n 3.Product of matrices..";
cout<<"\n 4.Row sum and column sum...";
cout<<"\n 5.Press 5 to exit...";
cout<<"\n Enter your choice...:";
cin>>g;
switch(g)
{
case 1: R.matrix();
R.sum();
break;
case 2: R.matrix();
R.difference() ;
break;
case 3: R.matrix();
R.product();
break;
case 4: R.matrix();
R.rowcolumn();
break;
case 5: exit(0);
break;