Back to Browse

C++ OOP Exercise: Creating Rectangle Class (Constructors, Methods, Objects)

21.5K views
Apr 24, 2015
34:02

C++ Programming Challenge: Creating Rectangle Class Similar to your lab, you will need to turn in 3 files. Rectangle.h, Rectangle.cpp, and main.cpp Rectangle should have two private fields defined as double data types, width and height. there should be get and set methods for each. A no-arg constructor that creates a rectangle with width of 1 and height of 1. Another constructor that cretaes a default rectangle with the specified width and height passed into it. Create a public function named getArea() that returns the area of the rectangle. Create a public function named getPerimeter() that returns the perimeter of the rectangle. In the int main() program, include the Rectangle.h file. You will loop until a a width or height of 0 is input: After you ask for a width and then a height, create an object and set the width and height of the rectangle to it. Then output to the screen what the area is and the perimeter is from the object. Learning to code? Follow my C++ tutorials for beginners. I do a lot of C++ programming challenges and C++ projects as part of my homework - every day! If you are learning to program, nothing beats solving real programming exercises and coding challenges. So don't forget to subscribe, as I release new programming videos every day! DOWNLOAD FILES: http://www.codinghomework.com/?p=718

Download

0 formats

No download links available.

C++ OOP Exercise: Creating Rectangle Class (Constructors, Methods, Objects) | NatokHD