I have to create a C++ program with a header file, implementation file, and test file for the class "Rectangle." However, I am unsure how to properly separate the header class, and I figure that's why I'm encountering errors in my test class. I am using the IDE codelite for this assignment.
Here is my header file:
#ifndef RECTANGLE_H
#define RECTANGLE_H
class rectangle {
private:
double width;
double height;
public:
rectangle();
rectangle(double inputWidth, double inputHeight);
double getWidth();
double getHeight();
double getArea();
double getPerimeter();
void printRectangle(string objectName);
}
#endif
I am getting an error message on the line that declares the class, which says, "Expected ';' after top level declarator."
I do not have any errors showing in my .cpp implementation file, but I am getting numerous in my tester file. It is not recognizing that I'm trying to create objects of the rectangle class, or at least it isn't when I try to call the parameterized constructor. When I do, it's giving me an error of "use of undeclared identifier 'rectangle'," then on the object that is supposed to take parameters, it is asking if I meant to type the original, default object.
Here is the code of the beginning of the file and the (attempted) creation of objects:
#include <stdio.h>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include "rectangle.h"
#include "rectangle.cpp"
using namespace std;
int main() {
double inputWidth;
double inputHeight;
rectangle myRectangle;
cout << "Enter the width of the rectangle:" << endl;
cin >> inputWidth;
cout << "Enter the height of the rectangle:" << endl;
cin >> inputHeight;
rectangle herRectangle(inputWidth, inputHeight);
Then, I am getting an error on every line of code that tries to call a method for the object created using the parameterized constructor, saying "use of undeclared identifier 'herRectangle.'" For some reason I am not getting these error messages on the lines of code for the default rectangle.
Here is the code showing the method calls for the 'herRectangle' object:
cout << "herRectangle" << endl;
cout << "------------" << endl;
cout << "Width: " << herRectangle.getWidth() << endl;
cout << "Height: " << herRectangle.getHeight() << endl;
cout << "Area: " << herRectangle.getArea() << endl;
cout << "Perimeter: " << herRectangle.getPerimeter() << endl;
herRectangle.printRectangle();
Any and all help would be greatly appreciated! If there's anything else you would like for me to show in order to help, please just let me know. Sorry if my formatting is a bit wonky as well, I'm new to the forum.