Question: Project#3(b)-Designing and implementing a C++ class data type: Fraction Class (40 points)..a multifile project Write a fraction class whose objects will represent fractions. You should

Project#3(b)-Designing and implementing a C++ class data type: Fraction Class (40 points)..a multifile project

Write a fraction class whose objects will represent fractions. You should provide the following member functions:

Two constructors, a default constructor which assigns the value 0 to the fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the fraction, and the second parameter will represent the initial denominator of the fraction. (6 pts for specification and implementation)

Arithmetic operations that add, subtract, multiply, and divide fractions. These should be implemented as four value returning functions that return a fractionobject. They should be named AddedTo, Subtract, MultipliedBy, and DividedBy. Note the returned fraction object must be in reduced form. (20 pts for specification and implementation)

A boolean operation named isGreaterThan that compares two fraction objects to determine whether one fraction object is greater than the other. (5 pts for specification and implementation)

An input operation named getFraction that prompts the user for two integer values to be used to define a new fraction object. One value is to be used for the numerator and the other for the denominator of the fraction object. on the screen in the form numerator/denominator. (5 pts for specification and implementation)

An output operation named showFraction that displays the value of a fraction object on the screen in the form numerator/denominator. (4 pts for specification and implementation)

NOTE: You may not implement the above member functions as inline functions but should include the function member declarations (or prototypes) in the class specification file (fraction.h) and then write the member function definitions in the implementation file (fraction.cpp).

Your class specification should have exactly two data members, one to represent the numerator of the fraction being represented, and one to represent the denominator of thefraction being represented.

When adding or subtracting fractions, remember that you must first find the common denominator. The easy way to do this is to multiply the denominators together and use that product as the common denominator.

I am providing a client program for you below. You should copy and paste this into a file and use it as your client program that will be a part of your mutlitfile project. The output that should be produced when the provided client program is run with your completed class specification and implementation files is also given below, so that you can check your results. Since this project requires multiple files you will need to first create a new project in your compiler and then write the source code for your class specification file, the implementation file and then add the client code below to the project. For an example with explanations of such C++ class related multifile projects review the Software Engineering Tip: Seperating Class, Specification, Implementation, and Client Code in Chapter 7.11 in your Gaddis textbook (pgs. 446-452)

I strongly suggest that you design your class incrementally. For example, you should first implement only the constructors and the output function, comment out parts of the client code that is not needed and then test what you have so far. Once this code has been thoroughly debugged, you should add additional member functions, testing each one thoroughly as it is added. You might do this by creating your own client program to test the code at each stage; however, it would probably be better to use the provided client program and comment out code that relates to member functions that you have not yet implemented.

As you can see from the sample output given below, except for the arithmetic operations you are not required to change improper fractions into mixed numbers for printing. Just print it as an improper fraction. You are, however, required to reduce fractions that are the result of an arithmetic operation. See the reduced fraction result for the multiplication and division in the sample output. You are not required to deal with negative numbers, either in the numerator or the denominator.

Here is the client program.

/*Client.cpp is set-up as a fraction class implementation and test driver program - DO NOT CHANGE SOURCE CODE All necessary class objects are declared and defined here to test various class related operations. HINT: see comments for specific class related function calls*/ #include  #include "fraction.h" using namespace std; int main() { fraction f1(9,8); //calling a parameterized class constructor fraction f2(2,3); fraction result; //calling a default class constructor const fraction f3(12, 8); const fraction f4(202, 303); fraction f5,f6; cout<<"C++ CLASS MULTI-FILE PROJECT"< 

Compiling/running the client program above along with the fraction class specification and implementation file should produce the output shown below:

C++ CLASS MULTI-FILE PROJECT Client.cpp - testing a fraction class implementation ---------------------------------------------------- The result object starts off at 0/1 Arithmetic operations with fraction objects stored in the results class object ------------------------------------------------------------------------------ The sum of 9/8 and 2/3 is 43/24 The difference of 9/8 and 2/3 is 11/24 The product of 9/8 and 2/3 is 3/4 The quotient of 12/8 and 202/303 is 9/4 Input and Output operations for two new class objects ----------------------------------------------------- Enter values for a fraction object Numerator: 12 Denominator: 13 12/13 Enter values for a fraction object Numerator: 5 Denominator: 6 5/6 A Boolean operation comparing two class objects ------------------------------------ 12/13 is greater than 5/6 --------------------------------------------------------- Fraction class implementation test now successfully concluded Process returned 0 (0x0) execution time : 10.546 s Press any key to continue. 

After successfully completing this mutifile project (ie., your program output should match the above), use the three text boxes below to paste in your source code for the "fraction class" specification file, followed by source code for your "fraction class" implementation file, followed by the output produced when you ran your mutlitfile project using the client program above. You may not change the client program in any way. Changing the client program will result in a grade of 0 on the project.

*important reminder: for multi-file projects to work in your C++ compiler/IDE environment ....make sure you create a new project folder and place all related files in the same folder. Also check that you have the appropriate #include statements in the class implementation and client code files. Xcode users should place these files in the debug folder. You may find a review of the instructor provided sample Abstract DataType project called "MoneyType" helpful when working on this - "Fraction class project".... follow this link => Abstract_Data_Type.pdf (see also class resources page for - a review of weeks#13-14 class lecture/lab recorded sessions along with sample source code may be helpful).

Please also make sure to include appropriate function documentation as needed (see handout on function documentation) and separate your member functions defintions in the implementation file with at least 1 inches of whitespace. You must also include the constant key words for all member functions that are "observer type" of functions.

project 3 folder should have the following files: fraction.h (class specification file) fraction.cpp (class implementation file) client.cpp (client code using the fraction class)

Project#3(b)-Designing and implementing a C++ class data type: Fraction Class (40 points)..a multifile project

Write a fraction class whose objects will represent fractions. You should provide the following member functions:

Two constructors, a default constructor which assigns the value 0 to the fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the fraction, and the second parameter will represent the initial denominator of the fraction. (6 pts for specification and implementation)

Arithmetic operations that add, subtract, multiply, and divide fractions. These should be implemented as four value returning functions that return a fractionobject. They should be named AddedTo, Subtract, MultipliedBy, and DividedBy. Note the returned fraction object must be in reduced form. (20 pts for specification and implementation)

A boolean operation named isGreaterThan that compares two fraction objects to determine whether one fraction object is greater than the other. (5 pts for specification and implementation)

An input operation named getFraction that prompts the user for two integer values to be used to define a new fraction object. One value is to be used for the numerator and the other for the denominator of the fraction object. on the screen in the form numerator/denominator. (5 pts for specification and implementation)

An output operation named showFraction that displays the value of a fraction object on the screen in the form numerator/denominator. (4 pts for specification and implementation)

NOTE: You may not implement the above member functions as inline functions but should include the function member declarations (or prototypes) in the class specification file (fraction.h) and then write the member function definitions in the implementation file (fraction.cpp).

Your class specification should have exactly two data members, one to represent the numerator of the fraction being represented, and one to represent the denominator of thefraction being represented.

When adding or subtracting fractions, remember that you must first find the common denominator. The easy way to do this is to multiply the denominators together and use that product as the common denominator.

I am providing a client program for you below. You should copy and paste this into a file and use it as your client program that will be a part of your mutlitfile project. The output that should be produced when the provided client program is run with your completed class specification and implementation files is also given below, so that you can check your results. Since this project requires multiple files you will need to first create a new project in your compiler and then write the source code for your class specification file, the implementation file and then add the client code below to the project. For an example with explanations of such C++ class related multifile projects review the Software Engineering Tip: Seperating Class, Specification, Implementation, and Client Code in Chapter 7.11 in your Gaddis textbook (pgs. 446-452)

I strongly suggest that you design your class incrementally. For example, you should first implement only the constructors and the output function, comment out parts of the client code that is not needed and then test what you have so far. Once this code has been thoroughly debugged, you should add additional member functions, testing each one thoroughly as it is added. You might do this by creating your own client program to test the code at each stage; however, it would probably be better to use the provided client program and comment out code that relates to member functions that you have not yet implemented.

As you can see from the sample output given below, except for the arithmetic operations you are not required to change improper fractions into mixed numbers for printing. Just print it as an improper fraction. You are, however, required to reduce fractions that are the result of an arithmetic operation. See the reduced fraction result for the multiplication and division in the sample output. You are not required to deal with negative numbers, either in the numerator or the denominator.

Here is the client program.

/*Client.cpp is set-up as a fraction class implementation and test driver program - DO NOT CHANGE SOURCE CODE All necessary class objects are declared and defined here to test various class related operations. HINT: see comments for specific class related function calls*/ #include  #include "fraction.h" using namespace std; int main() { fraction f1(9,8); //calling a parameterized class constructor fraction f2(2,3); fraction result; //calling a default class constructor const fraction f3(12, 8); const fraction f4(202, 303); fraction f5,f6; cout<<"C++ CLASS MULTI-FILE PROJECT"< 

Compiling/running the client program above along with the fraction class specification and implementation file should produce the output shown below:

C++ CLASS MULTI-FILE PROJECT Client.cpp - testing a fraction class implementation ---------------------------------------------------- The result object starts off at 0/1 Arithmetic operations with fraction objects stored in the results class object ------------------------------------------------------------------------------ The sum of 9/8 and 2/3 is 43/24 The difference of 9/8 and 2/3 is 11/24 The product of 9/8 and 2/3 is 3/4 The quotient of 12/8 and 202/303 is 9/4 Input and Output operations for two new class objects ----------------------------------------------------- Enter values for a fraction object Numerator: 12 Denominator: 13 12/13 Enter values for a fraction object Numerator: 5 Denominator: 6 5/6 A Boolean operation comparing two class objects ------------------------------------ 12/13 is greater than 5/6 --------------------------------------------------------- Fraction class implementation test now successfully concluded Process returned 0 (0x0) execution time : 10.546 s Press any key to continue. 

After successfully completing this mutifile project (ie., your program output should match the above), use the three text boxes below to paste in your source code for the "fraction class" specification file, followed by source code for your "fraction class" implementation file, followed by the output produced when you ran your mutlitfile project using the client program above. You may not change the client program in any way. Changing the client program will result in a grade of 0 on the project.

*important reminder: for multi-file projects to work in your C++ compiler/IDE environment ....make sure you create a new project folder and place all related files in the same folder. Also check that you have the appropriate #include statements in the class implementation and client code files. Xcode users should place these files in the debug folder. You may find a review of the instructor provided sample Abstract DataType project called "MoneyType" helpful when working on this - "Fraction class project".... follow this link => Abstract_Data_Type.pdf (see also class resources page for - a review of weeks#13-14 class lecture/lab recorded sessions along with sample source code may be helpful).

Please also make sure to include appropriate function documentation as needed (see handout on function documentation) and separate your member functions defintions in the implementation file with at least 1 inches of whitespace. You must also include the constant key words for all member functions that are "observer type" of functions.

project 3 folder should have the following files: fraction.h (class specification file) fraction.cpp (class implementation file) client.cpp (client code using the fraction class)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!