#include <iostream>

using std::cout;
using std::endl;
using std::cin;


class Rectangle // 직사각형 클래스
{
 double width, height;

 

public:


 Rectangle(double wid, double hei){ //생성자
  width = wid;
  height = hei;
 }

 

 double GetArea(){ //면적
  return width*height;
 }
 
 double GetGrith(){ //둘레
  return 2*width*height;
 }
};


class Circle // 원 클래스
{
 double radius;

 

public:
 Circle(double rad){ //생성자
  radius = rad;
 }

 

 double GetArea(){ //면적
  return 3.14*radius*radius;
 }

 

 double GetGrith(){ //둘레
  return 2*3.14*radius;
 }
};

 

int main(void)
{
 
 int Number = 0;
 
 do {

 cout << "Select a number 1 - Rectangle, 2 - Circle, 0 - Quit : " ;
 cin >> Number;
 
 if(Number == 0) // 0이 입력되면 종료
  return 0;

 }while(Number != 1 && Number != 2);

 

 switch (Number) {


 case 1 : { //직사각형 일 때
  double width=0;
  double height=0;

 

  do {
  cout << "Insert Rectangle's width(over 0) : "; //폭
  cin >> width;
  }while(width <= 0); //0이하의 값 거부
  
  do{
  cout << "Insert Rectangle's height(over 0) : "; //높이
  cin >> height;
  }while(height <=0);//0이하의 값 거부

 

  Rectangle rec(width, height); //객체생성


  cout << "Area is : " << rec.GetArea() << endl;
  cout << "Grith is : " << rec.GetGrith() << endl;


  break;
    }

 

 case 2 : { // 원 일 때
  double radius = 0;

 

  do {
   cout << "Insert Circle's radius(over 0) : "; //반지름
   cin >> radius;
  }while(radius <=0);//0이하의 값 거부
  
  Circle cir(radius); // 객체 생성


  cout << "Area is : " << cir.GetArea() << endl;
  cout << "Grith is : " << cir.GetGrith() << endl;


  break;
    }


 }//end switch


 return 0; //프로그램 종료
}


+ Recent posts