// 类graph的实现

#include "graph.h"
#include <iostream>
using namespace std; // 带参数的构造函数的实现
Graph::Graph(char ch, int n): symbol(ch), size(n) {
} // 成员函数draw()的实现
// 功能:绘制size行,显示字符为symbol的指定图形样式
// size和symbol是类Graph的私有成员数据
void Graph::draw() {
int x,y,z;
for(int x=;x<=size;x++){
for(int y=;y<=size-x;y++)
cout<<" ";
for(int z=;z<=*x-;z++) //使每行个数为等差奇数
cout<<symbol;
cout<<endl;
}
// 补足代码,实现「实验4.pdf」文档中展示的图形样式
}
#ifndef GRAPH_H
#define GRAPH_H // 类Graph的声明
class Graph {
public:
Graph(char ch, int n); // 带有参数的构造函数
void draw(); // 绘制图形
private:
char symbol;
int size;
}; #endif
#include <iostream>
#include "graph.h"
using namespace std; int main() {
Graph graph1('*',), graph2('$',) ; // 定义Graph类对象graph1, graph2
graph1.draw(); // 通过对象graph1调用公共接口draw()在屏幕上绘制图形
graph2.draw(); // 通过对象graph2调用公共接口draw()在屏幕上绘制图形 return ;
}

内容三

//fraction.h
class Fraction{
public:
Fraction(int t=,int b=);
void show();
void jia(Fraction &x);
void jian(Fraction &x);
void cheng(Fraction &x);
void chu(Fraction &x);
private:
int top; //分子
int bottom; //分母
};
//fraction.cpp
#include"fraction.h"
#include<iostream>
using namespace std;
Fraction::Fraction(int t,int b):top(t),bottom(b){
}
void Fraction::jia(Fraction &x){
top=top*x.bottom+x.top*bottom;
bottom=bottom*x.bottom;
}
void Fraction::jian(Fraction &x){
top=top*x.bottom-x.top*bottom;
bottom=bottom*x.bottom;
}
void Fraction::cheng(Fraction &x){
top=top*x.top;
bottom=bottom*x.bottom;
}
void Fraction::chu(Fraction &x){
top=top*x.bottom;
bottom=bottom*x.top;
}
void Fraction::show(){
cout<<top<<'/'<<bottom<<endl;
}
//main.cpp
#include"fraction.h"
#include <iostream>
using namespace std;
int main() {
Fraction a;
Fraction b(,);
Fraction c();
a.show();b.show();
c.show();
a.jia(a);a.show();
b.jian(b);b.show();
c.cheng(c);c.show();
c.chu(c);c.show();
return ;
}

小结:在做第二道题时,前几次不知怎么的,运行的结果会向右对其,后来不知怎么弄的又能运行出正确的结果了,可是我并没有改变代码啊,求解

得出的错误结果如右图

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

  1. Oracle 实验四-七

    shutdown immediateORA-01097: 无法在事务处理过程中关闭 - 请首先提交或回退 解决:先 "commit" 实验四 SQL Production :: C ...

  2. php实验四

    实验四 1.创建一个Person类,Person中包含三个属性name,age,wealth,分别设置为public,private,protected,再定义Person类的子类Student. 2 ...

  3. 实验四 简单的PV操作

    实验四 简单的PV操作 专业 网络工程   姓名 方俊晖 学号 201406114309 一.        实验目的 1.掌握临界区的概念及临界区的设计原则: 2.掌握信号量的概念.PV操作的含义以 ...

  4. Java实验四

    20145113 Java实验四 快捷键 之前没怎么记ISDEA的快捷键,但是熟练使用快捷键可以带来很多的便利,于是先开始学习一些常用的快捷键,就采用它默认的快捷键,这样后期就不会出现冲突,一些and ...

  5. 20145316&20145229实验四:驱动程序设计

    20145316&20145229实验四:驱动程序设计 结对伙伴:20145316 许心远 博客链接:http://www.cnblogs.com/xxy745214935/p/6130871 ...

  6. 20145301&20145321&20145335实验四

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

  7. 20145212 实验四《Andoid开发基础》

    20145212 实验四<Andoid开发基础> 实验内容 安装Android Studio 运行安卓AVD模拟器 使用Android运行出模拟手机并显示自己的学号 实验过程 一.安装An ...

  8. Java实验四和实验五

    实验四 类的继承性和多态性 [开发语言及实现平台或实验环境] Windows2000 或XP,JDK1.6与Jcreator4.0 [实验目的] 1.  掌握OOP方式进行程序设计的方法, 2.  了 ...

  9. 20145213 《Java程序设计》实验四 Android开发基础

    20145213 <Java程序设计>实验四 Android开发基础 说在前面的话 不同以往实验,对于这次实验具体内容我是比较茫然的.因为点我,打开实验四的链接居然能飘出一股熟悉的味道,这 ...

  10. 20145206实验四《Android开发基础》

    20145206 实验四<Android开发基础> 实验内容 ·安装Android Studio ·运行安卓AVD模拟器 ·使用安卓运行出虚拟手机并显示HelloWorld以及自己的学号 ...

随机推荐

  1. UML介绍

    UML是什么 Unified Modeling Language (UML)又称统一建模语言或标准建模语言,是始于1997年一个OMG标准,它是一个支持模型化和软件系统开发的图形化语言,为软件开发的所 ...

  2. Java 冒泡排序法

    冒泡排序法: public static void Bubbling(int []num){//冒泡排序法 for(int i=0;inum[j+1]){//前一个大于后一个为小到大排序 前一个小于后 ...

  3. [Leetcode 40]组合数和II Combination Sum II

    [题目] Given a collection of candidate numbers (candidates) and a target number (target), find all uni ...

  4. Django基础-01

    Django 是基于 Python,所有的 Django 代码都是用Python写成的. Django 特点 强大的数据库功能 拥有强大的数据库操作接口(QuerySet API),如需要也能执行原生 ...

  5. centos7初上手1-安装mysql数据库

    随着云服务器的普及,购入云服务器的门槛越来越低,对一个程序员来说,很多人会购买一款云服务器.以前买过两年windows服务器(没有什么实际用途,就是为了玩),最近有机会接触一下linux服务器,选择了 ...

  6. SQL-57 使用含有关键字exists查找未分配具体部门的员工的所有信息。

    题目描述 使用含有关键字exists查找未分配具体部门的员工的所有信息.CREATE TABLE `employees` (`emp_no` int(11) NOT NULL,`birth_date` ...

  7. python笔记26-编码规范层级目录

    bin-放的可执行文件 conf-放的配置文件 lib-放的一些lib库 temp-放的零时文件 logs-日志 core-核心逻辑 data-存放数据 README-帮助文档 start_shop. ...

  8. js显示表单的提交验证

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. PAT A1046 Shortest Distance

    PAT A1046 Shortest Distance 标签(空格分隔): PAT TIPS: 最后一个数据点可能会超时 #include <cstdio> #include <al ...

  10. change the version of python on my centos

    There are two versions of aconda: aconda and aconda3 in my home directorys. When comment the environ ...