I am attempting to write a program with the following requirements:
In this assignment students should create five header classes called Point, Circle, Rectangle, Square, FigureGeometry and one cpp file TestAll. The TestAll class should implement a main method which tests all of the other files created in the assignment. After the assignment has been completed, all six files should be submitted for grading into the Dropbox for Assignment 3, which can be found in the Dropbox menu on the course website. Students should note that only the *.h or .cpp file for each class needs to be submitted.
Please click on each of the following links to view specific requirements for the files that must be created and submitted:
Requirements: Point.h
Requirements: FigureGeometry.h
Requirements: Circle.h
Requirements: Rectangle.h
Requirements: Square.h
Requirements: TestAll.cpp
When trying to compile I get the following errors in the TestAll.cpp file:
error C2664: 'Square::Square(Point)' : cannot convert parameter 1 from 'float' to 'Point' Line 21
error C2664: 'Rectangle::Rectangle(Point)' : cannot convert parameter 1 from 'int' to 'Point' Line 28
I just cannot figure it out!
Here is my code:
TestAll.cpp
Point.h
FigureGeometry.h
Circle.h
Square.h
Rectangle.h
In this assignment students should create five header classes called Point, Circle, Rectangle, Square, FigureGeometry and one cpp file TestAll. The TestAll class should implement a main method which tests all of the other files created in the assignment. After the assignment has been completed, all six files should be submitted for grading into the Dropbox for Assignment 3, which can be found in the Dropbox menu on the course website. Students should note that only the *.h or .cpp file for each class needs to be submitted.
Please click on each of the following links to view specific requirements for the files that must be created and submitted:
Requirements: Point.h
Requirements: FigureGeometry.h
Requirements: Circle.h
Requirements: Rectangle.h
Requirements: Square.h
Requirements: TestAll.cpp
When trying to compile I get the following errors in the TestAll.cpp file:
error C2664: 'Square::Square(Point)' : cannot convert parameter 1 from 'float' to 'Point' Line 21
error C2664: 'Rectangle::Rectangle(Point)' : cannot convert parameter 1 from 'int' to 'Point' Line 28
I just cannot figure it out!
Here is my code:
TestAll.cpp
#include<iostream> #include<iomanip> #include<string> #include"Circle.h" #include"Square.h" #include"Rectangle.h" using namespace std; void main() { Circle* c1 = new Circle(5.0f); cout << "Details of c1: " << endl << "Radius: " << c1->getRadius() << endl << "Area: " << c1->getArea() << endl << "Perimeter: " << c1->getPerimeter() << endl << endl; Square* s1 = new Square(5.0); cout << "Details of s1: " << endl << "Radius: " << s1->getSideLength() << endl << "Area: " << s1->getArea() << endl << "Perimeter: " << s1->getPerimeter() << endl << endl; Rectangle* r1 = new Rectangle(5.0); cout << "Details of r1: " << endl << "Width: " << r1->getWidth() << endl << "Height: " << r1->getHeight() << endl << "Area: " << r1->getArea() << endl << "Perimeter: " << r1->getPerimeter() << endl << endl; }
Point.h
#ifndef POINT_H #define POINT_H #include<iostream> using namespace std; /** Class that represents a point. */ class Point { private: // Data fields. int width; // Stores the width of a Point object. int height; // Stores the height of a Point object. public: // Functions. Point() // Constructor. Initializes initial the width and height of a Point object. { width = 0; height = 0; } Point(int theWidth, int theHeight) // Constructor. Initializes the width and height of a Point object. { width = theWidth; height = theHeight; } int getWidth() // Returns the width of a Point object. { return width; } int getHeight() // Returns the height of a Point object. { return height; } void setWidth(int theWidth) // Assigns the width of a Point object, but does not return a value. { width = theWidth; } void setHeight(int theHeight) // Assigns the height of a Point object, but does not return a value. { height = theHeight; } }; #endif
FigureGeometry.h
#include<iostream> #include<iomanip> #include<string> #include"Circle.h" #include"Square.h" #include"Rectangle.h" using namespace std; void main() { Circle* c1 = new Circle(5.0f); cout << "Details of c1: " << endl << "Radius: " << c1->getRadius() << endl << "Area: " << c1->getArea() << endl << "Perimeter: " << c1->getPerimeter() << endl << endl; Square* s1 = new Square(5.0); cout << "Details of s1: " << endl << "Radius: " << s1->getSideLength() << endl << "Area: " << s1->getArea() << endl << "Perimeter: " << s1->getPerimeter() << endl << endl; Rectangle* r1 = new Rectangle(5.0); cout << "Details of r1: " << endl << "Width: " << r1->getWidth() << endl << "Height: " << r1->getHeight() << endl << "Area: " << r1->getArea() << endl << "Perimeter: " << r1->getPerimeter() << endl << endl; }
Circle.h
#ifndef CIRCLE_H #define CIRCLE_H #include<iostream> #include<iomanip> #include<string> #include "FigureGeometry.h" using namespace std; /** Class that represents a circle. */ class Circle : public FigureGeometry // Circle class is a derived class of FigureGeometry class. // It inherits its data and member functions. { private: // Data fields. float radius; // Stores the radius of an object. public: // Functions. Circle(){;} Circle(float theRadius) // Initializes the radius of a circle. { radius = theRadius; } ~Circle(){;} // Destructor, destroys instance of Circle. float getRadius() const // Returns the radius of a circle. { return radius; } float getArea() const // Returns the area of a circle. { return getRadius() * getRadius() * PI; } float getPerimeter() const // Returns the permimeter of a circle. { return getRadius() * 2 * PI; } void setRadius(float theRadius) // Assigns the radius of a circle object, but does not return a value. { radius = theRadius; } }; #endif
Square.h
/** Class that represents a square. */ class Square { private: // Data fields. Point point; // Stores the Point of Square object. public: // Functions. Square(){;} Square(Point p1) // Initializes the Point of a Square object. { point = p1; } ~Square(){;} // Destructor, destroys instance of Square. int getSideLength() // Returns the side length of a Square object. { return point.getWidth(); } virtual float getArea() // Returns the area of a Square object. { return getSideLength() * getSideLength(); } virtual float getPerimeter() // Returns the perimeter of a Square object. { return getSideLength() * 4; } void setPoint(Point p1) // Assigns the side length of a square object, but does not return a value. { point = p1; } }; #endif
Rectangle.h
#ifndef RECTANGLE_H #define RECTANGLE_H #include<iostream> #include<iomanip> #include<string> #include "Point.h" // Access to the Point class. using namespace std; /** Class that represents a rectangle. */ class Rectangle { private: // Data fields Point point; public: // Functions. Rectangle(){;} // Rectangle constructor. Rectangle(Point p1) { point = p1; } ~Rectangle(){;} // Destructor, destroys instance of Rectangle. int getWidth() // Returns the width of a Rectangle object. { return point.getWidth(); } int getHeight() // Returns the height of a Rectangle object. { return point.getHeight(); } float getArea() // Returns the area of a Rectangle object. { return getWidth() * getHeight(); } float getPerimeter() // Returns the perimeter of a Rectangle object. { return ( getWidth() + getHeight() ) * 2; } void setPoint(Point p1) // Assigns Point p1 to point, but does not return a value. { point = p1; } }; #endif