霍格沃兹学院c++课后习题
Love 6
腾讯WXG在职后台小鹅
展开
-
C++课后作业 32. vector向量的使用
vector向量的使用原创 2022-06-07 17:25:51 · 241 阅读 · 0 评论 -
C++课后作业 31. 容器和游标的使用
容器和游标的使用原创 2022-06-07 17:18:38 · 393 阅读 · 0 评论 -
C++课后作业 30. 输入输出流课堂练习:美丽的蛇形方阵
美丽的蛇形方阵原创 2022-06-06 19:35:44 · 279 阅读 · 0 评论 -
C++课后作业 29. 教材习题11_6:定义一个Dog类用文件读写对象
定义一个Dog类用文件读写对象原创 2022-06-06 19:17:39 · 325 阅读 · 0 评论 -
C++课后作业 28. 教材习题11_8:整数不同进制转换输出
整数不同进制转换输出原创 2022-06-06 19:15:23 · 215 阅读 · 0 评论 -
C++课后作业 27. 教材习题10_5:约瑟夫问题
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>#include <vector>using namespace std;int main() { vector<int> a; int n, m, x = 0; cout << "Input n and m:"; cin >> n >> m; a.resize(n); for (int i = 0;原创 2022-05-27 00:13:32 · 280 阅读 · 0 评论 -
C++课后作业 26. 教材习题10_8:统计单词曾经出现的次数
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>#include <string>#include <set>using namespace std;int main() { multiset<string> arr; string s; cin>>s; while (s != "#" ) { int times=0; times = arr.co原创 2022-05-26 23:44:16 · 243 阅读 · 0 评论 -
C++课后练习 25. 重载运算符为友元函数,实现分数的运算
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>#include <cmath>using namespace std;class CFraction { public: CFraction(int nu=0,int de=1):nume(nu),deno(de) {} void simplify(); //输入输出的重载 friend istream &operator>原创 2022-05-24 10:22:31 · 749 阅读 · 0 评论 -
C++课后练习 24. 运算符重载为成员函数,实现分数的运算
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>#include <math.h>using namespace std;int GetFactor(int up, int down) { int factor = 1; for (int i = 2; i <= min(up, down); ++i) { if (!(up % i) && !(down % i)) {原创 2022-05-24 09:59:09 · 282 阅读 · 0 评论 -
C++课后作业 23. 模板课堂练习
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>#include <cmath>using namespace std;class Complex { public: Complex() : real_(0), imag_(0) {} Complex(const double& real, const double& imag) : real_(real), imag_(imag)原创 2022-05-20 17:48:59 · 206 阅读 · 0 评论 -
C++课后作业 22. 教材习题9_1:利用数组类模板Array解决学生成绩问题
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>using namespace std;int main() { double scores[100]; int n; cout << "Input n:"; cin >> n; cout << "Input scores:"; for (int i = 0; i < n; ++i) { cin >>原创 2022-05-20 17:36:58 · 241 阅读 · 0 评论 -
C++课后作业 21. 教材习题9_10:利用插入排序函数模板进行排序
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>using namespace std;int data[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20};int main() { int len = sizeof(data) / sizeof(int); for原创 2022-05-20 17:28:39 · 266 阅读 · 0 评论 -
C++课后作业 20. 运算符重载课堂练习:分钟秒钟的时间相减
文章目录前引原题题目代码实现提交结果前引感觉有点像C++智商训练营了原题题目代码实现#include <iostream>using namespace std;#define N 100class CTime { public: CTime() : minutes_(0), seconds_(0) {} CTime(const int& minutes__, const int& seconds__) : minutes_原创 2022-05-14 17:54:41 · 532 阅读 · 0 评论 -
C++课后作业 19. 教材习题8_7:对类Point重载自增和自减运算符
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>using namespace std;class Point { public: Point() : x_(0), y_(0) {} Point(const int x__, const int y__) : x_(x__), y_(y__) {} Point(const Point& other) { x_ = other.x_; y原创 2022-05-14 17:35:25 · 715 阅读 · 0 评论 -
C++课后习题 18. 教材习题8_8:基类BaseClass派生出类DerivedClass
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>using namespace std;class BaseClass { public: virtual void fn1() const { cout << "BaseClass:fn1()" << endl; } void fn2() const { cout << "BaseClass:fn2()" <<原创 2022-05-11 21:57:28 · 519 阅读 · 0 评论 -
C++课后习题 17. 教材习题8_5:编写一个哺乳动物类Mammal
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>using namespace std;class Mammal { public: virtual void speak() const = 0;};class Dog : public Mammal { public: virtual void speak() const override { cout << "Dog is speaking原创 2022-05-11 21:52:43 · 804 阅读 · 0 评论 -
C++课后习题 16. 教材习题7_11:基类BaseClass派生出类DerivedClass
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>using namespace std;class BaseClass { public: void fn1() const { cout << "BaseClass:fn1()" << endl; } void fn2() const { cout << "BaseClass:fn2()" << endl; }};clas原创 2022-04-27 22:24:11 · 1459 阅读 · 0 评论 -
C++课后习题 15. 教材习题7_15:下面的程序能得到预期的结果吗
文章目录原题题目代码实现提交结果原题题目代码实现#include <iostream>using namespace std;struct Base1 {int x;};struct Base2 {float y;};struct Derived : Base1,Base2{};int main(){ Derived *pd=new Derived; pd->x=1;pd->y=2.0f; Base2 *pb =原创 2022-04-27 22:01:19 · 1670 阅读 · 0 评论 -
C++课后习题 14. 定义一个员工类、经理类、销售员类和销售经理类
文章目录前引原题题目代码实现提交结果前引✌ 费劲千辛万苦花了我一周的时间 终于精心打磨出来的旷世巨作作业我打算取名字为《定义一个员工类、经理类、销售员类和销售经理类》哇呜 炫酷大气的名字 华尔不实的内在 一塌糊涂的排版 垃圾中的垃圾的代码规范 不按规章的构造方式哈哈 我简直太佩服我自己了 花了一周的时间就把这个做出来了我太佩服我自己了 哈哈为了奖励我自己 我决定 我要再做一道这样的好题 哈哈!太好了本来下面写了一千多个字 骂了很多东西 都被我删掉了出这样的题目 写出这样的代码 误原创 2022-04-26 13:19:17 · 738 阅读 · 1 评论 -
C++课后习题 13. 修改下面的4个类,添加析构函数
文章目录前引原题题目代码实现提交结果前引天天做傻子题被当做傻子乐可惜傻子并不清楚自己是傻子每天乐呵呵的 呵呵~ 呵呵~ 过的好开心 呵呵~ 呵呵~每天以做傻子题为乐上傻子课为终极目标如果不上课 感觉如坐针毡一般 上傻子课才是对自己的终极救赎如果可以一直这样上傻子课的话 那该多好啊可惜傻子课快要上完了 很可惜的告诉你没多久傻子课可以学了 好好的自我麻痹 好好的珍惜这段可以上傻子课时光吧以后可再也没有这样的机会咯话很黑 话很直但就是事实原题题目代码实现作呕的题目排原创 2022-04-26 12:28:39 · 1192 阅读 · 0 评论 -
C++课后习题 12. 教材习题7_10:定义一个Object类和Box类
文章目录前引原题题目代码实现填入数据提交结果前引今天看到某乎对霍格沃兹学院的评价看到一条评论真是给我整笑了提问:霍格沃兹学院毕业出来的学生竞争力如何?回答:大概率进富士康哈哈哈哈 现在发现已经不是梦了做四年这样的题目 就可以直接领包入住了大厂入职(富士康) 不是梦 来这里读书 就一个字 赢✌!原题题目代码实现#include <iostream>#include <string>using namespace std;class Obje原创 2022-04-13 21:24:39 · 393 阅读 · 0 评论 -
C++课后作业 12. 教材习题7_8:定义一个Document类和Book类
文章目录前引原题题目代码实现提交结果前引敢不敢出一些小学生做不起的题啊这么有挑战 这么有质量 幼儿园的小朋友看了都笑了很怀疑这里是不是梵蒂冈C++课程特训 还是低等智商康复院给康复患者做的题不想出可以不出 哪怕抄人家北大的C++的题 去做其他大学的OJ都行啊 水平不行 对自己有个清楚定位 花钱用别人的题行不行原题题目代码实现#include <iostream>#include <string>using namespace std;clas原创 2022-04-13 21:02:21 · 937 阅读 · 0 评论 -
C++课后作业 11.教材习题6_20:实现一个简单圆类
文章目录前引原题题目代码实现填入数据提交结果前引这里浅浅的提一句作为C++程序员 现在应该尽量不出现 如果是动态分配的内存 应该是用智能指针包裹起来的 尽量不出现原始指针的情况这里没有办法添加<memory>头文件 不然的话这里使用unique_ptr<float>应该是更合适的 就不用手动delete了原题题目代码实现#include <iostream>using namespace std;const float pi = 3.原创 2022-04-06 21:30:57 · 1830 阅读 · 0 评论 -
C++课后作业 10.教材习题7_6:哺乳动物类Mammal派生出狗类Dog
文章目录原题题目代码实现填入数据提交结果原题题目代码实现#include <iostream>#include <string>using namespace std;class Mammal { public: Mammal(string name) : name(name) { cout << "Con.Mammal" << endl; } ~Mammal() { cout <<原创 2022-04-06 21:14:37 · 1463 阅读 · 0 评论 -
C++课后作业 9.教材习题7_5:Shape类派生Rectangle和Circle类
文章目录原题题目代码实现验证结果原题题目代码实现#include <iostream>using namespace std;class Shape { public: virtual double getArea() const = 0;};class Rectangle : public Shape { public: Rectangle() : length_(0), width_(0) {} Rectangle(const double&am原创 2022-04-06 21:06:51 · 743 阅读 · 0 评论 -
C++课后作业 8. 教材习题5_13:定义类X,Y,Z,按要求实现友元
文章目录原题题目代码实现填入数据验证结果原题题目代码实现#include <iostream>using namespace std;class X;class Y{ public: void g(X &x);};class Z{ public: void f(X &x);};class X{ public: X(int i):i(i){} friend void Y::g(X &原创 2022-03-30 23:45:13 · 1046 阅读 · 0 评论 -
C++课后作业 7.教材习题5_14:定义Boat与Car两个类,友元计算总重量
文章目录原题题目代码实现验证结果原题题目代码实现#include <iostream>using namespace std;class Boat { class Car; public: Boat() { cout << "Input boat weight:"; cin >> weight_; } const int weight() const { return weight_; } friend v原创 2022-03-30 23:36:35 · 887 阅读 · 3 评论 -
C++课后作业 6.教材习题5_7:利用静态变量统计小猫Cat的数量
文章目录前引原题题目代码实现验证结果前引y1s1 我确实对静态函数和静态成员用的比较少除了前段时间 自己写一个多进程的toy_server的时候为了让信号处理正常 自己用了singleton模型 然后才用了一个静态成员外 几乎没怎么再用古静态成员 静态函数了个人觉得 这种题目设计出来的意义呢 有意义吗 哈哈 可能有点吧但是不是类似于 教大学生学习加减乘除 非要一步一步的跟教婴儿一样的 有意义吗 之所以每次在前引中吐槽 是因为对这所学校的教学质量 课程设计的不满而所觉得失望 觉得无语我也希望原创 2022-03-23 21:20:20 · 1910 阅读 · 2 评论 -
C++课后作业 5. 教材习题4_20:定义满足要求的复数类Complex类
文章目录前引原题题目代码实现验证结果前引难绷原题题目代码实现#include <iostream>using namespace std;class Complex{ private: int real; int imag; public: Complex():real(0),imag(0) {} Complex(const int& _real = 0, const int& _imag = 0):real(_real),i原创 2022-03-17 23:35:49 · 876 阅读 · 0 评论 -
C++课后作业 4.教材习题4_9:通过屏幕两点确定矩形类Rectangle
文章目录前引原题题目代码实现验证结果前引哎 乌鱼子 又浪费我的时间 写这几道题 发博客把我的是间就当是有价值的吧原题题目代码实现#include <iostream>#include <memory>using namespace std;class Rectangle{ private: double l1; double l2; double r1; double r2; public: Rectangle():l1原创 2022-03-17 23:22:06 · 1192 阅读 · 0 评论 -
C++课后作业 3. 教材习题4_8:定义Dog类,包含age和weight信息
文章目录前引原题题目代码实现验证结果前引无语 真的跟着学校c++学出去估计 找工作直接被饿死 不如直接进厂上班 属实是dog了原题题目代码实现#include <iostream>using namespace std;class Dog{private: int age; double weight;public: Dog():age(0),weight(0) {} Dog(const int& _age,cons原创 2022-03-09 21:46:13 · 1136 阅读 · 1 评论 -
C++课后作业 2. 教材习题4_13:定义Circle类并计算面积
文章目录前引原题题目代码实现前引不支持auto stoi函数不支持 啥都不支持 你这个online judge说真的不如不做 还计算机B+ 我属实是流汗大黄豆了能早点跑路就早点跑路了 兄弟们 只能这样说了原题题目代码实现#include <iostream>#include <string>using namespace std;static double pai = 3.14;class Circle{private: doub原创 2022-03-09 21:29:41 · 338 阅读 · 0 评论 -
C++课后作业 1. 输出字符串,hello,霍格沃兹学院(第一次作业 内含闲聊)
文章目录前引原题题目代码实现提交结果前引哈哈 作为笔者 说实话 笔者学到现在 才真的感觉到了一种无可奈何 和 一种必须抗于压力去做很多事情的感觉第一个无可奈何 是对霍格沃兹学院的教学水平 感到深深的无力 尽管笔者的C++水平 现在还没有开始起步做一些很大型的项目 但是应该来说可以超过百分之八九十的C++ user 笔者在c++上要走的路还有很多…对于C++很多STL、内存分配的底层设计 虚函数、继承、多态等等知识 自己也是花了大量时间去学习 笔者前段时间自己也花了很大的功夫去学习 去阅读相关源原创 2022-03-02 21:14:07 · 617 阅读 · 5 评论