Answered step by step
Verified Expert Solution
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:
Students will apply basic constructs of programming languages to write programs.
Students will write correct, willdocumented 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 ab where a and b are integers and called numerator and denominator.
Requirements
Task
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 DL
Write a test program to show all your member functions work before you move to Task Name your program as projecttaskcpp
Task
Add the following nonmember functions in your fraction header file and implementation file following the example of modified point class in the file newpointh and newpointcpp:
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 newfractionh and newfractioncpp
Write another test program to show all the operations work correctly before you move to Task Name the program as projecttaskcpp
A run of this test program might look like this:
aout
Enter the first fraction: numerator denominator
Enter the second fraction: numerator denominator
The two fractions entered are
f
f
The arithmetic operations on these two fractions:
f f
f f
f f
f f
Task
Redo the Task 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 newfractionh and newfractioncpp
Write a program that performs all the operations defined above. Name the program as projecttaskcpp
Please write in C
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started