标签:style class add example color 绘制图形 ide click pen
#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(‘*‘,5); graph1.draw(); system("pause"); system("cls"); Graph graph2(‘$‘,7); graph2.draw(); return 0; }
#include "fraction.h" #include <iostream> using namespace std; void Fraction::add(Fraction x,Fraction y){ Fraction sum; sum.top=x.top*y.bottom+x.bottom*y.top; sum.bottom=x.bottom*y.bottom; cout<<"相加"<<sum.top<<"/"<<sum.bottom<<endl; } void Fraction::min(Fraction x,Fraction y){ Fraction min; min.top=x.top*y.bottom-y.top*x.bottom; min.bottom=x.bottom*y.bottom; cout<<"相减"<<min.top<<"/"<<min.bottom<<endl; } void mul(Fraction x,Fraction y){ Fraction mul; mul.top=x.top*y.top; mul.bottom=x.bottom*y.bottom; cout<<"相乘"<<mul.top<<"/"<<mul.bottom<<endl; } void div(Fraction x,Fraction y){ Fraction div; div.top=x.top*y.bottom; div.bottom=x.bottom*y.top; cout<<"相除"<<div.top<<"/"<<div.bottom<<endl; } void compare(Fraction x,Fraction y){ if(x.bottom==y.bottom) {if(x.top>y.top) cout<<"比较"<<x.top<<"/"<<x.bottom<<">"<<y.top<<"/"<<y.bottom<<endl; else cout<<"比较"<<x.top<<"/"<<x.bottom<<"<"<<y.top<<"/"<<y.bottom<<endl; } else {x.bottom=x.bottom*y.bottom; x.top=x.top*y.bottom; y.bottom=x.bottom*y.bottom; y.top=y.top*x.bottom; if(x.top>b.top) cout<<"比较"<<x.top<<"/"<<x.bottom<<">"<<y.top<<"/"<<y.bottom<<endl; else cout<<"比较"<<x.top<<"/"<<x.bottom<<"<"<<y.top<<"/"<<y.bottom<<endl; } } void show(){ }
#ifndef FRACTION_H #define FRACTION_H class Fraction{ public: Fraction(int top1=0,int bottom1=1):top(top1),bottom(bottom1) { } void add(Fraction x,Fraction y); void min(Fraction x,Fraction y); void mul(Fraction x,Fraction y); void div(Fraction x,Fraction y); void compare(Fraction x,Fraction y); void show(); private: int top; int bottom; }; #endif
#include <iostream> #include "Fraction.h" using namespace std; int main() { Fraction a; a.show(); Fraction b(3,4); b.show(); Fraction c(5); b.show(); Fraction example; example.add(b,c); example.min(b,c); example.mul(b,c); example.div(b,c); example.compare(b,c); }
实验小结:第三题太难了,我放弃了,写了个七七八八,日后改善,有缘再见
标签:style class add example color 绘制图形 ide click pen
原文地址:https://www.cnblogs.com/elise00/p/10753712.html