You are on page 1of 4

PRACTISE QUESTIONS

CLASS:XII
SET – A
Write the definition of a class CONTAINER in C++ with the following description :

Private members:
Radius, Height float type
Type int (1 for Cone,2 for Cylinder)
Volume float
CalVolume() Member function to calculate volume as per the Type :
Type Formula to calculate Volume
1 3.14*Radius*Height
2 3.14*Radius*Height/3
Public members:
GetValues() A function to allow user to enter value of Radius, Height and Type. Also, call
function CalVolume() from it
ShowAll() A function to display Radius, Height,Type and Volume of Container

Ans:

#include<iostream.h>

class CONTAINER
{
float Radius, Height;
int Type;
float Volume;
void CalVolume(){
if (Type == 1)
Volume=3.14*Radius*Height;
else if (Type == 2)
Volume=3.14*Radius*Height/3;
}
public:
void GetValues(){
cout<<"Enter Radius,Height, and Type:";
cin>>Radius>>Height>>Type ;
CalVolume();
}
void ShowAll(){
cout<<"Radius:"<<Radius<<"Height:"<<Height<<"Type:"<<Type<<"Volume:"
<<Volume<<endl;
}
};
void main(){
CONTAINER C;
C.GetValues();
C.ShowAll();
}

Write the definition of a function SumEvenOdd(int VALUES[], int N) in C++, which should
display the sum of even values and sum of odd values of the array separately.
Example :
If the array VALUES contains
25 20 22 21 53
Then the functions should display the output as :
Sum of even values = 42 (i.e., 20+22)
Sum of odd values = 99 (i.e., 25+21+53)
Ans:
#include<iostream.h>

void SumEvenOdd(int VALUES[ ],int N)


{
int Esum=0,Oddsum=0;
for(int x=0;x<N;x++)
{
if(VALUES[x]%2==0)
{
Esum=Esum+VALUES[x];
}else
{
Oddsum=Oddsum+VALUES[x];
}
}
cout<<"\nSum of even values="<<Esum;
cout<<"\nSum of odd values="<<Oddsum;
}
void main()
{
int A[5]={25,20,22,21,53};
SumEvenOdd(A,5);

Q3. Consider the Table “Gym” shown below.


Table : Gym
Mcode Mname Gender Age FeeGiven Type DtAdmit
1 Amit Male 35 6000 Monthly 2016-01-23
2 Rashmi Female 25 8000 Monthly 2016-09-23
3 George Male 42 24000 Yearly 2011-06-27
4 Rohan Male 27 12000 Quarterly 2012-10-16
5 Samit Male 54 6000 Monthly 2015-09-20
6 Lakshmi Female 43 4500 Monthly 2016-01-15
7 Samita Female 22 500 Guest 2017-01-23
8 Michael Male 51 24000 Yearly 2013-07-18
a. To display Mname, Age, FeeGiven of those members whose fee is above 12000
SELECT Mname,Age,FeeGiven FROM Gym WHERE FeeGiven>12000
b. To display Mcode, Mname, Age of all female members of the Gym
SELECT Mname,Age,FeeGiven FROM Gym WHERE Gender=”Female”
c. To display all the records from the table Gym in descending order of age.
SELECT * FROM Gym ORDER BY age DESC
d. Update the feegiven by 500 of those whose age is more than 30.
UPDATE Gym SET FeeGiven=FeeGiven+500 WHERE Age>30
e. Delete the records of those whose type is guest from the table gym.
DELETE FROM Gym WHERE Type=”Guest”

You might also like