Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: 1 . Students will apply basic constructs of programming languages to write programs. 2 . Students will write correct, will - documented and readable

Objectives:
1. Students will apply basic constructs of programming languages to write programs.
2. Students will write correct, will-documented and readable programs in a reasonable amount of time.
Problem Description:
Declare and define a class for a fraction number. A fraction in mathematics is defined as a/b, where a and b are integers and called numerator and denominator.
Requirements
Task1
Define a fraction class that has the following member functions:
o constructor that initializes the fraction by default arguments.
o set function that sets the numerator of the fraction.
o set function that sets the denominator of the fraction.
o get function that returns the numerator of the fraction.
o get function that returns the denominator of the fraction.
o a function that displays the fraction.
Write the class in header and implementation files, and compile it separately from the client program. Name the files as fraction.h and fraction.cpp.
Document the class following the example of the point class posted on D2L.
Write a test program to show all your member functions work before you move to Task2. Name your program as project1_task1.cpp.
Task2
Add the following nonmember functions in your fraction header file and implementation file following the example of modified point class in the file newpoint.h and newpoint.cpp:
o A function that returns the sum of two fractions.
o A function that returns the difference of two fractions.
o A function that returns the product of two fractions.
o A function that returns the quotient of two fractions.
[Note] To make your implementation easier, no need to simplify the calculated result.
Name the modified files as newfraction1.h and newfraction1.cpp.
Write another test program to show all the operations work correctly before you move to Task 3. Name the program as project1_task2.cpp.
A run of this test program might look like this:
>a.out
Enter the first fraction: numerator denominator
35
Enter the second fraction: numerator denominator
23
The two fractions entered are
f1=3/5
f2=2/3
The arithmetic operations on these two fractions:
f1+ f2=19/15
f1- f2=-1/15
f1* f2=6/15
f1/ f2=9/10
Task 3
Redo the Task 2 using operators.
Use operator overloading to define the following operations for the fraction class:
o Sum: + as a member function
o Difference: - as a member function
o Product: * as a non member function
o Quotient: / as a non member function
o Output: << as a non member function
o Input : >> as a friend function of the class fraction
Following the example of the point class for all the documentation.
Write and document the class in header and implementation files, and compile it separately from the client program. Name the files as newfraction2.h and newfraction2.cpp.
Write a program that performs all the operations defined above. Name the program as project1_task3.cpp.
Please write in C++

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions