Class Fraction


You are asked to develop a relatively complete mathematical module on fractions. You are required to use OOP concepts ONLY.

Part A

Create a class called Fraction
Its data members are:
numerator, denominator, fraction_value, slash, whole_number.

Fraction_value: stores the fraction decimal value.
Slash: ("/"): is common to all Fraction objects, and will be used for a formatted display.

The function members:

A constructor: accepts two integer values. If only one parameter is passed, then assign it to the numerator, and force denominator to be 1. If no parameter is passed, use zero for the numerator and one for the denominator.

A constructor that accepts 3 arguments: a whole number portion of the fraction, a numerator, and a denominator.

Each constructor determines whether the fraction is more than 1.
If it is the case, compute the whole number and store it accordingly (may use additional methods/member functions where necessary).

Great Common Denominator: a function that finds the largest number that can divide evenly into both the numerator and denominator.

To reduce a Fraction: use a function that reduces a fraction to its proper format.
(27/12 - 9/4)

Whenever a fraction is created, automatically reduce the fraction to its proper format.

Display: displays the fraction's value as a floating point number and as a fraction.

Then include a whole number portion, a space, the numerator, a slash, the denominator:
Example: Fraction: 27/5  5 2/5
Fraction 3/8  3/8 (do not display the whole number if it is 0)
Fraction 0/5  0

Add four arithmetic operators +, -, *, and /.

NB: After any arithmetic operation, make sure the result is in proper format: e.g. 1/2* 2/3 = 1/3 (not 2/6)

Add the operators == (), >(), <(), that compare the values of two fractions

Prompt the user to choose between four operations for an arithemetic drill-- addition, substraction, multiplication, or division.

After a user has selected an operation, generate five problems using five pairs of fractions from a 10-element array.

Display a problem for (for example, if the user chooses addition, the problem might be "1/5 + 3/5") and allow the user to enter an answer from the keyboard.

After each keybord answer, notify the user whether the answer was correct.

Code a function that decalres an array of randomly generated Fraction values. For which each numerator is a random value between 1 and 5. Set the denominator to 10. Reduce the fraction to its proper form.

Hint: May want to use rand( ) % n

Allow the user up to three attempts to correctly answer each problem.

Keep score. Display a message similar to " No !, you got 3 correct out of 5 problems"


Testing 1:
Test the above specification on an array of 10 randomly generated Fraction values between 6 and 10 inclusive for the denominators as well as numerators.

Please do email me d code....n thanks for your assistance.

Nick Evan commented: no -4
mvmalderen commented: plz do gimme tha code -> no buddy, do your own homework. -4

Recommended Answers

All 14 Replies

Please do email me d code....n thanks for your assistance.

Haha, but no.

Please...its not an assignment for me. Its for a friend. I need an assistance thats why i posted it. If u can help why not help since ure better than us. U knw knowledge is power. U knw more than us plz assist. We share knowledge here. If she knows it..i guess she wont ask me to help her, or if i know i wont bother posting it here. We all learn from others.

Thank you.

Please...its not an assignment for me. Its for a friend.

Yeah, sure.

I need an assistance thats why i posted it. If u can help why not help since ure better than us. U knw knowledge is power. U knw more than us plz assist. We share knowledge here. If she knows it..i guess she wont ask me to help her, or if i know i wont bother posting it here. We all learn from others.

Thank you.

Look: You can crawl all you want, I'm not going to make the assignment for you (or anyone else) if you're not going to show what you have done so far. No effort == No free code.

kthxbi!

Please...its not an assignment for me. Its for a friend. I need an assistance thats why i posted it.

ROFLMAO, The best one I've heard in a while :)
Do you know others like this?

If you are such a benefactor, would you mind doing my homework too?

Okay enough enough...i guess the people here are so ...

Dont worry guys..its okay.

" There is a saying that says...when one eats alone..surely he will die alone." Dont just think it talks abt food or death.

I dont wanna bog anyone again. I will try and complete it then send it to her...She just doesnt have an idea of OOP thats why she sent it to me. And to me...its been long i did programming, as its not my field of career.

Thanks guys...and sorry if i disturbed you.


Cheers

It are just the forum rules, I didn't invent them, but I agree with them.
If you have problems, you should just post the code you have so far, together with a detailed explanation of what your program does, and a description about what problem you have, and then, we can help you.
But we here have no time to write code for no matter who.

Okay enough enough...i guess the people here are so ...

Yep.

" There is a saying that says...when one eats alone..surely he will die alone." Dont just think it talks abt food or death.

I like this saying better: "When one can't make his own homework, one will fail in life"

I dont wanna bog anyone again. I will try and complete it then send it to her...

I'll try it one last time: If you post your effort (so the C++ code you've made), we will actually help you.

Oh thank you.

Nevermind, since you dont have time to help..its okay.

I will do more research and then finally come out with the code. Hardwork never kills you know, thats if one knows what to do.

Thanks

Member Avatar for iamthwee

[search]c++ fraction class[/search]

Oh, and maybe you should get a job in quoting cliches. You seem to be doing a good job of it.

[search]c++ fraction class[/search]

Oh, and maybe you should get a job in quoting cliches. You seem to be doing a good job of it.

Are you referring to me...??? Just take it easy ok. Thanks

Are you referring to me...??? Just take it easy ok. Thanks

No, I think he's referring to the pope :P

No, I think he's referring to the pope :P

Yeah, you are right. Very right cos he wouldnt be referring to me.

Irony is a beautiful thing :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.