#include <iostream>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */




class Bmi {     Bmi 클래스의 선언 마지막에는 세미콜론으로 닫아준다.

public :   public 형의 변수선언

int weight;

int tall;

double getBMI();

};

Bmi 클래스의 함수 구현

double Bmi::getBMI(){

return weight/((tall*tall)/10000);  Bmi 클래스 안의 변수 사용

}


int main() {

Bmi bmi;   자바와 다르게 변수 선언으로 객체가 생성!!

bmi.weight = 71;

bmi.tall   = 180;

cout << "비만도는  " <<  bmi.getBMI() << endl;

return 0;

}




결과값



자바와 다르게 변수가 선언되면 객체가 생성되어 메모리에 할당된다.

'개발자 > C++' 카테고리의 다른 글

C++ hellow world 시작 하기  (0) 2015.02.12
블로그 이미지

김진리

,