subject

Creating a class in c++in this lab, you create a programmer-defined class and then use it in a c++ program. the program should create two rectangle objects and find their area and perimeter. instructionsensure the class file named rectangle. cpp is open in your editor. in the rectangle class, create two private attributes named length and width. bothlength and width should be data type double. write public set methods to set the values for length and width. write public get methods to retrieve the values for length and width. write a public calculatearea()method and a public calculateperimeter() method to calculate and return the area of the rectangle and the perimeter of the rectangle. open the file named myrectangleclassprogram. cpp. in the myrectangleclassprogram, create two rectangle objects named rectangle1 and rectangle2 using the default constructor as you saw in myemployeeclassprogram. cpp. set the length of rectangle1 to 10.0 and the width to 5.0. set the length of rectangle2 to 7.0 and the width to 3.0.print the value of rectangle1’s perimeter and area, and then print the value of rectangle2’s perimeter and area. execute the program by clicking the "run code" button at the bottom of the screen given code // rectangle. cppusing namespace std; class rectangle{ public: // declare public methods here private: // create length and width here}; void rectangle: : setlength(double len){ }void rectangle: : setwidth(double wid){ // write setwidth here}double rectangle: : getlength(){ // write getlength here}double rectangle: : getwidth(){ // write getwidth here} double rectangle: : calculatearea(){ // write calculatearea here}double rectangle: : calculateperimeter(){ // write calculateperimeter here} other given code // this program uses the programmer-defined rectangle class.#include "rectangle. cpp"#include using namespace std; int main(){ rectangle rectangle1; rectangle rectangle2; rectangle1.setlength(10.0); rectangle1.setwidth(5.0); rectangle2.setlength(7.0); rectangle2.setwidth(3.0); cout < < "perimeter of rectangle1 is " < < rectangle1.calculateperimeter() < < endl; cout < < "area of rectangle1 is " < < rectangle1.calculatearea() < < endl; cout < < "perimeter of rectangle2 is " < < rectangle2.calculateperimeter() < < endl; cout < < "area of rectangle2 is " < < rectangle2.calculatearea() < < endl; return 0; }

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 17:30, glocurlsprinces
Rachel completed typing an official document with a word processing program. she wants to make sure that her document has no typographical errors. she also wants all headings to have the same font. which features in a word processing program should she use? rachel should use the feature in a word processing program to find typographical errors. she should apply to have uniform headings.
Answers: 1
image
Computers and Technology, 22.06.2019 20:00, bowmanari2154
What is used to analyze and summarize your data without graphical support
Answers: 1
image
Computers and Technology, 23.06.2019 22:20, Izzyfizzy
Read “suburban homes construction project” at the end of chapters 8 and 9 (in the textbook) and then develop a wbs (work breakdown structure) in microsoft excel or in microsoft word (using tables)
Answers: 1
image
Computers and Technology, 24.06.2019 08:10, anthonysutton82
Where are american poets found in the dewey decimal system
Answers: 1
You know the right answer?
Creating a class in c++in this lab, you create a programmer-defined class and then use it in a c++ p...

Questions in other subjects:

Konu
Mathematics, 13.11.2020 04:10
Konu
Mathematics, 13.11.2020 04:10
Konu
Mathematics, 13.11.2020 04:10