问题描述:
设计一个能身测试高体重是否标准的面向对象的程序,然后我与陆云杰同学一同完成。结对编程的过程很棒,在这里对云杰同学表示感谢!
代码:
#include
#include "Test.h" using namespace std; void fun_out(double W,double w); int main() { double h,w; char s; while(1) { cout<<"请输入身高,体重,性别(m(男性)f(女性)):"; cin>>h>>w>>s; if(h==0&&w==0&&s=='0') break; Test t(h,w,s); t.fun(); cout<<"请继续输入测试!(输入'0 0 0'退出)"<
#ifndef TEST_H #define TEST_H class Test { private: double height; double weight; char sex; public: Test(double h=0,double w=0,char s='a'):height(h),weight(w),sex(s) {}; void fun(); }; #endif // TEST_H
#include "Test.h" #include
using namespace std; void fun_out(double W,double w); void Test::fun() { double Weight; if(sex=='m') { Weight=height-100; } else Weight=height-105; fun_out(Weight,weight); }; void fun_out(double W,double w) { if(w>W*1.2) cout<<"您超重了!"<
运行结果:

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/228707.html原文链接:https://javaforall.net
