part2

graph.h

#ifndef GRAPH_H
#define GRAPH_H
// 类Graph的声明
class Graph {
public:
Graph(char ch, int n); // 带有参数的构造函数
void draw(); // 绘制图形
private:
char symbol;
int size;
};
#endif

main.cpp

#include <iostream>
#include "graph.h"
using namespace std;
int main() {
Graph graph1('*',5);
graph1.draw();
system("pause");
system("cls");
Graph graph2('$',7);
graph2.draw();
return 0;
}

graph.cpp

// 类graph的实现
#include "graph.h"
#include <iostream>
using namespace std;
// 带参数的构造函数的实现
Graph::Graph(char ch, int n): symbol(ch), size(n) {
}
// 成员函数draw()的实现
// 功能:绘制size行,显示字符为symbol的指定图形样式
void Graph::draw() {
for(int i=1;i<=size;i++)
{
for(int j=1;j<=size-i;j++)cout<<"";
for(int j=1;j<=2*i-1;j++)cout<<symbol

}
}

part3

fraction.h

#ifndef FRACTION_H
#define FRACTION_H
class Fraction
{
public:
Fraction(int top0=0,int bottom0=1):top(top0),bottom(bottom0) {}
friend void add(Fraction a,Fraction b);
friend void subtract(Fraction a,Fraction b);
friend void multiply(Fraction a,Fraction b);
friend void divide(Fraction a,Fraction b);
friend void compare(Fraction a,Fraction b);
private:
int top;
int bottom;
};
#endif

fraction.cpp

#include "fraction.h"
#include <iostream>
using namespace std;
void add(Fraction a,Fraction b)
{
int i,j;
i=a.top*b.bottom+a.bottom*b.top;
j=a.bottom*b.bottom;
cout<<i<<'/'<<j<<endl;
}
void subtract(Fraction a,Fraction b)
{
int i,j;
i=a.top*b.bottom-a.bottom*b.top;
j=a.bottom*b.bottom;
cout<<x<<'/'<<y<<endl;
}
void multiply(Fraction a,Fraction b)
{
int i,j;
i=a.top*b.top;
j=a.bottom*b.bottom;
cout<<i<<'/'<<j<<endl;
}
void divide(Fraction a,Fraction b)
{
int i,j;
i=a.top*b.bottom;
j=a.bottom*a.top;
cout<<i<<'/'<<j<<endl;
}
void compare(Fraction a,Fraction b)
{
int i;
i=a.top*b.bottom-a.bottom*b.top;
if(i>0)
{
cout<<'>'<<endl;
}
else if(i<0)
{
cout<<'<'<<endl;
}
else if(i=0)
{
cout<<'='<<endl;
}
}

#include "fraction.h"
#include <iostream>
int main()
{
Fraction a;
Fraction b(3,4);
Fraction c(5);
add(b,c);
subtract(b,c);
multiply(b,c);
divide(b,c);
compare(b,c);
return 0;
}

												

C++实验三的更多相关文章

  1. FPGA与simulink联合实时环路系列——实验三 按键key

    实验三 按键key 实验内容 在FPGA的实验中,经常涉及到按键的使用,按键是必不可少的人机交互的器件之一,在这些实验中,有时将按键的键值读取显示到数码管.LCD或者是通过串口传送到PC的串口助手上进 ...

  2. Java实验三

    20145113 20145102实验三 实验步骤 编码标准 编程标准包含:具有说明性的名字.清晰的表达式.直截了当的控制流.可读的代码和注释,以及在追求这些内容时一致地使用某些规则和惯用法的重要性 ...

  3. Verilog HDL那些事_建模篇笔记(实验三:按键消抖)

    实验三:按键消抖 首先将按键消抖功能分成了两个模块,电平检查模块和10ms延迟模块.电平检测模块用来检测按键信号的变化(是否被按下),10ms延迟模块用来稳定电平检查模块的输入,进而稳定按键信号,防止 ...

  4. 20145229&20145316 《信息安全系统设计基础》实验三 实时系统的移植

    实验封面 实验内容 1.安装ADS(安装文件在00-ads1.2目录下,破解方法00-ads1.2\Crack目录下) 2.安装GIVEIO驱动(安装文件在01-GIVEIO目录下) 3.把整个GIV ...

  5. 20145301&20145321&20145335实验三

    20145301&20145321&20145335实验三 这次实验我的组员为:20145301赵嘉鑫.20145321曾子誉.20145335郝昊 实验内容详见:实验三

  6. 20145212 实验三《敏捷开发与XP实践》

    20145212 实验三<敏捷开发与XP实践> 实验内容 使用git上传代码 与20145223同学一组,使用git相互更改代码 同组实验报告链接:http://www.cnblogs.c ...

  7. 20145213《Java程序设计》实验三敏捷开发与XP实践

    20145213<Java程序设计>实验三敏捷开发与XP实践 实验要求 1.XP基础 2.XP核心实践 3.相关工具 实验内容 1.敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法 ...

  8. 20145206《Java程序设计》实验三实验报告

    20145206<Java程序设计>实验三实验报告 实验内容 XP基础 XP核心实践 相关工具 实验步骤 (一)敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法应用到软件的开发.运 ...

  9. 20145308刘昊阳 《Java程序设计》实验三 敏捷开发与XP实践 实验报告

    20145308刘昊阳 <Java程序设计>实验三 敏捷开发与XP实践 实验报告 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 统计的PSP(Personal ...

  10. 20145337实验三实验报告——敏捷开发与XP实践

    20145337实验三实验报告--敏捷开发与XP实践 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 ** 实验步骤**### 敏捷开发与XP 软件工程包括下列领域:软件需求 ...

随机推荐

  1. Maven安装配置(Windows10)

    想要安装 Apache Maven 在Windows 系统上, 需要下载 Maven 的 zip 文件,并将其解压到你想安装的目录,并配置 Windows 环境变量. 所需工具 : JDK 1.8 M ...

  2. git Disconnected:No supported authentication methods available问题解决

    在本地克隆gitlab上的项目,报如下错误:Disconnected:No supported authentication methods available(server sent:publick ...

  3. [模板][题解][Luogu1939]矩阵乘法加速递推(详解)

    题目传送门 题目大意:计算数列a的第n项,其中: \[a[1] = a[2] = a[3] = 1\] \[a[i] = a[i-3] + a[i - 1]\] \[(n ≤ 2 \times 10^ ...

  4. 查看Linux系统软硬件信息

    查看Linux系统软硬件信息 查看计算机CPU信息 cat /proc/cpuinfo 查看文件系统信息 cat /proc/filesystems 查看主机中断信息 cat /proc/interr ...

  5. 构建MHA实现MySQL高可用集群架构

    一.MHA简介 MHA(Master HighAvailability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开 ...

  6. Oracle 备份与恢复

    在进行生产服务器升级.或更换数据库服务器.搭建测试环境时,需要对生产数据库进行备份以及将来可能的还原. 1.expdp导出 expdp DMS version directory=DATA_PUMP_ ...

  7. 图片上传 new FormData() ,new FileReader()

    多图片和单图片取决于 multiple属性,下面来介绍下 new FileReader() reader.readAsDataUrl(file[0]) 可以看到文件是Base64的, let fd = ...

  8. html页面转成jsp页面之后样式变化的问题解决方法

    转载:https://blog.csdn.net/zeb_perfect/article/details/51172859

  9. 基于nutch-1.2实现本地搜索引擎

    声明:本博文参考了很多资料,主要来自http://blog.csdn.net/jiutao_tang/article/details/6461884/,http://www.cnblogs.com/x ...

  10. ms17_010_psexec

    一.ms17_010_psexec简介 MS17-010 的psexec是针对Microsoft Windows的两款最受欢迎的漏洞进行攻击. CVE-2017-0146(EternalChampio ...