473,465 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Rational Class help. Reduction funtion doesnt work. Linker error in Dev cpp.

7 New Member
I created a rational class, created member functions to add, subtract, multiply and divide. The reduction function however doesn't work. And the Dev cpp compiler gives a linker error. I have attached the header, implementation and the driver file in rational.zip
Could you help me fix this code?
What am I doing wrong?
Attached Files
File Type: zip Rational.zip (2.3 KB, 104 views)
Nov 22 '09 #1
2 3082
Banfa
9,065 Recognized Expert Moderator Expert
Please post your linker errors.
Nov 22 '09 #2
rjddude1
7 New Member
@Banfa
Linker errors are gone however my reduction function does not work.
How do I make it so that it stores the function in reduced form and reduces them before they are printed.

Thank you in advance.

Here's my function implementation file

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include "Rational.h"
  3.  
  4. Rational::Rational()
  5. : is_valid_( false ), num ( 1 ), den ( 1 )
  6. {
  7. }
  8.  
  9. Rational::Rational( const int init_num, const int init_den )
  10. : num( init_num ), den( init_den )
  11. {
  12.     if ( den == 0 || (den == 0 && num == 0))
  13.         is_valid_ = false;
  14.     else
  15.         is_valid_ = true;
  16. }
  17.  
  18. bool Rational::is_valid() const
  19. {
  20.     return is_valid_;
  21. }
  22.  
  23. void Rational::check() const
  24. {
  25.     if ( ! ( is_valid() ) )
  26.     {
  27.         cout << "Indeterminate form of rational." << endl;
  28.         system("pause");
  29.         exit(1);
  30.     }
  31. }          
  32.  
  33. int Rational::get_num() const
  34. {
  35.    check();
  36.    return num;
  37. }
  38.  
  39. int Rational::get_den() const
  40. {
  41.    check();
  42.    return den;
  43. }
  44.  
  45. void Rational::set_num( const int val1 )
  46. {
  47.      num = val1;
  48. }
  49.  
  50. void Rational::set_den( const int val2 )
  51. {
  52.      den = val2;
  53. }
  54.  
  55. void Rational::reduce ()
  56. {
  57.      //Reduction function...
  58.      //Help required
  59. }
  60.  
  61.  
  62. void Rational::printRational() const
  63. {
  64.         cout << num << '/' << den;
  65. }
  66.  
  67. void Rational:: printRationalAsFloating() const
  68. {
  69.         cout << float(num)/den;
  70. }
  71.  
  72. Rational Rational::addition ( const Rational &a )
  73. {
  74.          Rational add;
  75.          add.num = (a.num * den) + (num * a.den);
  76.          add.den = (den * a.den);
  77.          reduce();
  78.          return add;
  79. }
  80.  
  81. Rational Rational::subtraction ( const Rational &a )
  82. {
  83.          Rational sub;
  84.          sub.num = (num * a.den) - (den * a.num);
  85.          sub.den = (den * a.den);
  86.          reduce();
  87.          return sub;
  88. }
  89.  
  90. Rational Rational::multiplication ( const Rational &a )
  91. {
  92.          Rational multi;
  93.          multi.num = (num * a.num);
  94.          multi.den = (den * a.den);
  95.          reduce();
  96.          return multi;
  97. }
  98.  
  99. Rational Rational::division ( const Rational &a )
  100. {
  101.          Rational div;
  102.          div.num = (num * a.den);
  103.          div.den = (den * a.num);
  104.          reduce();
  105.          return div;
  106. }
  107.  
Nov 23 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Mike Meyer | last post by:
This version includes the input from various and sundry people. Thanks to everyone who contributed. <mike PEP: XXX Title: A rational number module for Python Version: $Revision: 1.4 $...
2
by: Brian van den Broek | last post by:
Hi all, I guess it is more of a maths question than a programming one, but it involves use of the decimal module, so here goes: As a self-directed learning exercise I've been working on a...
7
by: Stephen | last post by:
I have some code which I call from a custom validator however I seem to have got the logic wrong and im having trouble figuring out how to write my code to get things to work the way I require....
3
BenTheMan
by: BenTheMan | last post by:
Hello all. I will probably be frequenting these discussions in the future. I am a graduate student in physics learning C++ on the fly. This is probably an easy quesiton, but my background in...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
2
by: saby | last post by:
Can anybody knowing Rational Purify help me? I am instrumenting an exe on solaris using Rational Purify. While building the exe, known as "DPSRun", it does not give any problem. But while I...
3
by: michael | last post by:
Hi All, Not sure if this is a c++ issue or a compiler issue. I have the following in a class: template<class T> bool Utility::getInput(T& i, T low, T up){ bool result = false; if(cin >i){
135
by: robinsiebler | last post by:
I've never had any call to use floating point numbers and now that I want to, I can't! *** Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) on win32. *** 0.29999999999999999 0.29999999999999999
5
by: anumliaqat | last post by:
hello!! i hav a problem.my program is giving correct outputs for some inputs but wrong results for others. for example if u give (4 2 2)&(2 1 2) to it,it shows all results correct....
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.