일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- meta
- c++
- array
- System
- API
- HTML
- CSS
- CLASS
- beans
- 악성코드
- java
- C
- 투자
- 포인터
- Sort
- UTF-8
- jsp
- windows
- 자료구조
- Call-by-reference
- 윈도우즈
- query
- OOP
- 노드
- request
- WebProgramming
- algorithm
- JavaScript
- function
- Kafka
- Today
- Total
hahahia
1주차 본문
#include <iostream>
using namespace std;
typedef unsigned short int USHORT;
typedef unsigned long int ULONG;
enum BOOL {FALSE, TRUE};
enum CHOICE {DrawRect = 1, GetArea, GetPerim, ChangeDimensions, Quit};
class Rectangle{
public:
Rectangle(USHORT width, USHORT height);
~Rectangle();
USHORT GetHeight() const
{
return itsHeight;
}
USHORT GetWidth() const
{
return itsWidth;
}
ULONG GetArea() const
{
return itsHeight * itsWidth;
}
ULONG GetPerim() const
{
return 2*itsHeight + 2*itsWidth;
}
void SetSize(USHORT newWidth, USHORT newHeight);
void DrawShape() const;
private:
USHORT itsWidth;
USHORT itsHeight;
};
void Rectangle::SetSize(USHORT newWidth, USHORT newHeight)
{
itsWidth = newWidth;
itsHeight = newHeight;
}
Rectangle::Rectangle(USHORT width, USHORT height)
{
itsWidth = width;
itsHeight = height;
}
Rectangle::~Rectangle()
{
}
USHORT DoMenu();
void DoDrawRect(Rectangle);
void DoGetArea(Rectangle);
void DoGetPerim(Rectangle);
void main()
{
Rectangle theRect(30, 5);
USHORT choice = DrawRect;
USHORT fQuit = FALSE;
while(!fQuit)
{
choice = DoMenu();
if(choice < DrawRect || choice > Quit)
{
cout << endl << "Invalid Choice, please try again." << endl ;
continue;
}
switch(choice)
{
case DrawRect:
DoDrawRect(theRect);
break;
case GetArea:
DoGetArea(theRect);
break;
case GetPerim:
DoGetPerim(theRect);
break;
case ChangeDimensions:
USHORT newLength, newWidth;
cout << endl << "New width: " ;
cin >> newWidth;
cout << "New height: " ;
cin >> newLength;
theRect.SetSize(newWidth, newLength);
DoDrawRect(theRect);
break;
case Quit:
fQuit = TRUE;
cout << "Exiting... " << endl;
break;
default:
cout << "Error in choice! " << endl;
fQuit = TRUE;
break;
}
}
}
USHORT DoMenu()
{
USHORT choice;
cout << endl << "***Menu*** " << endl;
cout << "(1) Draw Rectangle " << endl;
cout << "(2) Area " << endl;
cout << "(3) Perimeter " << endl;
cout << "(4) Resize " << endl;
cout << "(5) Quit " << endl;
cin >> choice;
return choice;
}
void DoDrawRect(Rectangle theRect)
{
USHORT height = theRect.GetHeight();
USHORT width = theRect.GetWidth();
for(USHORT i = 0; i<height; i++)
{
for(USHORT j=0; j<width; j++)
{
cout << "*";
}
cout << endl;
}
}
void DoGetArea(Rectangle theRect)
{
cout << "Area: " << theRect.GetArea() << endl;
}
void DoGetPerim(Rectangle theRect)
{
cout << "Perimeter : " << theRect.GetPerim() << endl;
}
'Language > C++' 카테고리의 다른 글
C++ 포함 (0) | 2012.09.01 |
---|---|
Operator Overloading(연산자 오버로딩) (0) | 2012.09.01 |
Class GradeBook Using an Array to Store Grades (0) | 2011.05.25 |
재귀함수를 이용한 fibonacci (0) | 2011.05.17 |
간단한 Class프로그램을통한 Class의 개념과 특징 (0) | 2011.05.10 |