You are on page 1of 4

SET-B

Q1.
Write the definition of a class FIGURE in C++ with following description:
Private Members
Sides integer
Shape char array of size 20
AssignShape() Member function to assign value of shape based upon Sides as follows:
Sides Shape
<3 Open
==3 Triangle
==4 Quadrilateral
>5 Polygon
Public Members
GetFigure() A function to allow user to enter value of Sides. Also, this function
should call Assign() to assign value of Shape
ShowFigure() A function to display Sides and Shape

Ans:
#include<iostream.h>
#include<string.h>
class FIGURE{
private:
int Sides;
char Shape[20];
public:
void AssignShape(){
if(Sides<3)
strcpy(Shape,”Open”);
else if(Sides==3)
strcpy(Shape,”Triangle”);
else if(Sides==4)
strcpy(Shape,”Quadrilateral”);
else if(Sides>5)
strcpy(Shape,”Polygon”);
}
void GetFigure(){
{
cout<<”\n enter value of Sides:”;
cin>>Sides;
AssignShape();
}
void ShowFigure(){
cout<<”Sides:”<<Sides<<”Shapes:”<<Shape;
}
};
void main(){
FIGURE F;
F. GetFigure();
F. ShowFigure();
}
Q2.
Write the definition of a function grace_score (int score [], int size) in C++, which should
check all the elements of the array and give an increase of 5 to those scores which are
less than 40.
Example: if an array of seven integers is as follows:
45 35 85 80 33 27 90
After executing the function, the array content should be changed as follows:
45 40 85 80 38 32 90

#include<iostream.h>

void grace_score(int score[],int size)


{

for(int x=0;x<size;x++)
{
if(score[x]<40)
{
score[x]=score[x]+5;
}
}
}
void main()
{
int A[7]={45,35,85,80,33,27,90};
grace_score(A,7);
for(int x=0;x<7;x++)
{
cout<<A[x]<<" ";
}
}

Q3. Consider the Table “Salesperson” shown below.


(Table : Salesperson)
SID Name Phone DOB Salary Area
S101 Amit Kumar 98101789654 1967-01-23 67000.00 North
S102 Deepika Sharma 99104567834 1992-09-23 32000.00 South
S103 Vinay Srivastav 98101546789 1991-06-27 35000.00 North
S104 Kumar Mehta 88675345789 1967-10-16 40000.00 East
S105 Rashmi Kumar 98101567434 1972-09-20 50000.00 South
a. Display names of Salespersons and their Salaries who have salaries in the range
30000.00 to 40000.00
SELECT Name, Salary FROM Salesperson WHERE Salary BETWEEN 30000.00 AND
40000.00
b. To display Names and Salaries of Salespersons in descending order of salary.
SELECT Name, Salary FROM Salesperson ORDER BY salary DESC
c. To display areas in which Salespersons are working. Duplicate Areas should not be
displayed.
SELECT DISTINCT Area FROM Salesperson.
d. To increase the salary by 500 of those whose area is North.
UPDATE Salesperson SET Salary=Salary+500 WHERE Area=”North”
e. To delete the record from the table salesperson whose salary is less than 40000.00
DELETE FROM Salesperson WHERE Salary<40000.00

You might also like