1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
//Thomas Diaque
//C++ Assignment 1
using namespace std;
#include <iostream>
#include "class.h"
//constructor
rectangle::rectangle()
{
length = 1.0;
width = 1.0;
}
rectangle::rectangle(double length)
{
setLength(length);
width = 1.0;
}
rectangle::rectangle(double length, double width)
{
setWidth(width);
setLength(length);
}
rectangle::~rectangle() //destructor
{
cout << "Out of scope" << endl;
}
int main()
{
rectangle R1;
R1.setLength(1);
R1.setWidth(1);
// rectangle R2(7.1,3.2);
rectangle R2;
R2.setLength(7.1);
R2.setWidth(3.2);
// rectangle R3(6.3);
rectangle R3;
R3.setLength(6.3);
R3.setWidth(1);
// rectangle R4(-30,50);
rectangle R4;
R4.setLength(-30);
R4.setWidth(50);
// rectangle R5(R2.getLength(),R2.getWidth());
rectangle R5;
R5.setWidth(R2.getWidth());
R5.setLength(R2.getLength());
cout << "length: " << R1.getLength() << ", width: " << R1.getWidth() << ", perimeter: " << R1.calcPerimeter() << ", area: " << R1.calcArea() << " is square? ";
if (R1.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
cout << "length: " << R2.getLength() << ", width: " << R2.getWidth() << ", perimeter: " << R2.calcPerimeter() << ", area: " << R2.calcArea() << " is square? ";
if (R2.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
cout << "length: " << R3.getLength() << ", width: " << R3.getWidth() << ", perimeter: " << R3.calcPerimeter() << ", area: " << R3.calcArea() << " is square? ";
if (R3.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
cout << "length: " << R4.getLength() << ", width: " << R4.getWidth() << ", perimeter: " << R4.calcPerimeter() << ", area: " << R4.calcArea() << " is square? ";
if (R4.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
cout << "length: " << R5.getLength() << ", width: " << R5.getWidth() << ", perimeter: " << R5.calcPerimeter() << ", area: " << R5.calcArea() << " is square? ";
if (R5.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
cout <<"*************************************"<< endl;
//rectangle R1(5.4,10.5);
R1.setLength(5.4);
R1.setWidth(10.5);
//rectangle R4(15.6);
R4.setLength(15.6);
R4.setWidth(15.6);
cout << "length: " << R1.getLength() << ", width: " << R1.getWidth() << ", perimeter: " << R1.calcPerimeter() << ", area: " << R1.calcArea() << " is square? ";
if (R1.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
cout << "length: " << R2.getLength() << ", width: " << R2.getWidth() << ", perimeter: " << R2.calcPerimeter() << ", area: " << R2.calcArea() << " is square? ";
if (R2.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
cout << "length: " << R3.getLength() << ", width: " << R3.getWidth() << ", perimeter: " << R3.calcPerimeter() << ", area: " << R3.calcArea() << " is square? ";
if (R3.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
cout << "length: " << R4.getLength() << ", width: " << R4.getWidth() << ", perimeter: " << R4.calcPerimeter() << ", area: " << R4.calcArea() << " is square? ";
if (R4.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
cout << "length: " << R5.getLength() << ", width: " << R5.getWidth() << ", perimeter: " << R5.calcPerimeter() << ", area: " << R5.calcArea() << " is square? ";
if (R5.isSquare() ) cout << "yes." << endl;
else cout << "no." << endl;
// R1.calcPerimeter();
// R1.calcArea();
// R2.calcPerimeter();
// R2.calcArea();
// R3.calcPerimeter();
// R3.calcArea();
//
//
//cout <<"the area is "<< R1.calcArea() <<"!" << endl;
//cout<< "the perimeter is "<< R1.calcPerimeter() <<"!" << endl;
//
//cout <<"the area is "<< R2.calcArea() <<"!" << endl;
//cout<< "the perimeter is "<< R2.calcPerimeter() <<"!" << endl;
//
//cout <<"the area is "<< R3.calcArea() <<"!" << endl;
//cout<< "the perimeter is "<< R3.calcPerimeter() <<"!" << endl;
//
cin.clear();
cin.ignore(255, '\n');
cin.get();
return 0;
}
|