Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a c++ program and create a class called Rectangle. Use separate header and

ID: 653960 • Letter: W

Question

Write a c++ program and create a class called Rectangle. Use separate header and implementation files. The main program (not the functions) should display the values of perimeter and area after calling the functions. The problem refers to accessor (get) and mutator (set) functions for all the data fields. This means the following functions should be included: getHeight( ); getWidth( ); setHeight( ); setWidth( ); Run the main program for two cases (each case has two rectangle): 1) Text example (W = 4, H = 40 for the first rectangle. W = 3.5, H = 35.9 for the second rectangle) The program output should include the length, width, area, and perimeter.

Explanation / Answer

rectangle.h

class rectangle

{ public float h, w;

public float getHeight();

public float getWidth();

public float setHeight();

public float setWidth();

}

rectangle.cpp

# include conio

float getHeight()

{ cout << "Please enter the height "; endl;

cin << h;

}

float getWidth()

{ cout endl; cout << "Please enter the Width   " ; endl ;

cin >> w;

}

float setHeight()

{ private float height;

height = h;

}

float setWidth()

{ private float Width;

Width = w;

}

void main()

{ double area, perimeter;

area = width * height;

perimeter = 2* ( width + height);

cout << "height, width , area, perimeter"; cout << endl;

cout << height << width << area << perimeter; cout << endl;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote