C++实验三
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++实验三的更多相关文章
- FPGA与simulink联合实时环路系列——实验三 按键key
实验三 按键key 实验内容 在FPGA的实验中,经常涉及到按键的使用,按键是必不可少的人机交互的器件之一,在这些实验中,有时将按键的键值读取显示到数码管.LCD或者是通过串口传送到PC的串口助手上进 ...
- Java实验三
20145113 20145102实验三 实验步骤 编码标准 编程标准包含:具有说明性的名字.清晰的表达式.直截了当的控制流.可读的代码和注释,以及在追求这些内容时一致地使用某些规则和惯用法的重要性 ...
- Verilog HDL那些事_建模篇笔记(实验三:按键消抖)
实验三:按键消抖 首先将按键消抖功能分成了两个模块,电平检查模块和10ms延迟模块.电平检测模块用来检测按键信号的变化(是否被按下),10ms延迟模块用来稳定电平检查模块的输入,进而稳定按键信号,防止 ...
- 20145229&20145316 《信息安全系统设计基础》实验三 实时系统的移植
实验封面 实验内容 1.安装ADS(安装文件在00-ads1.2目录下,破解方法00-ads1.2\Crack目录下) 2.安装GIVEIO驱动(安装文件在01-GIVEIO目录下) 3.把整个GIV ...
- 20145301&20145321&20145335实验三
20145301&20145321&20145335实验三 这次实验我的组员为:20145301赵嘉鑫.20145321曾子誉.20145335郝昊 实验内容详见:实验三
- 20145212 实验三《敏捷开发与XP实践》
20145212 实验三<敏捷开发与XP实践> 实验内容 使用git上传代码 与20145223同学一组,使用git相互更改代码 同组实验报告链接:http://www.cnblogs.c ...
- 20145213《Java程序设计》实验三敏捷开发与XP实践
20145213<Java程序设计>实验三敏捷开发与XP实践 实验要求 1.XP基础 2.XP核心实践 3.相关工具 实验内容 1.敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法 ...
- 20145206《Java程序设计》实验三实验报告
20145206<Java程序设计>实验三实验报告 实验内容 XP基础 XP核心实践 相关工具 实验步骤 (一)敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法应用到软件的开发.运 ...
- 20145308刘昊阳 《Java程序设计》实验三 敏捷开发与XP实践 实验报告
20145308刘昊阳 <Java程序设计>实验三 敏捷开发与XP实践 实验报告 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 统计的PSP(Personal ...
- 20145337实验三实验报告——敏捷开发与XP实践
20145337实验三实验报告--敏捷开发与XP实践 实验名称 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 ** 实验步骤**### 敏捷开发与XP 软件工程包括下列领域:软件需求 ...
随机推荐
- angular 2+ 变化检测系列三(Zone.js在Angular中的应用)
在系列一中,我们提到Zone.js,Zones是一种执行上下文,它允许我们设置钩子函数在我们的异步任务的开始位置和结束位置,Angular正是利用了这一特性从而实现了变更检测. Zones.js非常适 ...
- centos7安装elasticsearch
[root@aaron tools]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.1.zi ...
- SpringMVC-2-(Controller)
一)参数类型 @RequestMapping("hello4") @ResponseBody public ModelAndView Hello4( // Servlet的三个参数 ...
- 全文搜索引擎——Solr
1.部署solr a.下载并解压Solr b.导入项目(独立项目): 将解压后的 server\solr-webapp 下的 webapp文件夹 拷贝到tomcat的webapps下,并重命名为 so ...
- 动态规划——Edit Distance
大意:给定两个字符串word1和word2,为了使word1变为word2,可以进行增加.删除.替换字符三种操作,请输出操作的最少次数 Example 1: Input: word1 = &quo ...
- angularjs ng-if 中的ng-model 值作用域问题
现象:最近做了一个需求,页面上使用了ng-if 条件做判断,导致通过使用 $scope 获取不到 ng-model 的值. 问题原因: ng-if这个指令单独开了一个作用域,它只可以继承,不可以进行往 ...
- 马昕璐 201771010118《面向对象程序设计(java)》第六周学习总结
第一部分:理论知识学习部分 1.继承 继承:用已有类来构建新类的一种机制.当定义了一个新类继承了一个类时,这个新类就继承了这个类的方法和域,同时在新类中添加新的方法和域以适应新的情况. 继承是Java ...
- CSS_细节总结
1. 负外边距 上下200*200盒子的重叠,切记用 absolute 绝对定位 为最佳解决方案. 定位 position : fixed absolute relative( top 为 ...
- 07_ for 练习 _ sumOfOdd
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- 日期类的使用(java)-蓝桥杯
蓝桥杯日期问题常考,java提供了日期类很方便: //日历类 Calendar c = Calendar.getInstance(); // 获取实例化对象 Date date =c.getTime( ...