标签:应该 open symbol space action class fine define cti
2.
#include "graph.h" #include <iostream> using namespace std; Graph::Graph(char ch, int n): symbol(ch), size(n) { } void Graph::draw() { int i,j,k; for(int i=0;i<size;i++){ for(int j=0;j<size-i;j++) cout<<" "; for(int k=0;k<2*i-1;k++) cout<<symbol; cout<<endl; } }
#ifndef GRAPH_H #define GRAPH_H class Graph { public: Graph(char ch, int n); void draw(); private: char symbol; int size; }; #endif
3.
#include "fraction.h" #include<iostream> using namespace std; void fraction::add(fraction x , fraction y){ fraction s; s.high=x.high*y.low+y.high*x.low; s.low=x.low*y.low; cout<<"x+y="<<s.high<<"/"<<s.low<<endl; } void fraction::min(fraction x , fraction y){ fraction s; s.high=x.high*y.low-y.high*x.low; s.low=x.low*y.low; cout<<"x-y="<<s.high<<"/"<<s.low<<endl; } void fraction::mul(fraction x , fraction y){ fraction s; s.high=x.high*y.high; s.low=x.low*y.low; cout<<"x*y="<<s.high<<"/"<<s.low<<endl; } void fraction::div(fraction x , fraction y){ fraction s; s.high=x.high*y.low; s.low=x.low*y.high; cout<<"x/y="<<s.high<<"/"<<s.low<<endl; } void fraction::compare(fraction x , fraction y){ int s; s=x.high*y.low-y.high*x.low; if (s<0) cout<<"比较:"<<x.high<<"/"<<x.low<<"<"<<y.high<<"/"<<y.low<<endl; else if (s>0) cout<<"比较:"<<x.high<<"/"<<x.low<<">"<<y.high<<"/"<<y.low<<endl; else cout<<"比较:"<<x.high<<"/"<<x.low<<"="<<y.high<<"/"<<y.low<<endl; } void fraction::show(){ cout<<high<<"/"<<low<<endl; }
#ifndef FRACTION_H #define FRACTION_H class fraction{ public: fraction(int x = 0 , int y = 1):high(x),low(y){} void add(fraction a,fraction b); void min(fraction a,fraction b); void mul(fraction a,fraction b); void div(fraction a,fraction b); void compare(fraction a,fraction b); void show(); private: int high; int low; }; #endif
#include<iostream> #include"Fraction.h" using namespace std; int main(){ fraction a; a.show(); fraction b(5,2); b.show(); fraction c(7,3); c.show(); fraction s; s.add(b,c); s.min(b,c); s.mul(b,c); s.div(b,c); s.compare(b,c); }
总结:
第三题其实不大会,参考了别的同学的程序,给更多时间应该可以参透题目吧
标签:应该 open symbol space action class fine define cti
原文地址:https://www.cnblogs.com/changtingzao/p/10759627.html