3.13 c++ 类的声明定义 第八章习题

#include<iostream>
using namespace std;
class xtime
{
public:
    void set_time();
    void show_time();
private:
    int hour;
    int minute;
    int sec;
};

xtime t;

void xtime::set_time()
{
    cin >> t.hour;
    cin >> t.minute;
    cin >> t.sec;
}

void xtime::show_time()
{
    cout << t.hour << ":" << t.minute << ":" << t.sec << endl;
}

int main()
{
    t.set_time();
    t.show_time();
    system("pause");
    return 0;
}

头文件

#include<iostream>
using namespace std;
class Array_max
{
public:
    void set_value();
    void max_value();
    void show_value();
private:
    int array[10];
    int max;
};

源文件1

#include"arraymax.h"
using namespace std;
void Array_max::set_value()
{
    int i;
    for (i = 0; i < 10; i++) cin >> array[i];
}
void Array_max::max_value()
{
    int i;
    max = array[0];
    for (i = 1; i < 10; i++)
        if (array[i] > max)max = array[i];
}
void Array_max::show_value()
{
    cout << "max=" << max;
}

源文件2

#include"arraymax.h"
using namespace std;
int main()
{
    Array_max arrmax{};
    arrmax.set_value();
    arrmax.max_value();
    arrmax.show_value();
    system("pause");
    return 0;
}

#include<iostream>
using namespace std;
class cube
{
public:
    void set_l();
    void show_l();
private:
    int c;
    int k;
    int g;
};
void cube::set_l()
{
    int i;
    cin >>c>>k>>g;
}
void cube::show_l()
{
    cout << "vol=" << c*k*g;
}
int main()
{
    cube f1{}, f2{}, f3{};
    f1.set_l();
    f1.show_l();
    f2.set_l();
    f2.show_l();
    f3.set_l();
    f3.show_l();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值