Assignment, C/C++ Programming

Assignment Help:
(RationalNumber Class) A rational number is a number that can be represented as the quotient of two
integers. For example, 1/3, 5/7, 7/2, and so forth are rational numbers (By 2/1, etc., we mean the
everyday meaning of the fraction, not the integer division this expression would produce in a C++
program.) In general a rational number is represented as a/b where a and b are the numerator and
the denominator, respectively, and the denominator does not equal to 0.
Suppose a/b and c/d are rational numbers. Arithmetic operations on rational numbers are defined
by the following rules:
a / b + c / d = (ad + bc) / bd
a / b - c / d = (ad - bc)/bd
a / b x c / d = ac / bd
(a / b) / (c / d) = ad / bc, where c / d ? 0
Rational numbers are compared as follows: a/b op c/d if ad op bc, where op is any of the
relational operations. For example, a/b < c/d if ad < bc.
In this exercise, define a class named as RationalNumber. Suppose x, y, and z are objects of type
RationalNumber. The class RationalNumber
? Includes private member variables
o numerator and denominator of type int.
o str of type char*. This member variable is a C string with the format
numerator/denominator
and is managed by new and delete.
? Includes a member function reduction to normalize the values stored so that, after any
operation (construction, initialization, assignment, any arithmetic operations, etc), the greatest
common divisor (gcd) of numerator and denominator is 1. For example, after reduction, 21/14
becomes 3/2, i.e., the values of numerator and denominator are 3 and 2, respectively, and
str is a C string “3/2”.
? Includes a constructor where the default values of the numerator and the denominator are 0
and 1, respectively.
? Includes a copy constructor, which performs deep copy of class member variables.
? Overloads the stream extraction (>>) and stream insertion (<<) operators.
o If the input is 4/6, the statement “cin >> x;” would store 2/3 into object x.
o If x is 2/3, the statement “cout << x;” would output “2/3” to stdout.
? Overloads the assignment operator (=), and the following arithmetic operators: +, -, *, /.
o For example, the statement “cout << x + y << endl;” sends the resulting value
of x + y in rational number format to stdout.
o For example, the statement “z = x + y;” assigns the sum of x and y into z in
rational number.
? Overloads the following operators: ==, !=, >, >=, <, <=.
Write a driver program called testRationalNumber.cpp to test each of the above functions and
overloaded operators in the RationalNumber class.
Additional requirements: 2

? Include your first name in output and screenshot.
? Add “const” to appropriate formal parameters, and member/nonmember functions.
? State purpose, pre-conditions, and post-conditions for each function.
? Add proper comments to code.
? Check boundary and error conditions without crash.
Turn in the following as separate files:
? RationalNumber.h: class declaration
? RationalNumber.cpp: class implementation
? testRationalNumber.cpp: driver program
? Screenshots of output

Related Discussions:- Assignment

Develop a biomedical imaging project, Develop a biomedical imaging project ...

Develop a biomedical imaging project Project Description: This is a biomedical imaging project. Skills required are C++ Programming, Cocoa, Mac OS, Objective C

Need cron job parsing json from api, Need Cron Job Parsing JSON from API, I...

Need Cron Job Parsing JSON from API, Inserting in to DB Project Description: The Project is to prepare a Cron Job with an adjustable interval in seconds and milli seconds. Cr

Graphical user interface designed for the output peripherals, Introduction ...

Introduction to I/O interfacing, discuss microcontrollers applications in industry. Detailed product design specifications that have sections on both hardware and software inclu

Parking garage, A parking garage charges a $2.00 minimum fee to park for up...

A parking garage charges a $2.00 minimum fee to park for up to three hours and an additional $0.50 per hour for each hour or part thereof over three hours. The maximum charge for a

Fundamental input - output routines getc and putc, Access to the channel/de...

Access to the channel/devices is achieved by means of general purpose I/O routines Theses are standard functions described in stdio.h header file namely getc and putc. Getc and put

C program for removing char which u want, C Program for REMOVING CHAR WHICH...

C Program for REMOVING CHAR WHICH U WANT void main() {           int i,j;           char a[100],r;           clrscr();           for(i=0;i

C++ Program Please see where i do mistake, #include #include #include ...

#include #include #include #include #include class Employee { private: char *Name; //Set them as pointers... int IdNumber; char *Department; char *Position; public: voi

Program with inbuilt functions, write a atm program in c with inbuilt funct...

write a atm program in c with inbuilt functions for 1782?

Program to calculate the n factorial, Debug the following program to calcul...

Debug the following program to calculate N! #include using namespace std; main() {             int N, factorial=1;             cout             cin >> N;

CarDealership, ABC Car Dealership needs your help to update the ordering sy...

ABC Car Dealership needs your help to update the ordering system. This car dealer is selling four types of vehicles: Sedan, Truck, SUV, and mini Van. And each type of vehicle can h

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd