C++作业

1、思维导图:

2、模板类的课上练习

cpp 复制代码
#include <iostream>
#include <stdexcept>
using namespace std;
template <typename T, int MAXSIZE>
class Stack {
private:
    T data[MAXSIZE];
    int top;
public:
    Stack() : top(-1) {}
    bool isEmpty() const {
        return top == -1;
    }
    void push(const T& x) {
        if (top == MAXSIZE - 1) {
            cout<<"stack full"<<endl;
        }
        data[++top] = x;
    }
    void pop() {
        if (isEmpty()) {
           cout<<"stack empty"<<endl;
        }
        top--;
    }
};
int main() {
    Stack<int, 10> s;
    try {
        s.push(1);
        s.push(2);
        s.push(3);
    } catch (const exception& e) {
        cout << "Error: " << e.what() << endl;
    }
    return 0;
}

3、异常处理的代码重新写一遍

相关推荐
tachibana21 小时前
与其他语言相比,使用 Go 有什么好处?
开发语言·后端·golang·go
阿俊-全栈开发5 小时前
LikeShop 单商户SaaS商城分销模块二开:佣金计算与结算逻辑实现
java·开发语言·微服务·likeshop·likeshop开源商城·likeshop多商户
weixin_424183618 小时前
开放—封闭原则实战(下):基于策略的流程编排与编译期多态
c++·分布式·系统架构
wuminyu8 小时前
C++协程实现接收端的零拷贝Buffer管理原理剖析
java·linux·c语言·jvm·c++
m0_380743879 小时前
C++中的freopen的用法实例详解
开发语言·c++
Escalating_xu9 小时前
【Python】基础语法(1):常量、变量、类型、输入输出与运算符
开发语言·python
jimy110 小时前
polymorph.cpp里面的“析构函数、智能指针”问题
开发语言·c++
m0_3807438710 小时前
PHP 8.3 缓存清除不生效怎么排查
开发语言·php
朝朝辞暮i10 小时前
C++ 第 6 课:switch —— 多状态选择
开发语言·c++·算法
小凡geo10 小时前
本地商家 GEO:用脚本一键生成 FAQPage 结构化数据,让 AI 切片更稳
开发语言·人工智能·python·microsoft·搜索引擎·ai