求大神解答这道C++编程题,谢谢~(我刚开始学,很多基础题都不会做,求帮忙解答)

如题所述

//#include "stdafx.h"//If the vc++6.0, with this line.
#include <iostream.h>
#include <iomanip.h>
class Time{
    public:
        Time(int hour,int minu,int seco){
            h=hour,m=minu,s=seco;
        }
        void myshow(void){
            cout << setw(2) << setfill('0') << h << ':';
            cout << setw(2) << setfill('0') << m << ':';
            cout << setw(2) << setfill('0') << s << endl;
        }
    private:
        int h,m,s;
};
int main(int argc,char *argv[]){
    int h,m,s;
    cout << "Input hours, minutes & seconds:\n";
    cin >> h >> m >> s;
    Time t(h,m,s);
    t.myshow();
    return 0;
}

追问

谢谢~

可以再问你一道题吗?求圆柱体体积的~

追答

说吧……

追问

求解答

你好,做出来了吗?

追答

刚才不在。这种题你照猫画虎就可以了……

//#include "stdafx.h"//If the vc++6.0, with this line.
#include <iostream>
using namespace std;
#define pai 3.14
class CYLINDER{
    public:
        CYLINDER(double radius,double high){
            h=high,r=radius;
        }
        double getvolume(void){
            return pai*r*r*h;
        }
    private:
        int h,r;
};
int main(int argc,char *argv[]){
    int h,r;
    cout << "Please enter the radius and high:\n";
    cin >> r >> h;
    CYLINDER t(r,h);
    cout << t.getvolume() << endl;
    return 0;
}

追问

好的,谢谢

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网