(一)
1.默认构造,输出Constructor called
2.copy构造,输出Copy constructor called
3.参数构造,输出Constructor called
4.两个参数构造,输出Constructor called
Constructor called
5.参数构造divide1,输出Constructor called
6.copy d1 和d2,输出Copy constructor called
Copy constructor called,
参数构造result,输出Constructor called
copy构造divide2,输出Copy constructor called

#include  <iostream>
using namespace std;
class Fraction {//数据成员,访问控制属性默认是私有int  m_numerator = 0; // 分子默认为0; C++11int  m_denominator = 1; //分母默认为1;
public://公有成员函数int   getdenominator()const { return m_denominator; }//(2.3)(获取分母分子)int   getnumerator()const { return m_numerator; }Fraction(int above = 0, int below = 1) :m_numerator(above), m_denominator(below) {cout << "Constructor called" << endl;}Fraction(const Fraction& rhs) : m_numerator(rhs.m_numerator), \m_denominator(rhs.m_denominator) {cout << "Copy constructor called" << endl;}~Fraction() {cout << "Destructor of Fraction" << endl;//(1)(显示析构函数)}Fraction yuefen() {int yueshu = qiuyueshu(m_numerator, m_denominator);m_numerator /= yueshu;m_denominator /= yueshu;Fraction result(m_numerator, m_denominator);return result;//(4)约分}int qiuyueshu(int x,int y) {if (x == y) return x;if (x % y == 0) {return y;}else {int e = x % y;x = y;y = e;return qiuyueshu(x, y);}}Fraction tongfen(const Fraction& a, const Fraction& b) {//(5) 通分Fraction buzou1(a.getnumerator() * b.getnumerator(), a.getdenominator() * b.getdenominator());Fraction result(buzou1.getnumerator()/qiuyueshu(buzou1.getnumerator(), buzou1.getdenominator()),buzou1.getnumerator()/ qiuyueshu(buzou1.getdenominator(), buzou1.getnumerator()));return result;}
};Fraction operator/(const Fraction&left,const Fraction&right) {// (6)重载/Fraction result(left.getnumerator() * right.getdenominator() / left.getdenominator() * right.getnumerator());return result;
};
Fraction divide1(const Fraction& divident, const Fraction& divisor) {return Fraction(divident.getnumerator() * divisor.getdenominator(), \divident.getdenominator() * divisor.getnumerator());
}
Fraction divide2(Fraction divident, Fraction divisor) {Fraction result(divident.getnumerator() * divisor.getdenominator(), \divident.getdenominator() * divisor.getnumerator());return result;
}
int main() {Fraction a;
Fraction b(a);
Fraction c = Fraction(3, 2);
Fraction d1(2, 3), d2(4, 5);
Fraction e1 = divide1(d1, d2);
Fraction e2 = divide2(d1, d2);
}

第二题

#include <iostream>
#include <vector>
using namespace std;
int a[5] = { 19,67,24,11,17 }, b[5] = { 2,3,9,17,59 };
int main() {int find=17;for (int i = 0; i < 5; i++) {if (a[i] == find) {cout << "a." << i + 1 << endl;//顺序查找}}int small = 0, big = 4;for (int i = 0; 1;i++) {int m = (small + big) / 2;//折中查找if (b[m] == 17) {cout <<"b."<< m+1<<endl; break;}if (b[m] > 17) {big = m;}if (b[m] < 17) {small = m+1;}}vector <int>c1;for (int i = 0; i < 5; i++) {//将a、b中的素数合并到c1中int x = a[i],c=0,d=0;for (int b=2;b<x;b++) {if (x % b == 0) {c = c + 1;break; }}if (c == 0) {c1.push_back(a[i]);}for ( int e = 2; e < x; e++) {if (x % e == 0) {d = d + 1;break;}}if (d == 0) {c1.push_back(b[i]);}}for (int i = 0; i < c1.size(); i++) {//查重并删去cout << c1[i] << " ";}cout << endl;for (int i = 0; i < c1.size();i++) {int a = c1[i]; for (int c=i+1; c < c1.size(); c++) {int b = c1[c];if(b==a){c1.erase(c1.begin()+i);}}}       for (int i = 0; i < c1.size(); i++) {cout << c1[i] << " ";}cout << endl;for (int i = 0; i < c1.size(); i++) {//冒泡排序for (int j = 0; j < c1.size()-1; j++) {if (c1[j] > c1[j + 1]){int x;x = c1[j + 1];c1[j+1] = c1[j];c1[j] = x;}}}for (int i = 0; i < c1.size(); i++) {cout << c1[i] << " ";}return 0;
}

第三题

#include <iostream>
#include <cmath>
using namespace std;class Point {double m_x = 0, m_y = 0;
public:double getx() { return m_x; }//获取坐标double gety() { return m_y; }Point(double x = 0, double y = 0) : m_x(x), m_y(y) {cout << "Constructor of Point" << endl;}Point(const Point& p) :m_x(p.m_x), m_y(p.m_y) {cout << "Copy constructor of Point" << endl;}~Point() {cout << "Destructor of Point" << endl;}friend double length(const Point& a, const Point& b);
};
double length(Point& a, Point& b) {//求点到点距离double l = sqrt((a.getx() - b.getx()) * (a.getx() - b.getx()) + (a.gety() - b.gety()) * (a.gety() - b.gety()));return 0;
}
class Circle {Point m_center; double m_radius = 1.0;
public:Circle(double r = 1, const Point& p = Point()) :m_center(p), m_radius(r) {cout << "Constructor of Circle" << endl;}~Circle() {cout << "Destructor of Circle" << endl;}double mianji() {//求面积double s = 3.14 * m_radius * m_radius;return s;}double zhouchang() {//求周长double c = 2 * 3.14 * m_radius;return c;}
};
int main(){Circle a(2, Point(1, 1));Point x(1, 1);cout << "end" << endl;cout << x.getx() <<" " << x.gety() << endl <<a.mianji()<<endl<< a.zhouchang();return 0;
}

这道题非常的综合,很好。

大一的第三次作业,/(ㄒoㄒ)/~~相关推荐

  1. 求职准备:大一到大三,做好五件大事!

    无论你现在是大几  无论你对于大学是多么的绝望  无论你多么不喜欢你的专业 无论如何 请朋友们好好看完这篇文章  我不能保证你能从此收获多少  但是我保证每一位认真看完的朋友会受益于整个大学生活  他 ...

  2. 大一到大三一定要做完!

    无论你现在是大几 无论你对于大学是多么的绝望 无论你多么不喜欢你的专业 无论如何 请朋友们好好看完这篇文章 我不能保证你能从此收获多少 但是我保证每一位认真看完的朋友会受益于整个大学生活 他会教你少走 ...

  3. OO第三单元作业总结

    OO第三次作业总结 一.JML (一)JML语言理论基础 (1)JML表达式: JML表达式包括以下几种: 原子表达式如\result(方法执行后的返回值).\old(表达式在相应方法执行前的取值): ...

  4. 程序设计第三次作业附加 代码规范

    题目:第三次作业附加 myGithub 我的程序设计第三次作业 Calculator.h //==============================// //文件名称:calculator.h ...

  5. JML规格编程——BUAA OO第三单元作业总结

    整体概述 这个单元整体围绕Java Model Language(JML)展开,通过学习JML规格了解契约式编程的过程,课上实验中进行了JML规格的简要编写,课下实验主要通过阅读规格并按照规格的要求正 ...

  6. 2021年人工神经网络第三次作业-第二题:遗传算法与人工神经网络-参考答案

    简 介: 给出了对于BP网络求解异或问题过程中,利用遗传算法完成网络演变的过程.所使用的遗传算法是最基本的遗传算法.利用遗传算法对于网络的系数进行演变,可以对网络系数初始化过程进行优化.对于不同的遗传 ...

  7. 2021年春季学期-信号与系统-第三次作业参考答案-第十一道题

    本文是 2021年春季学期-信号与系统-第三次作业参考答案 中的参考答案. ▌第十一道题 11. 如果已知系统的输入输出关系可以使用二阶常系数 差分方程来描述.如果相应输入为:x[n]=u[n]x\l ...

  8. 2021年春季学期-信号与系统-第三次作业参考答案-第十道题

    本文是 2021年春季学期-信号与系统-第三次作业参考答案 中的参考答案. ▌第十道题 10. 求解差分方程: (1)第一小题 y[n]=−5y[n−1]+ny\left[ n \right] = - ...

  9. 2021年春季学期-信号与系统-第三次作业参考答案-第九道题

    本文是 2021年春季学期-信号与系统-第三次作业参考答案 中的参考答案. ▌第九道题 9. 已知因果线性时不变系统的输入输出之间的微分方程为: ddty(t)+5y(t)=∫−∞∞x(τ)f(t−τ ...

最新文章

  1. sqplus操作oracle,sqlplus操作oracle
  2. arnold官方帮助文档_Baklib-随时编辑随时发布的在线帮助文档制作平台
  3. python面试-python简单面试题
  4. (转)TCP和UDP之间的区别
  5. 推荐一个算法/数据结构 可视化(Data structure Visualization) 网站
  6. iOS10 UI教程层次结构的事件
  7. Python中使用pip安装库时指定镜像源为豆瓣镜像源
  8. freemarker生成word模板
  9. 僵尸网络--botnet--DDoS 章2
  10. 如何熟练使用EXCEL
  11. 机器学习算法(十):线性回归之最小二乘法
  12. 免费软电话 — X-Lite 的安装及配置向导
  13. 英雄之盾-第11届蓝桥杯Scratch省赛真题第4题
  14. windows设置CPU主频
  15. 社保入税+国家支持,企业一大法宝:灵活用工
  16. 1064 例题5-1-5 连续自然数求和
  17. 测试路由器wlan口向lan口通信,解决ping不通wlan口和传输文件问题
  18. linux程序 tty没了,linux – 提示自定义:如何检测何时没有tty
  19. html nav 置顶居中,CSS / HTML试图使nav ul元素居中
  20. java ajax 登陆验证_AJAX+JAVA用户登陆注册验证

热门文章

  1. 10+ 小故事揭秘高频「操作系统面试题」
  2. GZHU18级寒假训练:Aquarius's Trial F
  3. python读取文本并且替换_python 读取文件并替换字段的实例
  4. 怎么windows设置qq邮箱服务器,电脑中如何添加QQ邮箱到Windows Live Mail
  5. AI万物生成技术,颠覆内容传统创作模式 | iBrandUp 职位内推
  6. php ftp 时间不对,ftp时间差8小时引起的?
  7. 单片机并行口开发——双数码管显示
  8. NXP 公司的 RFID 卡
  9. 白屏、首屏的定义、影响因素、优化方法
  10. c位边上还有什么位_λ(c位旁边二个位置叫什么)