If I use classes, will this reduce my lines of code?
Is this a good way?
Should I use a header for certain functions?
Thanks
(
Just wondering, thanks
/* Ask how many sides a shape has,
go to that shape,
ask for values to do questions about the shape
give answers
repeat
*/
#include <cstdlib>
#include <iostream>
using namespace std;
int Perimeter(int x, int y);
int Area(int x, int y);
int ChangeSize();
void SquaresAndRectangles();
int length, width, option;
bool program = true;
int main(int argc, char *argv[])
{
int sides;
do
{
cout << "How many sides does your shape have?\t";
cin >> sides;
switch(sides)
{
case 4:
cout << "Your shape is a square or a rectangle.\n";
SquaresAndRectangles();
break;
case 3:
cout << "Your shape is a triangle.\n";
break;
default:
cout << "This is geometry, be realistic\n";
}
}while ( sides != 4 || 3);
cin.get();
return EXIT_SUCCESS;
}
void SquaresAndRectangles()
{
cout << "Please enter the length of your shape\t";
cin >> length;
cout << "Please enter the width of your shape\t";
cin >> width;
while ( program = true )
{
cout << "(1):\tArea\n(2):\tPerimenter\n(3):\tChange Sizes";
cin >> option;
switch(option)
{
case 1:
Area(length, width);
break;
case 2:
Perimeter(length, width);
break;
case 3:
ChangeSize();
default:
break;
}
}
}
int Perimeter(int x, int y)
{
int Perimeter = x*2 + y*2;
cout << "The perimeter of your shape is " << Perimeter << ".\n";
return Perimeter;
};
int Area(int x, int y)
{
int Area = x*y;
cout << "The area of your shape is " << Area << ".\n";
return Area;
};
int ChangeSize()
{
cout << "Please enter the length of your shape\t";
cin >> length;
cout << "Please enter the width of your shape\t";
cin >> width;
return length;
return width;
}