Hello,
I am currently a sophomore CS major and have a C++ assignment I need help with. I have browsed the boards to see if asking for hw help was appropriate, and I did not find anything saying that it was not. If this is not appropriate, please let mek now and I will remove the post.
Add the following constructors to your application:
Constructor Parameter Instance Variables Value
Default None x 1
y 1
height 10
width 10
Three Member newX x newX
newY y newY
size height size
width size
Four Member newX x newX
newY y newY
newHeight height newHeight
newWidth width newWidth
In each constructor, add cout statements that indicate which constructor is executing.
<my program so far>
// Lab 6
// Class header
// Rectangle.h
class Rectangle {
public:
Rectangle(double x=1, double y=1, double Height=10, double Width=10);
double getArea();
double getPerimeter();
void draw();
double getX();
double getY();
double getHeight();
double getWidth();
void setX(int a);
void setY(int a);
void setHeight(int a);
void setWidth(int a);
private:
double x;
double y;
double Height;
double Width;
};
// Lab 6
// Class implementation
// Rectangle.cpp
#include "Rectangle.h"
#include <iostream>
using namespace std;
double Rectangle::getArea() {
return Height*Width;
}
double Rectangle::getPerimeter(){
return 2*Height+2*Width;
}
void Rectangle::draw(){
cout << "Rectangle\n";
}
double Rectangle::getX(){
return x;
}
double Rectangle::getY(){
return y;
}
double Rectangle::getHeight(){
return Height;
}
double Rectangle::getWidth(){
return Width;
}
void Rectangle::setX(int a){
if(a>0) {
x=a;
}
}
void Rectangle::setY(int a){
if(a>0) {
y=a;
}
}
void Rectangle::setHeight(double a){
double a;
if(a >0) {
Height=a;
}
}
void Rectangle::setWidth(double a){
double a;
if(a>0) {
Width=a;
}
}
// Lab 6
// Main function
// TestRectangle.cpp
#include <iostream>
#include "rectangle.h"
using namespace std;
void main() {
Rectangle r1;
r1.setHeight(30);
r1.setWidth(10);
r1.setX(100);
r1.setY(150);
cout << "Rectangle Settings" << endl;
cout << "X: " << r1.getX();
cout << "\tY: " << r1.getY();
cout << "\tHeight: " << r1.getHeight();
cout << "\tWidth: " << r1.getWidth();
cout << "\tArea: " << r1.getArea();
cout << "\tPerimeter: " << r1.getPerimeter();
cout << endl << endl;
}
I'm not looking for someone to do it all for me, but some advice would be great on how to implement the constructors. I am clueless on this atm.
Thanks in advance!