实验三

//main.cpp
#include <iostream> #include"graph.h" using namespace std; int main () { Graph Graph1('*',5); Graph1.draw(); system("pause"); system("cls"); Graph Graph2('$',7); Graph2.draw(); system("pause"); return 0; }
//Graph.h
#ifndef GRAPH_H
#define GRAPH_H
class Graph
{
    public:
        Graph(char c,int n);
        void draw();
        
    private:
        char c;
        int n;        
};
#endif
//Garph.cpp
#include "Graph.h"
#include<iostream>
using namespace std;
Graph::Graph(char c,int n):c(c),n(n)
{
    cout<<"Construction is called"<<endl;
}
void Graph::draw()
{
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<n-i;j++)
            cout<<' ';
        for (int j=0;j<2*i-1;j++)
            cout<<c;
        for (int j=0;j<2*n-1;j++)
            cout<<' ';
        cout<<endl;
    }
}

 

//main.cpp
#include <iostream> #include"Fraction fraction.h" using namespace std; void add(Fraction a,Fraction b) { int cbottom=a.bottom*b.bottom; int ctop=a.top*b.bottom+a.bottom*b.top; cout<<ctop<<"/"<<cbottom<<endl; } void min(Fraction a,Fraction b) { int cbottom=a.bottom*b.bottom; int ctop=a.top*b.bottom-a.bottom*b.top; cout<<ctop<<"/"<<cbottom<<endl; } void mul(Fraction a,Fraction b) { int ctop=a.top*b.top; int cbottom=a.bottom*b.bottom; cout<<ctop<<"/"<<cbottom<<endl; } void div(Fraction a,Fraction b) { int ctop=a.top*b.bottom; int cbottom=a.bottom*b.top; cout<<ctop<<"/"<<cbottom<<endl; } int main () { Fraction a; Fraction b(3,4); Fraction c(5); add(c,b); min(c,b); mul(c,b); div(c,b); return 0; }
//fraction.h
#ifndef FRACTION_H
#define FRACTION_H #include <iostream> using namespace std; class Fraction { public: Fraction(int top=0,int bottom=1); friend void add(Fraction a,Fraction b); friend void min(Fraction a,Fraction b); friend void mul(Fraction a,Fraction b); friend void div(Fraction a,Fraction b); private: int top,bottom; }; #endif
//fraction.cpp
#include"Fraction fraction.h" #include<iostream> using namespace std; Fraction::Fraction(int top,int bottom):top(top),bottom(bottom){}

 

转载于:https://www.cnblogs.com/libing-072921/p/10728911.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值