C++实验四
// 类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++实验四的更多相关文章
- Oracle 实验四-七
shutdown immediateORA-01097: 无法在事务处理过程中关闭 - 请首先提交或回退 解决:先 "commit" 实验四 SQL Production :: C ...
- php实验四
实验四 1.创建一个Person类,Person中包含三个属性name,age,wealth,分别设置为public,private,protected,再定义Person类的子类Student. 2 ...
- 实验四 简单的PV操作
实验四 简单的PV操作 专业 网络工程 姓名 方俊晖 学号 201406114309 一. 实验目的 1.掌握临界区的概念及临界区的设计原则: 2.掌握信号量的概念.PV操作的含义以 ...
- Java实验四
20145113 Java实验四 快捷键 之前没怎么记ISDEA的快捷键,但是熟练使用快捷键可以带来很多的便利,于是先开始学习一些常用的快捷键,就采用它默认的快捷键,这样后期就不会出现冲突,一些and ...
- 20145316&20145229实验四:驱动程序设计
20145316&20145229实验四:驱动程序设计 结对伙伴:20145316 许心远 博客链接:http://www.cnblogs.com/xxy745214935/p/6130871 ...
- 20145301&20145321&20145335实验四
20145301&20145321&20145335实验四 这次实验我的组员为:20145301赵嘉鑫.20145321曾子誉.20145335郝昊 实验内容详见:实验四
- 20145212 实验四《Andoid开发基础》
20145212 实验四<Andoid开发基础> 实验内容 安装Android Studio 运行安卓AVD模拟器 使用Android运行出模拟手机并显示自己的学号 实验过程 一.安装An ...
- Java实验四和实验五
实验四 类的继承性和多态性 [开发语言及实现平台或实验环境] Windows2000 或XP,JDK1.6与Jcreator4.0 [实验目的] 1. 掌握OOP方式进行程序设计的方法, 2. 了 ...
- 20145213 《Java程序设计》实验四 Android开发基础
20145213 <Java程序设计>实验四 Android开发基础 说在前面的话 不同以往实验,对于这次实验具体内容我是比较茫然的.因为点我,打开实验四的链接居然能飘出一股熟悉的味道,这 ...
- 20145206实验四《Android开发基础》
20145206 实验四<Android开发基础> 实验内容 ·安装Android Studio ·运行安卓AVD模拟器 ·使用安卓运行出虚拟手机并显示HelloWorld以及自己的学号 ...
随机推荐
- MySQL运用
进入mysql 命令行: mysql -uroot -p查看所有数据库: show databases;创建数据库: create database niu charset utf8;删除数据库: d ...
- unity中使用www的库读取数据里面的数据
//使用www的库,读取数据里面的数据 string factoryControllerUrl = "http://IP地址:8086/DatabaseServerCode/GangShan ...
- _net之美 记录笔记
第一章: Valpoint vPoint1=new Valpoint(); Console.WriteLine(vPoint1.x); 1.=号左边ValPoint vPoint1,在线程上创建一个V ...
- Intellij 代理抛出异常错误: java.rmi.server.ExportException: Port already in use: 1099,端口被占用
代理抛出异常错误: java.rmi.server.ExportException: Port already in use: 1099 端口被占用 解决方案: 1.查找出占用进程id 2.杀死进程 ...
- js实现农历时间代码
var dNow = new Date(); var CalendarData=new Array(100); var madd=new Array(12); var tgString="甲 ...
- [Leetcode 216]求给定和的数集合 Combination Sum III
[题目] Find all possible combinations of k numbers that add up to a number n, given that only numbers ...
- Js函数基本介绍
1. 函数的创建 在JavaScript里面创建函数的关键字为function 函数名:就是在我们调用函数的时候需要书写的标识符 形参:全称为形式参数,调用函数的时候,这个函数所需要的参数是什么 实参 ...
- Java将ip字符串转换成整数的代码
下面代码是关于Java将ip字符串转换成整数的代码,希望对各位有较大用途. public class IpUtil { public static int Ip2Int(String strIp){ ...
- L1-037 A除以B (10 分)
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805094485180416 真的是简单题哈 —— 给定两个 ...
- python+appium 自动化2--元素定位uiautomatorviewer
出处:https://www.cnblogs.com/yoyoketang/p/6128741.html 前言: 可以打开手机上的app了,下一步元素定位uiautomatorviewer,通过定位到 ...