실습과제 모음

cpp 실습

TanSanC 2014. 1. 15. 14:02

#include <iostream>

using namespace std;



class WeightControl

{

private:

double  height, weight;

int  WeightStatus;

public:

void  setHeight(const double h);

void  setWeight(const double w);

double  getHeight();

double  getWeight();

int  StdWeight();

int  getWeightStatus();

};

int main()

{

WeightControl wc;

wc.setHeight(170);

wc.setWeight(80);

wc.StdWeight();

cout << wc.getWeightStatus() << endl;

return 0;

}



void  WeightControl::setHeight(const double h)

{

if ( h > 0)

{

height = h;

}

else

{

height = 150;

}

}

void  WeightControl::setWeight(const double w)

{

//  0 < weight 조건

if ( w > 0)

{

weight = w;

}

else

{

weight = 60;

}

}

double  WeightControl::getHeight()

{

return height;

}

double  WeightControl::getWeight()

{

return weight;

}


int  WeightControl::StdWeight()

{

if ( (height - 100) < weight )

{

WeightStatus = 1;

}

else

{

WeightStatus = 0;

}

WeightStatus = -1;

return 0;

}

int  WeightControl::getWeightStatus()

{

return WeightStatus;

}