GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Mar-2005, 11:15
ap6118 ap6118 is offline
Junior Member
 
Join Date: Feb 2005
Posts: 62
ap6118 is on a distinguished road

i've been having this problem lately.


i use visual studio 6 to compile most of my code. For some reason, it is compiling fine but would build the .exe file. The message that it outputs is most confusing to me, <the c++ beginner>. i was wondering if anyone would be able to, if possible of course, compiler the program and see if he gets the same error message.
please let me know.
thanks in adavance.
here is the header, implementation, and driver files

CPP / C++ / C Code:
// rational.h
#ifndef RATIONAL_H
#define RATIONAL_H

// class RationalNumber definition
class RationalNumber {

public:
   RationalNumber( int = 0, int = 1 ); // default constructor

   const RationalNumber operator+( const RationalNumber& );
   /* Write prototype for operator- */
   const RationalNumber operator-( const RationalNumber& );
   const RationalNumber operator*( const RationalNumber& );
   const RationalNumber operator/( const RationalNumber& );
   bool operator>( const RationalNumber& ) const;
   bool operator<( const RationalNumber& ) const;
   bool operator>=( const RationalNumber& ) const;
   /* Write prototype for operator <= */
   bool operator<=( const RationalNumber& ) const;
   bool operator==( const RationalNumber& ) const;
   bool operator!=( const RationalNumber& ) const;

   void printRational() const;

private:
   int numerator;
   int denominator;
   void reduction();

}; // end class RationalNumber

#endif // RATIONAL_H

[c/c++]

// rational.cpp 
#include <cstdlib>

#include <iostream> 

using std::cout; 
using std::endl; 

#include "rational.h"

// constructor
RationalNumber::RationalNumber( int n, int d )
{
   numerator = n;
   denominator = d;
   reduction();
   
   /* Write function call to reduction function */

} // end class RationalNumber constructor

/* Write definition for overloaded operator+ */
const RationalNumber RationalNumber::operator +( const RationalNumber &s )
{
	RationalNumber add;

	add.numerator = numerator * s.denominator + denominator * s.numerator;
    add.denominator = denominator * s.denominator;
    add.reduction();

   return add;
}

// function operator- definition
const RationalNumber RationalNumber::operator-(
   const RationalNumber &s )
{
   RationalNumber sub;

   sub.numerator = numerator * s.denominator - denominator *
      s.numerator;
   sub.denominator = denominator * s.denominator;
   sub.reduction();
   return sub;

} // end function operator- 

/* Write definition for overloaded operator * */
const RationalNumber RationalNumber::operator *( const RationalNumber &k)
{
	RationalNumber mult;
	mult.numerator = numerator * k.numerator;
	mult.denominator = denominator * k.denominator;

	return mult;
}

// function operator/ definition
const RationalNumber RationalNumber::operator/( 
   const RationalNumber &d )
{
   RationalNumber divide;

   if ( divide.numerator = 0 ) 
   {  
      divide.numerator = numerator * d.denominator;
      divide.denominator = denominator * d.numerator;
      divide.reduction();

   } // end if

   else {
      cout << "Divide by zero error: terminating program\n";
      exit( 1 );   // cstdlib function

   } // end else

   return divide;

} // end function operator/

// function operator> definition
bool RationalNumber::operator>( const RationalNumber &gr ) const
{
   // compare double values of two rational numbers
   if ( static_cast< double >( numerator ) / denominator > 
        static_cast< double >( gr.numerator ) / gr.denominator )
      return true;

   else
      return false;

} // end function operator>

// function operator< definition
bool RationalNumber::operator<( const RationalNumber &lr ) const
{
   return !( *this > lr );

} // end function operator<

// function operator>= definition
bool RationalNumber::operator>=( const RationalNumber &rat ) const
{  
   return *this == rat || *this > rat;

} // end function operator>=
bool RationalNumber::operator<=( const RationalNumber &rat ) const
{
	return *this == rat || *this < rat;
}

/* Write definition for operator <= */

/* Write definition for operator == */
bool RationalNumber::operator==( const RationalNumber &iq ) const
{
	if ( *this == iq )
		return true;

	return false;
	
}

/* Write definition for operator != */
bool RationalNumber::operator!=( const RationalNumber &iq ) const
{
	if ( *this == iq )
		return false;

	return true;
}

// function printRational definition
void RationalNumber::printRational() const
{
   if ( numerator == 0 )         // print fraction as zero
      cout << numerator;

   else if ( denominator == 1 )  // print fraction as integer
      cout << numerator;

   else
      cout << numerator << '/' << denominator;

} // end function printRational

// function reduction definition
void RationalNumber::reduction()
{
   int smallest;
   int gcd = 1;  // greatest common divisor

   smallest = ( numerator < denominator ) ? numerator 
      : denominator;

   for ( int loop = 2; loop <= smallest; ++loop )

       if ( numerator % loop == 0 && denominator % loop == 0 )
          gcd = loop;

   numerator /= gcd;
   denominator /= gcd;

} // end function reduction

CPP / C++ / C Code:

// driver.cpp
#include <iostream> 

using std::cout;
using std::endl; 

#include "rational.h"

int main()
{
   RationalNumber c( 7, 3 );  
   RationalNumber d( 3, 9 );
   RationalNumber x;

   c.printRational();
   cout << " + " ;
   d.printRational();
   cout << " = ";
   x = c + d;
   x.printRational();

   cout << '\n';
   c.printRational();
   cout << " - " ;
   d.printRational();
   cout << " = ";
   /* Write statement to subtract c from d and assign the result to x */
   d - c == x;
   x.printRational();

   cout << '\n';
   c.printRational();
   cout << " * " ;
   d.printRational();
   cout << " = ";
   /* Write statement to multiply c and d and assign the result to x */
   c * d == x;
   x.printRational();

   cout << '\n';
   c.printRational();
   cout << " / " ;
   d.printRational();
   cout << " = ";
   x = c / d;
   x.printRational();

   cout << '\n';
   c.printRational();
   cout << " is:\n";

   cout << ( ( c > d ) ? "  > " : "  <= " );
   d.printRational();
   cout << " according to the overloaded > operator\n";

   cout << ( ( c < d ) ? "  < " : "  >= " );
   d.printRational();
   cout << " according to the overloaded < operator\n";

   cout << ( ( c >= d ) ? "  >= " : "  < " );
   d.printRational();
   cout << " according to the overloaded >= operator\n";

   cout << ( ( c <= d ) ? "  <= " : "  > " );
   d.printRational();
   cout << " according to the overloaded <= operator\n";

   cout << ( ( c == d ) ? "  == " : "  != " );
   d.printRational();
   cout << " according to the overloaded == operator\n";

   cout << ( ( c != d ) ? "  != " : "  == " );
   /* Write statement to print d */
   cout << " according to the overloaded != operator" << endl;

   return 0;

} // end main
Last edited by LuciWiz : 23-Mar-2005 at 14:34. Reason: Please insert your C code between [c] & [/c] tags
  #2  
Old 23-Mar-2005, 11:16
ap6118 ap6118 is offline
Junior Member
 
Join Date: Feb 2005
Posts: 62
ap6118 is on a distinguished road

[c/c++] way is not working


for some reason whenever i try using that when posting,all it does is just gives me smilies.
  #3  
Old 23-Mar-2005, 12:13
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,693
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by ap6118
for some reason whenever i try using that when posting,all it does is just gives me smilies.
Put this before the first line of code (but don't leave any spaces between the brackets and the letter 'c'.

[ c ]

Put this after the last line of code (without the spaces)

[ /c ]

What is the error message? (Be specific: paste the entire error messages into the post.)

Regards,

Dave
  #4  
Old 23-Mar-2005, 12:58
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 890
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
You had this when I edited your post:

Quote:
Originally Posted by ap6118
[c/c++]
//bla-bla

//and nothing here

Please read the tutorial in my signature. Or you could just follow Dave's directions.
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #5  
Old 23-Mar-2005, 14:09
ap6118 ap6118 is offline
Junior Member
 
Join Date: Feb 2005
Posts: 62
ap6118 is on a distinguished road

thanks a bunch


as usual,thank you guys,for pointing out things to me.lol
i really mean it.

anyways the errors that i am getting are as follows :
--------------------Configuration: rational - Win32 Debug--------------------
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/rational.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

rational.exe - 2 error(s), 0 warning(s)

there's probably something wrong in the code itself?but where?

ah..the pain!!
  #6  
Old 23-Mar-2005, 14:27
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,693
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by ap6118
a:
--------------------Configuration: rational - Win32 Debug--------------------
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/rational.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

rational.exe - 2 error(s), 0 warning(s)

there's probably something wrong in the code itself?but where?

ah..the pain!!

It means that you have set up the project to be a Windows (GUI) program. The entry point of a Windows program is _WinMain() instead of main(). You need to change the project application to be Windows Console. I don't currently have Visual Studio 6, so I can't give you the exact steps for project creation.

Regards,

Dave
  #7  
Old 23-Mar-2005, 22:46
ap6118 ap6118 is offline
Junior Member
 
Join Date: Feb 2005
Posts: 62
ap6118 is on a distinguished road

thank you so much


That was a big insight. The program runs fine now. Thanks a lot dave,that was really nice of you. I would never have thought about it.
 
 

Recent GIDBlogToyota - 2008 August Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache / PHP problem, maybe output length? HaganeNoKokoro Apache Web Server Forum 3 07-Aug-2008 04:42
Need advice on a disturbing problem JUNK KED Open Discussion Forum 6 31-Mar-2005 13:51
Css design problem JUNK KED Web Design Forum 4 25-Jan-2005 17:45
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 07:53
unwanted scrollbar problem kelly001 Web Design Forum 3 24-Oct-2003 10:44

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:48.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.