Sponsor Area

Classes and Objects

Question
CBSEENCO12011568

Write the definition of a class BOX in C++ with following description:

Private Members

- BoxNumber    // data member of integer type
- Side         // data member of float type
- Area         // data member of float type
- ExecArea()   // Member function to calculate and assign
               // Area as Side * Side

Public Members

- GetBox()     // A function to allow user to enter values of
               // BoxNumber and Side. Also, this
               // function should call ExecArea() to calculate
               // Area
- ShowBox()    // A function
               // and Area

Solution

The definition of a class Box in C++ given,

class BOX
{
	int BoxNumber;
	float Side;
	float Area;
	void ExecArea(){ Area=Side*Side;}
public:
	void GetBox();
	void ShowBox();
};
void BOX::GetBox()
{
	cin>>BoxNumber>>Side;
	ExecArea();
}
void BOX::ShowBox()
{
	cout<<BoxNumber<<' '<<Side<<' '<<Area<<endl;
}

Question
CBSEENCO12011618

Write the definition of a function FixPay(float Pay[], int N) in C++, which should modify each element of the array Pay having N elements, as per the following rules:

Existing Value of Pay Pay to be changed to
If less than 100000 Add 25% in the existing value
If >=100000 and <20000 Add 20% in the existing value
If >=200000 Add 15% in the existing value

Solution

void FixPay(float Pay[ ], int N)
{
	for (int i=0;i<N;i++){
		if(Pay[i]<100000){
			Pay[i]+= 0.25 * Pay[i];
		}
		else if (Pay[i]>=100000 && Pay[i]<20000){
			Pay[i]+= 0.2 * Pay[i];
		}
		else if(Pay[i]>=200000){
			Pay[i]+= 0.15 * Pay[i];
		}
	}
}