Click here to Skip to main content
15,894,825 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Question about 'new' and 'delete' Pin
Ryan Binns12-Feb-06 12:26
Ryan Binns12-Feb-06 12:26 
GeneralRe: Question about 'new' and 'delete' Pin
Richard Andrew x6412-Feb-06 12:38
professionalRichard Andrew x6412-Feb-06 12:38 
AnswerRe: Question about 'new' and 'delete' Pin
Michael Dunn12-Feb-06 12:56
sitebuilderMichael Dunn12-Feb-06 12:56 
GeneralRe: Question about 'new' and 'delete' Pin
Richard Andrew x6412-Feb-06 13:00
professionalRichard Andrew x6412-Feb-06 13:00 
AnswerRe: Question about 'new' and 'delete' Pin
ThatsAlok14-Feb-06 17:30
ThatsAlok14-Feb-06 17:30 
Questionfopen error (due to string??) Pin
kittymew12-Feb-06 9:38
kittymew12-Feb-06 9:38 
AnswerRe: fopen error (due to string??) Pin
Spykraft13-Feb-06 2:03
Spykraft13-Feb-06 2:03 
QuestionNeed help with HugeInt class program Pin
mattherb18212-Feb-06 8:37
mattherb18212-Feb-06 8:37 
I have it broken into 3 source files, here is the code:
//hugeint.cpp<br />
#include "cstring"<br />
#include "hugeint.h"<br />
<br />
// Conversion constructor<br />
HugeInt::HugeInt( long val )<br />
{<br />
   int i; <br />
<br />
   for ( i = 0; i <= 29; i++ )<br />
      integer [i] = 0;   // initialize array to zero<br />
<br />
   for ( i = 29; val != 0 && i >= 0; i-- ) <br />
   {<br />
      integer[i] = val % 10;<br />
      val /= 10;<br />
   }<br />
}<br />
HugeInt::HugeInt( char *string )<br />
{<br />
   int i, j;<br />
<br />
   for ( i = 0; i <= 29; i++ )<br />
      integer[i] = 0;<br />
<br />
   for ( i = 30 - strlen( string ), j = 0; i <= 29; i++, j++ )<br />
      if (isdigit( string[j] ))<br />
         integer[i] = string[j] - '0';<br />
}<br />
// Addition<br />
HugeInt HugeInt::operator+( HugeInt &op2 )<br />
{<br />
   HugeInt temp;<br />
   int carry = 0;<br />
<br />
   for ( int i = 29; i >= 0; i-- ) <br />
  {<br />
      temp.integer[i] = integer[i] + <br />
                          op2.integer[i] + carry;<br />
<br />
      if ( temp.integer[i] > 9 ) {<br />
         temp.integer[i] %= 10;<br />
         carry = 1;<br />
      }<br />
      else<br />
         carry = 0;<br />
   }<br />
<br />
   return temp;<br />
}<br />
// Addition<br />
HugeInt HugeInt::operator+( int op2 )<br />
   { return *this + HugeInt( op2 ); }<br />
<br />
// Addition<br />
HugeInt HugeInt::operator+( char *op2 )<br />
   { return *this + HugeInt( op2 ); }<br />
<br />
ofstream& operator << ( ofstream &output, HugeInt &num )<br />
{<br />
   int i;<br />
<br />
   for ( i = 0; ( num.integer[i] == 0 ) && ( i <= 29 ); i++ ); // skip leading zeros<br />
if ( i == 30 )<br />
      output << 0;<br />
   else<br />
      for ( ; i <= 29; i++ )<br />
         output << num.integer[i];<br />
<br />
   return output;<br />
}<br />
<br />
//hugeint.h<br />
#include <iostream><br />
<br />
using namespace std;<br />
<br />
class HugeInt {<br />
<br />
public:<br />
short integer[30];<br />
HugeInt(); // default constructor<br />
HugeInt( long int ); // convert constructor<br />
HugeInt( const char * ); // convert constructor<br />
HugeInt operator+( HugeInt ); // addition operator<br />
void operator=( HugeInt ); // assignment operator<br />
void print( ofstream& ); // file output method<br />
};<br />
<br />
//main.cpp<br />
#include <fstream> // other directives and declarations as needed here<br />
#include "hugeint.h"<br />
<br />
using namespace std;<br />
<br />
int main()<br />
{<br />
HugeInt n1(7654321), n2(7891234),<br />
n3("99999999999999999999999999999"), n4("1"), n5;<br />
// define and open output file stream fout<br />
<br />
fstream fout;<br />
fout.open("file.txt");<br />
<br />
fout << "n1 is ";<br />
n1.print(fout);<br />
fout << endl;<br />
fout << "n2 is ";<br />
n2.print(fout);<br />
fout << endl;<br />
fout << "n3 is ";<br />
n3.print(fout);<br />
fout << endl;<br />
fout << "n4 is ";<br />
n4.print(fout);<br />
fout << endl;<br />
fout << "n5 is ";<br />
n5.print(fout);<br />
fout << endl;<br />
<br />
n5 = n1 + n2;<br />
n1.print(fout);<br />
fout << " + ";<br />
n2.print(fout);<br />
fout << " = ";<br />
n5.print(fout);<br />
fout << endl << endl;<br />
<br />
n5 = n3 + n4;<br />
n3.print(fout);<br />
fout << " + ";<br />
n4.print(fout);<br />
fout << " = ";<br />
n5.print(fout);<br />
fout << endl << endl;<br />
<br />
n5 = n1 + 9;<br />
n1.print(fout);<br />
fout << " + " << 9 << " = ";<br />
n5.print(fout);<br />
fout << endl; << endl;<br />
<br />
n5 = n2 + "10000";<br />
n2.print(fout);<br />
fout << " + " << "10000" << " = ";<br />
n5.print(fout);<br />
fout << endl << endl;<br />
<br />
// close output file stream fout<br />
fout.close();<br />
return 0;<br />
} <br />
<br />


My main error is 'HugeInt::print' : cannot convert parameter 1 from 'std::fstream' to 'std::ofsteam &'
but there may be more errors than this. Thanks for any help you could give! Smile | :)

-- modified at 14:41 Sunday 12th February, 2006
AnswerRe: Need help with HugeInt class program Pin
rspielmann12-Feb-06 12:18
rspielmann12-Feb-06 12:18 
GeneralRe: Need help with HugeInt class program Pin
mattherb18212-Feb-06 15:42
mattherb18212-Feb-06 15:42 
QuestionShell Namespace; Going Async Pin
__int6412-Feb-06 6:52
__int6412-Feb-06 6:52 
QuestionHelp?? How to Fade out text using CStatic Pin
LivingThoughts12-Feb-06 6:45
LivingThoughts12-Feb-06 6:45 
AnswerRe: Help?? How to Fade out text using CStatic Pin
Iain Clarke, Warrior Programmer12-Feb-06 12:33
Iain Clarke, Warrior Programmer12-Feb-06 12:33 
GeneralRe: Help?? How to Fade out text using CStatic Pin
LivingThoughts12-Feb-06 16:24
LivingThoughts12-Feb-06 16:24 
QuestionScrollbar in CFormView does not work,why? Pin
lostangels12-Feb-06 4:46
lostangels12-Feb-06 4:46 
AnswerRe: Scrollbar in CFormView does not work,why? Pin
Optimus Chaos12-Feb-06 5:57
Optimus Chaos12-Feb-06 5:57 
QuestionScrollbar in CFormView does not work,why? Pin
lostangels12-Feb-06 4:42
lostangels12-Feb-06 4:42 
QuestionCalling .m files from C++ Pin
misugi12-Feb-06 2:49
misugi12-Feb-06 2:49 
AnswerRe: Calling .m files from C++ Pin
Nick_Kisialiou12-Feb-06 9:56
Nick_Kisialiou12-Feb-06 9:56 
GeneralRe: Calling .m files from C++ Pin
misugi13-Feb-06 22:23
misugi13-Feb-06 22:23 
Questionvisual studio 2003 MFC/SDI help drawing Pin
ALTF412-Feb-06 1:02
ALTF412-Feb-06 1:02 
AnswerRe: visual studio 2003 MFC/SDI help drawing Pin
try8812-Feb-06 6:28
try8812-Feb-06 6:28 
GeneralRe: visual studio 2003 MFC/SDI help drawing Pin
ALTF412-Feb-06 6:39
ALTF412-Feb-06 6:39 
Questionproblem with CSocket Pin
hamidreza_buddy12-Feb-06 1:00
hamidreza_buddy12-Feb-06 1:00 
AnswerRe: problem with CSocket Pin
ALTF412-Feb-06 1:06
ALTF412-Feb-06 1:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.