实验三:类和对象

1.part1

part2

part3

#ifndef Fraction_H
#define Fraction_H
#include<iostream>
using namespace std;
class Fraction
{
    public:
    Fraction(int top0=0,int bottom0=1);
    void divide(Fraction a,Fraction b);
    void show();
    ~Fraction();
    private:
    int top;
    int bottom;
};
#endif
Fraction.h
#include <iostream>
#include "Fraction.h"
#include <cstdlib>
using namespace std;
Fraction::Fraction(int top0,int bottom0):top(top0),bottom(bottom0);{}
//除法
void Fraction::divided(Fraction a,Fraction b);
{top=a.top*b.top;
    bottom=a.bottom*b.bottom;
  
    
    show();
}
void Fraction::show();
{
    if(bottom==1)
    cout<<" "<<top<<endl;
    else
    {
        cout<<"分数形式"<<top<<"/"<<bottom<<endl;
       
        cout<<"小数形式:"<<static_cast<double>(top)/static_cast<double>(bottom)<<endl;
    }
}

Fraction::~Fraction()
{}
Fraction.cpp
#include <iostream>
#include "Fraction.h"
using namespace std;
int mian()
{
    Fraction.a;
    cout<<"a:"<<endl;
    a.show();
    Fraction.b(2,3);
    cout<<"b:"<<endl;
    b.show();
    return 0;
    
        
}
main.cpp

 小结:

第三题我觉得有点难,很多地方真的不太懂。

老师课上讲的基本上都能听懂,轮到自己写又是另一回事,边写边看别人的博客对比的时候,感觉别人就是很强很厉害,自己很弱很不行,也立下很多flag比如说今天一定要好好学习,可基本上一天课上下来,脑子都闷圈了。

也许别人比我还累,却比我更有毅力,更愿意花时间去思考,我太急于求成,反而什么都学不到。

关于分数类,我看到一个人很厉害,写了各种加减乘除的算法,他的总结也写的好认真,也许上五百字小作文了,我虽然敲代码不行,但碎碎念应该还是可以的= =

反正还是加油啦!

希望接下来的日子能花更多精力在C++上。

posted @ 2019-04-23 22:09  音音最腻害!  阅读(182)  评论(0)    收藏  举报