Design a class. RectangleType, that can store the length and width of a rectangle. Provide appropriate functions for setting and getting the length and width as well as the calculating the perimeter and the area. The bottom, of a rectangular box is a rectangle. Design a class, BoxType, derived from RectangleType, which can capture the values of length, width, and height. Some of the operations that can be performed on a box are: calculate the volume and the total surface area, set and get the dimensions. Write a program to test the capabilities of RexctangleType and BoxType.
Here are my errors I know its quite a bit of them but please help me out!
Thank You
error C2059: syntax error : '?'
error C2143: syntax error : missing ';' before '}'
error C2238: unexpected token(s) preceding ';'
error C2248: 'RectangleType::recLenght' : cannot access private member declared in class 'RectangleType'
see declaration of 'RectangleType::recLenght'
see declaration of 'RectangleType'
error C2248: 'RectangleType::recWidth' : cannot access private member declared in class 'RectangleType'
see declaration of 'RectangleType::recWidth'
see declaration of 'RectangleType'
error C2248: 'RectangleType::recLenght' : cannot access private member declared in class 'RectangleType'
see declaration of 'RectangleType::recLenght'
see declaration of 'RectangleType'
cannot access private member declared in class 'RectangleType'
see declaration of 'RectangleType::recWidth'
see declaration of 'RectangleType'
error C2248: 'RectangleType::recLenght' : cannot access private member declared in class 'RectangleType'
see declaration of 'RectangleType::recLenght'
see declaration of 'RectangleType'
'RectangleType::recWidth' : cannot access private member declared in class 'RectangleType'
see declaration of 'RectangleType::recWidth'
: see declaration of 'RectangleType'
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
class RectangleType
{
private: double recLenght;
double recWidth;
double perimeter;
double recArea;
public:
RectangleType()
{
recLenght = 0;
recWidth = 0;
perimeter = 0;
recArea = 0;
}
void setRecLength()
{
cout <<"Enter the length: ";
cin >> recLenght;
if (recLenght < 1)
{
cout <<"Please enter a positive number: ";
cin >> recLenght;
}
}
void setRecWidth()
{
cout <<"Enter the width: ";
cin >> recWidth;
if (recWidth < 1)
{
cout <<"Please enter a positive number: ";
cin >> recWidth;
}
}
void setPerimeter()
{
perimeter = 2*recWidth +2*recLenght;
cout << fixed << showpoint << setprecision(2);
cout <<" The perimeter of the rectangle is " << perimeter << endl;
}
void setArea()
{
recArea = recLenght*recWidth;
cout <<"The area of the rectangle is " << recArea << endl;
}
};
class BoxType:public RectangleType
{
private:
RectangleType shape;
double boxHeight;
double boxVolume;
double boxArea;
public:
BoxType()
{
boxHeight = 0;
boxVolume = 0;
boxArea = 0;
}
void setBoxLength()
{
shape.setRecLength();
}
void setBoxWidth()
{
shape.setRecLength();
}
void setBoxHeight()
{
cout <<"Enter the box height: ";
cin >> boxHeight;
if (boxHeight < 1)
{
cout <<"Please enter a positive number: ";
cin >> boxHeight;
}
}
void setBoxVolume()
{
boxVolume = recLenght*recWidth*boxHeight;
cout << fixed << showpoint << setprecision(2);
cout <<"The volume of the box is " << boxVolume << endl;
}
void setBoxArea()
{
boxArea = 2*recLenght*recWidth + 2*recLenght*boxHeight + 2*recWidth*boxHeight;
cout << fixed << showpoint << setprecision(2);
cout <<"The surface area of the box is " << boxArea << endl;
}
};
int main()
{
RectangleType shape1;
BoxType shape2;
shape1.setRecLength();
shape1.setRecWidth();
shape1.setPerimeter();
shape1.setArea();
cout << endl;
shape2.setBoxLength();
shape2.setBoxWidth();
shape2.setBoxHeight();
shape2.setBoxVolume();
shape2.setBoxArea();
return 0;
}
|