java小程序体重监测,一个计算标准体重的小程序

匆匆忙忙,弄了一个计算身高的程序。实现这么简单的功能不需要100多行,这样写趁机熟悉一下C++的对象。当然程序还可以优化。不高兴写了,这个东西再写下去有点儿无聊。

#include

//这是一个简单的程序,用来测试身材,用指针操作对象;

using namespace std;

enum Choice{

ShowMenu=1,

SetInfo,

ShowCalc,

Help,

Quit

};

class Human

{

public:

Human(int Age,double Height,double Weight);

~Human();

void SetAge(int Age){ItsAge=Age;}

void SetHeight(double Height) {ItsHeight=Height;}

void SetWeight(double Weight) {ItsWeight=Weight;}

void SetSex(int Sex) {ItsSex=Sex;}

int GetAge() const {return ItsAge;}

double GetHeight() const {return ItsHeight;}

double GetWeight() const {return ItsWeight;}

int GetSex() const {return ItsSex;}

private:

int ItsAge,ItsSex;

double ItsHeight;

double ItsWeight;

};

Human::Human(int a,double h,double w){

ItsAge=a;

ItsHeight=h;

ItsWeight=w;

}

Human::~Human(){}

Human *PM;

int DoMenu();

void DoInput();

void DoCalc();

void DoInfo();

void DoHelp();

void main(){

PM = new Human(24,172,86);

int Choice=ShowMenu;

int FQuit=false;

while(!FQuit)

{

int Choice=DoMenu();

if (ChoiceQuit){

cout<

continue;

}

switch (Choice)

{

case ShowMenu:

DoMenu();

break;

case SetInfo:

DoInput();

break;

case ShowCalc:

DoCalc();

break;

case Help:

DoHelp();

break;

case Quit:

FQuit=true;

cout<

break;

}

}

delete PM;

PM=0;

}

void DoInput(){

int A,S;

double H,W;

cout<

cin>>A;

cout<

cin>>H;

cout<

cin>>W;

cout<

cin>>S;

if ((A>100) || (A<1) || (H>250) || (H<40) || (W>200) || (W<2) || (S!=1 && S!=0))

{

cout<

}

else{

PM->SetAge(A);

PM->SetHeight(H);

PM->SetWeight(W);

PM->SetSex(S);

cout<

}

}

void DoCalc(){

int A,S;

double H,W,Rate;

A=PM->GetAge();

H=PM->GetHeight();

W=PM->GetWeight();

S=PM->GetSex();

(H<165 && S==1)?(H-=105):(H-=100);

S==1?H=H*0.9:H=H*0.9-2.5;

Rate=H/((*PM).GetAge());

cout<GetWeight()<

}

void DoInfo(){

cout<

}

void DoHelp(){

cout<

}

int DoMenu(){

int Choice;

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cin>>Choice;

return Choice;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值