Part 2

#ifndef GRAPH_H
#define GRAPH_H
class Graph {
public:
Graph(char ch, int n);
void draw();
private:
char symbol;
int size;
}; #endif

graph.h

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

graph.app

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

main.app

part 3

#ifndef FRACTION_H
#define FRACTION_H class Fraction {
public:
Fraction(int t = , int b = ) : top(t), bottom(b) {
}
Fraction(const Fraction &fr) : top(fr.top), bottom(fr.bottom) {
}
void fractionadd(Fraction &f, Fraction &p);
void fractionmin(Fraction &f, Fraction &p);
void fractionmul(Fraction &f, Fraction &p);
void fractiondiv(Fraction &f, Fraction &p);
void fractioncom(Fraction &f, Fraction &p);
void show();
private:
int top;
int bottom;
};
#endif // !FRACTION_H#pragma once

fraction.h

#include"fraction.h"
#include<iostream>
using namespace std;
void Fraction::show() {
if (top == ) cout << << endl;
else if (bottom == ) cout << top << endl;
else if (top / bottom < ) cout << "-" << top << "/" << bottom << endl;
else cout << top << "/" << bottom << endl;
} void Fraction::fractionadd(Fraction &f, Fraction &p) {
int t1, b1, t2, b2, m, n, temp, x, y, z;
t1 = f.top;
t2 = p.top;
b1 = f.bottom;
b2 = p.bottom;
y = b1 * b2;
x = t1 * b2 + t2 * b1;
m = x;
n = y;
if (m < n)
{
temp = m;
m = n;
n = temp;
}
for (z = n;z >= ;z--)
{
if (x%z == && y%z == ) break;
}
x = x / z;
y = y / z;
cout << x << "/" << y << endl;
} void Fraction::fractionmin(Fraction &f, Fraction &p) {
int t1, t2, b1, b2, x, y, m, n, temp, z;
t1 = f.top;
t2 = p.top;
b1 = f.bottom;
b2 = p.bottom;
y = b1 * b2;
x = t1 * b2 - t2 * b1;
m = x;
n = y;
if (m < n)
{
temp = m;
m = n;
n = temp;
}
for (z = n; z >= ; z--)
{
if (x%z == && y%z == ) break;
}
x = x / z;
y = y / z;
cout << x << "/" << y << endl;
} void Fraction::fractionmul(Fraction &f, Fraction &p) {
int t1, t2, b1, b2, x, y, m, n, temp, z;
t1 = f.top;
t2 = p.top;
b1 = f.bottom;
b2 = p.bottom;
y = b1 * b2;
x = t1 * t2;
m = x;
n = y;
if (m < n)
{
temp = m;
m = n;
n = temp;
}
for (z = n; z >= ; z--)
{
if (x%z == && y%z == ) break;
}
x = x / z;
y = y / z;
cout << x << "/" << y << endl;
} void Fraction::fractiondiv(Fraction &f, Fraction &p) {
int t1, t2, b1, b2, x, y, m, n, temp, z;
t1 = f.top;
t2 = p.bottom;
b1 = f.bottom;
b2 = p.top;
y = b1 * b2;
x = t1 * t2;
m = x;
n = y;
if (m < n)
{
temp = m;
m = n;
n = temp;
}
for (z = n; z >= ; z--)
{
if (x%z == && y%z == ) break;
}
x = x / z;
y = y / z;
cout << x << "/" << y << endl;
} void Fraction::fractioncom(Fraction &f, Fraction &p) {
int t1, t2, b1, b2, x, y;
t1 = f.top;
t2 = p.top;
b1 = f.bottom;
b2 = p.bottom;
y = b1 * b2;
x = t1 * b2 - t2 * b1;
if (x < ) cout << f.top << "/" << f.bottom << "<" << p.top << "/" << p.bottom << endl;
else if (x > ) cout << f.top << "/" << f.bottom << ">" << p.top << "/" << p.bottom << endl;
else if (x == ) cout << f.top << "/" << f.bottom << "=" << p.top << "/" << p.bottom << endl;
}

fraction.app

#include"fraction.h"
#include<iostream>
using namespace std;
int main() {
Fraction a;
a.show();
Fraction b(, );
b.show();
Fraction c();
c.show();
int x, y;
cin >> x >> y;
Fraction d(x, y);
d.show();
a.fractionadd(b, d);
a.fractionmin(b, d);
a.fractionmul(b, d);
a.fractiondiv(b, d);
a.fractioncom(b, d);
system("pause");
}

mian.cpp

最新文章

  1. gitignore 规范
  2. Sharp Memory LCD (ls013b7dh03)驱动
  3. 三步将Node应用部署到Heroku上
  4. 【总结】探索Newlife组件:服务代理利器XAgent的前世今生
  5. DOM 元素节点几何量与滚动几何量
  6. ES6 你可能不知道的事 – 基础篇
  7. 异常:The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application
  8. hibernate annotation注解 columnDefinition用法
  9. C# 之 Math取整
  10. iconv 文件编码转换
  11. Eclipse常用热键
  12. css代码整理
  13. php上传文件,接口是java,go。
  14. HTML5 — 地理定位
  15. Halcon示例:print_quality 字符验证
  16. 使用iconv进行编码gb2312转utf8 转码失败的坑
  17. 一文犀利看懂中美贸易战 z
  18. centos7 设置 静态IP
  19. vi如何修改注释颜色
  20. VMware虚拟机配置

热门文章

  1. ubuntu google chrome 忽略证书错误 -- 解决自签名证书不支持的问题
  2. jsapi 调起微信支付的的踩坑
  3. grid-layout
  4. namespace的作用
  5. Java——值传递与引用传递
  6. JavaScript学习摘要
  7. cocos2dx 3.17.1 导演类
  8. ORA-01555快照过旧报错
  9. Protege4.3 添加Rules 栏
  10. 通过重写request.getParameter方法来解决中文乱码问题。