Test #1 Create a class called Rectangle. Use the UML below to define the methods in the class. Create a folder on the linux server called test1 and write and test your code in that area. An executable program must be on the linux server. Hit submit on the assignment page when you have completed the test. Use a similar driver as below to test your class. #include #include"Rectangle.h" int main(){ Rectangle r1(1.2, 3.4); cout<
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Test #1
Create a class called Rectangle. Use the UML below to define the methods in the class. Create a folder on the linux server called test1 and write and test your code in that area. An executable program must be on the linux server. Hit submit on the assignment page when you have completed the test.
Use a similar driver as below to test your class.
#include<iostream>
#include"Rectangle.h"
int main(){
Rectangle r1(1.2, 3.4);
cout<<r1.toString()<<endl;
Rectangle r2;
cout<<r2.toString()<<endl;
// Test setters and getters
r1.setLength(5.6);
r1.setWidth(7.8);
cout<<r1.toString()<<endl;
cout<<"length is: " <<r1.getLength()<<endl;
cout<<"width is: "<<r1.getWidth()<<endl;
// Test getArea() and getPerimeter()
cout<<"area is: "<<r1.getArea()<<endl;
cout<<"perimeter is: "<<r1.getPerimeter()<<endl;
}
Output Should be something like the following:
Rectangle[length=1.2,width=3.4]
Rectangle[length=1.0,width=1.0]
Rectangle[length=5.6,width=7.8]
length is: 5.6
width is: 7.8
area is: 43.68
perimeter is: 26.80
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images