






















#include <iostream>
#include <string>
using namespace std;
class teacher {
// 私有成员变量
string name;
float salary; // 月薪
float money; // 奖金
string date; // 入职日期
public:
// 无参构造函数
teacher() {
name = "unknown";
salary = 0;
money = 0;
date = "0";
}
// 带参构造函数(已修复!)
teacher(string n, float s, float m, string d) {
name = n; // 正确赋值
salary = s;
money = m;
date = d;
}
// 输入信息
void input() {
cout << "请输入姓名:";
cin >> name;
cout << "请输入月薪:";
cin >> salary;
cout << "请输入奖金:";
cin >> money;
cout << "请输入入职日期:";
cin >> date;
}
// 计算月总收入
float cmonth() {
return salary + money;
}
// 计算年薪(修复:添加return)
float cyear() {
return cmonth() * 12;
}
// 显示所有信息(修复:完整输出)
void disp() {
cout << "\n===== 教师信息 =====" << endl;
cout << "姓名:" << name << endl;
cout << "入职日期:" << date << endl;
cout << "月薪:" << salary << endl;
cout << "奖金:" << money << endl;
cout << "月总收入:" << cmonth() << endl;
cout << "年薪:" << cyear() << endl;
cout << "====================\n" << endl;
}
};
// 主函数(修复逻辑)
int main() {
teacher t;
int a;
while (true) { // 更清晰的循环
cout << "退出请按 1,继续输入请按 2:";
cin >> a;
if (a == 1) {
cout << "已退出程序" << endl;
break;
}
if (a == 2) {
t.input(); // 输入
t.disp(); // 显示
}
}
return 0;
}
#include <iostream>
#include <cstdint> // C++20 固定宽度整数类型
#include <stdexcept> // 异常处理
// C++20 constexpr:允许编译期计算阿克曼函数
// uint64_t:64位无符号整数,防止数值溢出
constexpr uint64_t ackermann(uint64_t m, uint64_t n)
{
// 限制输入范围,避免栈溢出/计算爆炸
if (m > 4) {
throw std::invalid_argument("m 不能大于 4,否则计算量极大且会栈溢出!");
}
// 阿克曼函数标准定义
if (m == 0) {
return n + 1;
}
else if (n == 0) {
return ackermann(m - 1, 1);
}
else {
return ackermann(m - 1, ackermann(m, n - 1));
}
}
int main()
{
try {
std::cout << "=== C++20 阿克曼函数演示 ===" << std::endl;
// 编译期计算(C++20 新特性)
constexpr auto a0 = ackermann(0, 5);
constexpr auto a1 = ackermann(1, 5);
constexpr auto a2 = ackermann(2, 3);
constexpr auto a3 = ackermann(3, 4);
std::cout << "ackermann(0, 5) = " << a0 << '\n';
std::cout << "ackermann(1, 5) = " << a1 << '\n';
std::cout << "ackermann(2, 3) = " << a2 << '\n';
std::cout << "ackermann(3, 4) = " << a3 << '\n';
// 注意:ackermann(4, 1) 已经非常大
// ackermann(4, 2) 数值巨大,计算极慢
}
catch (const std::exception& e) {
std::cerr << "错误:" << e.what() << '\n';
return 1;
}
return 0;
}
https://github.com/TheAlgorithms
Professional Parallel Programming with C#: Master Parallel Extensions with .NET 4
https://www.wiley.com/en-us/Professional+Parallel+Programming+with+C%23%3A+Master+Parallel+Extensions+with+.NET+4-p-9780470495995#downloadstab-section
https://github.com/shtigran/Async-Programming
https://github.com/ltd-ARYAN-pvt/Introduction-to-Parallel-Processing-and-Asynchronous-Programming
https://github.com/SaladinoBelisario/Parallel-And-Asynchronous-Java
https://github.com/thanhit95/multi-threading
https://github.com/SalehAhmadi/parallel-programming-csharp
https://github.com/PacktPublishing/Asynchronous-Programming-with-CPP
https://github.com/djeada/Parallel-and-Concurrent-Programming
https://github.com/raymondino/Csharp-multithreading
https://github.com/Alejoho/Tutorial-of-Multithreading-Asynchronous-Programming-in-CSharp-NET-8-2024-Parallel-Programming
https://github.com/zahi1/Concurrent-Programming
https://github.com/PacktPublishing/Mastering-Concurrency-in-Python
https://github.com/jeremybytes/async-workshop-2024
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。