Questions: 11 448

Answers by our Experts: 10 707

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Write the definition for a class called Rectangle that has floating point data members

length and width. The class has the following member functions:

void setlength(float)r

void setwidth(float)

float perimeter()

float area()

void show()

int sameArea(Rectangle) that has one parameter of type Rectangle. sameArea returns 1 if the

two Rectangles have the same area, and returns 0 if they don't.

1. Write the definitions for each of the above member functions.

2. Write main function to create two rectangle objects. Set the length and width of the first

rectangle to 5 and 2.5. Set the length and width of the second rectangle to 5 and 18.9. Display

each rectangle and its area and perimeter.


3. Check whether the two Rectangles have the same area and print a message indicating the result.

Set the length and width of the first rectangle to 15 and 6.3. Display each Rectangle and its area

and perimeter again. Again, check whether the two Rectangles have the same area and print a

message indicating the result.


Consider the definition of the following class:

class Sample

{

private:

int x;

double y;

public :

Sample(); //Constructor 1

Sample(int); //Constructor 2

Sample(int, int); //Constructor 3

Sample(int, double); //Constructor 4

};

i. Write the definition of the constructor 1 so that the private member variables are initialized to

0.

ii. Write the definition of the constructor 2 so that the private member variable x is initialized

according to the value of the parameter, and the private member variable y is initialized to 0.

iii. Write the definition of the constructors 3 and 4 so that the private

member variables are initialized according to the values of the parameters.


Answer the questions (i) and (ii) after going through the following class:

class Test

{

char paper[20];

int marks;

public:

Test () // Function 1

{

strcpy (paper, "Computer");


r

marks = 0;

}

Test (char p[]) // Function 2

{

strcpy(paper, p);

marks = 0;

}

Test (int m) // Function 3

{

strcpy(paper,"Computer");

marks = m;

}

Test (char p[], int m) // Function 4

{

strcpy (paper, p);

marks = m;

}

};

i. Write statements in C++ that would execute Function 1, Function 2, Function 3 and Function 4

of class Test.

ii. Which feature of Object Oriented Programming is demonstrated using Function 1, Function 2,

Function 3 and Function 4 together in the above class Test?


Answer the questions (i) and (iii) after going through the following class:

class Seminar

{

int time;

public:

Seminar() //Function 1

{

time = 30;

cout << "Seminar starts now" << endl;

}

void lecture() //Function 2

{

cout << "Lectures in the seminar on" << endl;

}

Seminar(int duration) //Function 3

{

time = duration;

cout << "Seminar starts now" << endl;

}

~Seminar() //Function 4

{

cout << "Thanks" << endl;

}

};

i. Write statements in C++ that would execute Function 1 and Function 3 of class Seminar.

ii. In Object Oriented Programming, what is Function 4 referred as and when does it get

invoked/called?

iii. In Object Oriented Programming, which concept is illustrated by Function 1 and Function 3

together?


Write the definition for a class called complex that has floating point data members for

storing real and imaginary parts. The class has the following member functions:

void set(float, float) to set the specified value in object

void disp() to display complex number object

complex sum(complex) to sum two complex numbers & return complex number


1. Write the definitions for each of the above member functions.

2. Write main function to create three complex number objects. Set the value in two objects and

call sum() to calculate sum and assign it in third object. Display all complex numbers.

Note: For user understanding purposes you should write comment with each line of code.


Define a class batsman with the following specifications: Note for user understanding purposes

you should write comment with each line of code.

Private members:

bcode 4 digits code number

bname 20 characters

innings, notout, runs integer type

batavg it is calculated according to the formula –

batavg =runs/(innings-notout)

calcavg() Function to compute batavg

Public members:

readdata() Function to accept value from bcode, name, innings, notout and invoke

the function calcavg()

displaydata() Function to display the data members on the screen.


Define a class student with the following specification. Note for user understanding purposes you

should write comment with each line of code.

Private members of class student

admno integer

sname 20 character

eng. math, science float

total float

ctotal() a function to calculate eng + math + science with float return type.


Public member function of class student

Takedata() Function to accept values for admno, sname, eng, science and invoke

ctotal() to calculate total.

Showdata() Function to display all the data members on the screen.


A program needs to be developed for helping your younger siblings to calculate the area of a square when the input(side) is given. The program first of all needs to permit him/her to work on the area when he/she is below class 6. The program should allow for new entering of class when the class given doesn’t meet the requirement for working on area of a square. Also, ensure that the side given is a positive number else allow him/her enter a new side. 


Write a C++ program that creates two one dimensional arrays “A” and “B” of size 20 elements each. The main program should get the input in the array “A” from the user and initialize array “B” with values “0”. Your program should calculate the (number -2) of each element of array “A” and should store in the square value in corresponding positions (index) in the array “B”. In the end, the main program (main function) prints the calculated values of array “B”. Also display the values in array B which are Odd


At the peak of COVID-19, most worker started working from home. Salaries of workers were reduced by 30%. Assuming income tax was also reduced by 50% from the previous rate of 15% and workers were paid on the number of hours worked in a month and each worker is supposed to work a total of 170 hours in a month. All overtime has been cancelled. If a worker does not meet the 170 hours’ threshold for a month, 5% is deducted from the salary. Assuming the hourly rate is GHC 10, Write a c++ program for the scenario narrated above. Your program should:

a) request for an employee’s name, the number of hours worked in a month AP[2 marks]

b) define a function called payRole, your function should compute a worker’s salary and income tax and any deductions if any

c) your program should display the results in “b” above.

AN[10 marks]

AP[3 marks]

d) explain the logic behind the code especially the function


LATEST TUTORIALS
APPROVED BY CLIENTS