C++ 括号表达式作业代编程、expression、代写C++ 编程

C++ 括号表达式作业代编程、expression
Use the handin directory hw1 to submit your work
Fraction calculator
Description
Create a simple fraction calculator that can add and subtract any number of fractions and writes

the answer as a reduced fraction.
Your program will read input from stdin and write output on stdout.
A fraction is represented as the sequence:
a/b
where a and b are integers and any amount of white space characters ' ' (including none) can
separate a from '/' and '/' from b.
Input consists of an expression made of fractions separated by the operators '+' or '-'.
The number of fractions in the expression is arbitrary. Each of the following 6 lines is an
example of valid input expression:
1/2 + 3/4
1/2-5/7+3/5
355/113
3 /9- 21 / -7
4/7-5/-8
-2/-3 +7 /5
Note that the numerator and/or denominator of a fraction given as input may be negative.
The input will consist of a single expression on a single line terminated by a \n character.
The output should consist of a single, irreducible fraction written as
c/d
where c is a signed integer and d is a positive integer (i.e. the denominator cannot be negative in
the output). The numbers c and d should not have any common factors (apart from 1).
Error processing and special cases
You can expect the input to consist of complete expressions, i.e. there will be no incomplete or
missing fractions in the input. Fractions with a zero denominator may appear in input, and must
cause the following error message to be printed on stdout:
Error: zero denominator
with no other output.
If the answer is an integer, the program should only print that integer and not a fraction
Example: input= 3/2 + 4/8 , output = 2
Examples of input and corresponding output will be provided in the file homework1.tar. Your
output should exactly match the output in the example files (including spaces if any).
Implementation
The main program, called calculator.cpp , is provided. Your project must include a class
Fraction that encapsulates all functions related to the processing of fractions. The >> and <<
operators must be overloaded and used to read and write fractions. The presence of a zero
denominator in input should be handled by throwing an exception of type
invalid_argument defined in <stdexcept>. The class Fraction must be defined in a
source file Fraction.cpp and declared in a header file Fraction.h. The implementation
of the member functions should be defined in the file Fraction.cpp. The class Fraction must
include a constructor Fraction::Fraction(int a, int b). The internal
representation of the fraction should be in reduced form, i.e. using a pair of numbers that have no
common factors. Constructors and other member functions must ensure that the fraction is
always reduced. Use Euclid's algorithm to simplify fractions to reduced form. An example of a C
implementation reduce_fraction.c of this algorithm is provided in the file homework1.tar. Do not
include the file reduce_fraction.c in your submission. The operators '+', '-' and '=' must be
overloaded and defined. Member functions getNum() and getDen() should be implemented,
returning the (reduced) numerator and denominator of the fraction. It should be possible to use
the class Fraction in the program useFraction.cpp which #includes the header
Fraction.h. The program useFraction.cpp is provided in the file homework1.tar. You
should not modify that program.
Submission
Create a tar file named hw1.tar containing the files calculator.cpp Fraction.cpp
Fraction.h useFraction.cpp and Makefile. Do not compress the tar file. The files
calculator.cpp and useFraction.cpp must be identical to the files provided. The
Makefile must contain a target calculator , a target useFraction, a target all, and a
target clean. The target all should appear first and will be used to build both executables.
The target clean will be used to remove all object files and executables. The Makefile
should include the necessary definition to compile C++ files with the –Wall option. Include
your name and Student ID in a comment at the top of each file (except calculator.cpp and
useFraction.cpp). Submit your project using:
$ handin cs40 hw1 hw1.tar
http://www.daixie0.com/contents/13/1286.html

本团队核心人员组成主要包括硅谷工程师、BAT一线工程师,国内Top5硕士、博士生,精通德英语!我们主要业务范围是代做编程大作业、课程设计等等。

我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全  汇编语言 硬件编程 软件设计 工程标准规等。其中代写代做编程语言或工具包括但不限于以下范围:

C/C++/C#代写

Java代写

IT代写

Python代写

辅导编程作业

Matlab代写

Haskell代写

Processing代写

Linux环境搭建

Rust代写

Data Structure Assginment 数据结构代写

MIPS代写

Machine Learning 作业 代写

Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导

Web开发、网站开发、网站作业

ASP.NET网站开发

Finance Insurace Statistics统计、回归、迭代

Prolog代写

Computer Computational method代做

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:[email protected]

微信:codinghelp

猜你喜欢

转载自www.cnblogs.com/helpcode/p/8946563.html