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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.