我是靠谱客的博主 冷静电话,最近开发中收集的这篇文章主要介绍C++分数类设计题C++分数类设计题源码传送门,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

C++分数类设计题

Define and implement (that is, create Fraction.h and Fraction.cpp files) for a class called Fraction. The class represents a fraction in math (i.e., an integer over an integer) that has the following features and operations:
The class’s attributes should consist of two int values: numerator and denominator.
There should be the following constructors:A parameterless constructor that initializes the fraction to 0. That is, 0/1.
A constructor that takes a single int value, x. The fraction should be initialized to be a fraction equivalent of the int value. That is, x/1.
A constructor that takes two int values, x and y. The fraction should be initialized to be a fraction equivalent of the int value. That is, x/y.
A copy constructor.
The following operations should  be defined:toDouble() : returns a double representation of the fraction.
toString() : returns a string representation of the fraction.
getNumerator() : returns the numerator
getDenominator() : returns the denominator
The following operators should be overridden:

+ : adds two fractions in the typical way
- : subtracts fractions in the typical way
* : multiplies fractions in the typical way
/ : divides fractions in the typical wayThe user should assume the responsibility of not dividing by zero. We'll learn how to deal with this later.

The stream operators << and >> should be implemented (as friend functions).
You must also provide a test program (main.cpp) that exercises the features of the class and ensures they work correctly.

源码传送门

传送门:https://pan.baidu.com/s/1JJs9vbZahUCB6cQvXLgAVg?pwd=1111

最后

以上就是冷静电话为你收集整理的C++分数类设计题C++分数类设计题源码传送门的全部内容,希望文章能够帮你解决C++分数类设计题C++分数类设计题源码传送门所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(79)

评论列表共有 0 条评论

立即
投稿
返回
顶部