'개발자/C++'에 해당되는 글 2건

#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
블로그 이미지

김진리

,

#include <iostream>

using namespace std;

int main() {

cout << "Hellow World!";

return 0;

}







#include <iostream>  : c++ 에 있는 입출력을 위한 헤더파일 ( input / output stream) 입출력 스트림

using namespace std : c++ 표준에서 제공하는 다양한 요소들은 namespace std 안에 선언되어 있어 cout를 사용 할 수 있다.

using namespace std 가 존재 하지 않는 경우 


위와 같이 std:: 를 사용해주어야 한다. std 를 선언하므로써 축약이 가능


cout  : (console output) 화면에 출력

같이 쓰는 명령어 

cout << "Hellow World!" << endl;


endl : (End Line) 줄의 끝 , new line으로 시작


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

C++ 클래스와 객체 사용법  (0) 2015.02.12
블로그 이미지

김진리

,