You are on page 1of 26

QUESTION: TO CHECK WHETHER A GIVEN STRING IS

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();
};

(i) Which type of Inheritance out of the following


is illustrated in the above example?
-Single Level Inheritance
- Multi Level Inheritance
- Multiple Inheritance
Ans. Multiple Inheritance

(ii) Write the names of all the data members,


which are directly accessible from the
member functions of class SHOWROOM.
Ans. Name, City, Manager.
(iii) Write the names of all the member
functions, which are directly accessible by
an object of class SHOWROOM.
Ans. Input(), View(), GetIn(), Show()

(iv) What will be the order of execution of


the constructors, when an object of class
SHOWROOM is declared?
Ans. (i) PRODUCT() (ii) WHOLESALER()
(iii)SHOWROOM()
QUESTION: Observe the following STUDENTS
and EVENTS tables carefully and write
the name of the RDBMS operation
which will be used to produce
the output as shown in LIST? Also, find
the Degree and Cardinality of the LIST.

Ans) Cartesian Product


Degree=4 Cardinality =6
(b). Write SQL queries for (i) to (iv) and find
outputs for SQLqueries (v) to (viii), which are
based on the tables

Note: • PERKM is Freight Charges per kilometer


• VTYPE is Vehicle Type

Note: •NO is Traveler Number


• KM is Kilometer travelled
• NOP is number of traveler travelled in
vehicle
•TDATE is Travel Date
(i). To display NO,NAME, TDATE from the table
TRAVEL in descending order of NO.
Ans. SELECT NO, NAME, TDATE FROM TRAVEL
ORDER BY NO DESC

(ii).To display the NAME of all the travellers


from the table TRAVEL who are
traveling by vehiclewith code 101 or
102.
Ans. SELECT NAME FROM TRAVEL WHERE
CODE='101' OR CODE='102';
OR SELECT NAME FROM TRAVEL WHERE
CODE=101 OR CODE=l02;
OR SELECT NAME FROM TRAVEL WHERE
CODE IN ('101','102');
OR SELECT NAME FROM TRAVEL WHERE
CODE IN (101,102);

(iii). To display the NO and NAME of those


travellers from the table TRAVEL who
travelled between ‘2015-12-31’ and
‘2015-04-01’.
Ans. SELECT NO, NAME from TRAVEL WHERE
TDATE >= '2015-04-01' AND TDATE <=
'2015-12-31';
OR SELECT NO, NAME from TRAVEL
WHERE TDATE BETWEEN '2015-04-01' AND
'2015-12-31';
OR SELECT NO, NAME from TRAVEL
WHERE TDATE <= '2015-12-31' AND
TDATE >= '2015-04-01';
OR SELECT NO, NAME from TRAVEL WHERE
TDATE BETWEEN '2015-12-31’ AND '2015-04-
01';

(iv) To display all the details from table


TRAVEL for the travellers, who have
travelled distance more than 100 KM in
ascending order of NOP.
Ans. SELECT * FROM TRAVEL WHERE KM > 100
ORDER BY NOP;
(v). SELECT COUNT(*), CODE FROM TRAVEL GROUP
BY CODE HAVING COUNT(*)>l;
Ans.

(vi). SELECT DISTINCT CODE FROM TRAVEL


Ans. DISTINCT CODE
101
102
103
104
105
(vii). SELECT A.CODE, NAME, VTYPE FROM
TRAVEL A,VEHICLE B
WHERE A.CODE=B.CODE AND KM<90;
Ans.

(viii) SELECT NAME,KM*PERKM FROM TRAVEL


A,VEHICLE B WHERE A.CODE=B.CODE
AND A.CODE='105';
Ans.
QUESTION: Consider a 1d array a containing 100
integers
Develop a program to do the following
1) Removing all occurances of a given integer.
2) Shift the elements of the array to the right so that the
used space is left on the left side.
3) Fill the unused space by zero.

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;

default: cout<<"\n ..wrong choice..";


break;
}
}
getch();
}

You might also like