넓이 2

전전컴/C++ 2011. 1. 25. 22:43

#include <iostream.h>

class setLength
{
 int width;
 int height;

public:
 setLength(int a, int b);
 float getArea();
};

setLength::setLength(int a, int b)
{
 width=a;
 height=b;
}

float setLength::getArea()
{
 float area;
 area=width*height*0.5;
 return area;
}

int main(void)
{
 int a, b;

 cout<<"가로를 입력하세요";
 cin>> a;
 cout<<"세로를 입력하세요";
 cin>> b;

 setLength area(a, b);

 cout<< "삼각형의 넓이는" <<area.getArea()<<"입니다" <<endl;


 return 0;
}


 

설정

트랙백

댓글

넓이

전전컴/C++ 2011. 1. 25. 22:20


#include <iostream.h>

class trangleArea
{
 int width;
 int height;

public:
 void setWidth(int a)
 {
  width=a;
 };

 void setHeight(int b)
 {
  height=b;
 };

 float area()
 {
  return 0.5*width*height;
 };
};

int main(void)
{
 int a, b;

 cout<<"가로길이를 입력하세요:";
 cin>>a;
 cout<<"세로길이를 입력하세요:";
 cin>>b;
 
 trangleArea area;

 area.setHeight(b);
 area.setWidth(a);
 cout <<"삼각형의 넓이는" << area.area() << "입니다";

 return 0;
}

설정

트랙백

댓글

팩토리얼

전전컴/C++ 2011. 1. 16. 21:22


#include <iostream.h>


int getFACT(int n)
{
 if(n==1)
 {
  return 1;
 }
 else
 {
  return n*getFACT(n-1);
 }
}

int main(void)
{
 int a;
 int result;
 cin>>a;
 if(a==0)
  result=1;
 else
 result=getFACT(a);

 cout <<a<<"까지의 팩토리얼은은"<<result<<"입니다";

 return 0;
}

설정

트랙백

댓글


#include <iostream.h>


int getSUM(int n)
{
 if(n==1)
 {
  return 1;
 }
 else
 {
  return n+getSUM(n-1);
 }
}

int main(void)
{
 int a;
 int result;
 cin>>a;
 result=getSUM(a);

 cout <<a<<"까지의 합은"<<result<<"입니다";

 return 0;
}

설정

트랙백

댓글