본문 바로가기
Language/C++ & openGL

C++ powerC++ p404 LAB box 클래스 setter getter 함수

by javapp 자바앱 2019. 1. 9.
728x90

#include <iostream>

#include <string>


using namespace std;



class Box {

private:

int width, length, height;

int v;

public:

void setwidth(int w);

int getwidth(); //접근자

void setlength(int l);

int getlength(); //접근자

void setheight(int h);

int getheight(); //접근자



int getVolume();

void get_input();

void print();

};


void Box::setwidth(int w)

{

width = w;

}

int Box::getwidth()

{

return width;

}

void Box::setlength(int l)

{

length = l;

}

int Box::getlength()

{

return length;

}

void Box::setheight(int h)

{

height = h;

}

int Box::getheight()

{

return height;

}



int Box::getVolume() //부피 계산

{

v = width * length*height;

return v;

}



void Box::get_input()

{

cout << "가로 세로 높이 입력 : ";

cin >> width >> length >> height;

v = width * length*height;

}


void Box::print()

{

cout << "부피는 " << v << endl;

}


int main(void)

{

Box box1;                            //객체 선언


box1.setwidth(10);                //10으로 디폴트 지정

box1.setlength(10);

box1.setheight(10);


box1.getVolume();

box1.print();


box1.get_input();                    //입력

box1.print();


return 0;

}


댓글