1、代码如下:

#include #include

using namespace std;

int main() { char *strSource = "AABADCDABDEA"; int len = strlen(strSource); for (int i = 0; i < len; i++) { if (strSource[i] == 'A') { strSource[i] = 'C'; } } cout << strSource << endl; return 0; }

2、代码如下:

#include

using namespace std;

class Time { private: int hour; int minute; int second;

public: Time() { hour = 0; minute = 0; second = 0; }

Time(int h, int m, int s) {
    hour = h;
    minute = m;
    second = s;
}

void set(int h, int m, int s) {
    hour = h;
    minute = m;
    second = s;
}

int getHour() {
    return hour;
}

int getMinute() {
    return minute;
}

int getSecond() {
    return second;
}

void display() {
    cout << hour << ":" << minute << ":" << second << endl;
}

bool equal(Time &other_time) {
    if (hour == other_time.getHour() && minute == other_time.getMinute() && second == other_time.getSecond()) {
        return true;
    }
    else {
        return false;
    }
}

void increment() {
    second++;
    if (second >= 60) {
        second = 0;
        minute++;
        if (minute >= 60) {
            minute = 0;
            hour++;
            if (hour >= 24) {
                hour = 0;
            }
        }
    }
}

bool less_than(Time &other_time) {
    if (hour < other_time.getHour()) {
        return true;
    }
    else if (hour == other_time.getHour() && minute < other_time.getMinute()) {
        return true;
    }
    else if (hour == other_time.getHour() && minute == other_time.getMinute() && second < other_time.getSecond()) {
        return true;
    }
    else {
        return false;
    }
}

};

int main() { Time t1(10, 30, 45); Time t2; t2.set(23, 59, 59); t1.display(); t2.display(); t1.increment(); t1.display(); cout << "t1 equal t2: " << t1.equal(t2) << endl; cout << "t1 less than t2: " << t1.less_than(t2) << endl; return 0;

1、10分编写程序将char strSource =AABADCDABDEA中的A全部替换成C。2、20 分定义一个时间类 Time它能表示 24 小时制的时、分、秒具体要求如下1 提供默认构造函数 Time 0将时、分、秒都初始化成 0。2提供构造函数 Timeint hint mint s。3提供成员函数 setint hint mint s功能是调整时间。4能够分别获取时、分、秒信息。5 提

原文地址: https://www.cveoy.top/t/topic/fjPD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录