There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen boot bsod computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Fractions in C++


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Snake~eyes's Avatar
Senior Member with 640 posts.
 
Join Date: Apr 2002
27-Aug-2002, 11:37 PM #1
Fractions in C++
im looking to create a fraction class

The class would beable to subtract, multiply, add and divide.

The fractions should be stored as simplified. Improper fractions instead of mix numbers.

How would i go about doing tihs?
Guy's Avatar
Guy Guy is offline
Senior Member with 260 posts.
 
Join Date: Feb 1999
Location: abby, BC, canada
28-Aug-2002, 12:21 PM #2
basically, All you would need is 2 variables that store the numerator and denominator. I would make them integers, but depending on the size you want, you could make them long integers. For the addition, multiplication, etc you would need operator overloading, which I have sort of forgotten so you will have to do a search on google or something. I actually just wrote a function that simplifys fractions for this mini-contest that I could show you if you wanted.

If you were looking more for a code example I could give you one but I dont want to give away too much if you are trying to learn or something.

Peace,
- Guy
__________________
There are only 10 types of people in the world; Those who understand binary, and those who dont.
IMM's Avatar
IMM IMM is offline IMM is authorized to help remove malware.
Distinguished Member with 3,160 posts.
 
Join Date: Feb 2002
28-Aug-2002, 02:46 PM #3
Perhaps you want to follow this one http://www.brent.worden.org/tips/199...rloading1.html through to the 4th page on overloading http://www.brent.worden.org/tips/199...rloading4.html
and then download the files at the bottom of the page.
Snake~eyes's Avatar
Senior Member with 640 posts.
 
Join Date: Apr 2002
29-Aug-2002, 11:30 PM #4
thankyou you two.

I know how to over load functions and what not but this little tutorial/lesson will be very useful.

I appreciate it.

-Snake
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:11 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.