首页 技术 正文
技术 2022年11月12日
0 收藏 738 点赞 4,686 浏览 1683 个字
// 类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 ;
}

C++实验四

内容三

//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++实验四

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297