It is my last section of code that doesnt want to copy properly but here is the updated.
I'm not sure what you mean by invisible newlines either.
I notice you print the perimeter in main but I am supposed to use the print function to display the information for the rectangle. i.e. the print function should give the length, width, area, perimeter, and whether or not the object is a square(when I get that far lol)
Code:
//Program to calculate the perimeterand area of a rectangle
#include<iostream>
#include"Rectangle.h"
usingnamespace std;
int main()
{
Rectangleobject1;
Rectangleobject2 (7.1, 3.5);
Rectangleobject3 (6.3);
Rectangleobject4 (21, 22);
Rectangleobject5 = object2;
/*
Rectangleobject1 (5.4, 10.5);
Rectangleobject4 (15.6, 15.6);
*/
object1.printData();
object2.printData();
object3.printData();
object4.printData();
object5.printData();
}
Code:
//Rectangle.h
//Defintion of class Rectangle
#ifndef RECTANGLE_H
#define RECTANGLE_H
class Rectangle
{
public:
//overloaded constructor functions
Rectangle();
Rectangle(double length);
Rectangle(double length, doublewidth);
//set functions
void setLength( double);
void setWidth( double);
//get functions
double getLength() const;
double getWidth() const;
//calculation functions
double calcPerimeter() const;
double calcArea() const;
//test for square
void booleanSquare ();
//print functions
void printData();
private:
double length;
double width;
};
#endif
Code:
//Rectangle.cpp
//Rectangle class member functions
#include<iostream>
#include<iomanip>
#include"Rectangle.h"
usingnamespace std;
Rectangle::Rectangle()
{
setLength(1.0);
setWidth(1.0);
}
Rectangle::Rectangle(double length)
{
setLength(length);
setWidth(1.0);
}
Rectangle::Rectangle(double length, double width)
{
setLength(length);
setWidth(width);
}
double Rectangle::calcArea() const
{
return length*width;
}
doubleRectangle::calcPerimeter() const
{
return (2*length)+(2*width);
}
voidRectangle::setLength (double l)
{
if (l >= 0 && l <= 20)
length = l;
else
{
length = 1.00;
cout<<
"The length entered is invalid and has been set to 1.00";
}
}
void Rectangle::setWidth (double w)
{
if (w >= 0 && w <= 20)
width = w;
else
{
width = 1.00;
cout<<
"The width entered is invalid and has been set to 1.00";
}
}
double Rectangle::getLength() const
{
return length;
}
double Rectangle::getWidth() const
{
return width;
}
void Rectangle::booleanSquare()
{
/*
if (length-width < .0001)
*/
}
void Rectangle::printData()
{
cout<<
"Length: " << length;
cout<<
"Width: " << width;
cout<<
"Area: " << area;
cout<<
"Perimeter: " << perimeter;
}