?
Solved

Class Question

Posted on 2003-03-18
6
Medium Priority
?
334 Views
Last Modified: 2008-02-01
I'm trying to understand, so forgive my ignorance. I'm running the following tiny program just to test a class. It doesn't look as though a.inputHugeInteger is ever executing, and I don't understand why.

Output
------
We are indeed in main

Press any key to continue

Code
----
// definition of HugeInteger class

#ifndef HugeInteger_H
#define HugeInteger_H

class HugeInteger
{
private:
     char cTheNumber[40];
     bool bCarry;
public:
     HugeInteger();
        void inputHugeInteger();
     };
#endif

// implementation of HugeInteger class

#include"HugeInteger.h"
#include<iostream>

using std::cout;

HugeInteger::HugeInteger()
{
     cTheNumber[0] = '\0';
     bCarry = false;
}

void HugeInteger::inputHugeInteger()
{

     cout <<"In input huge integer";
     //local variables
     char cInputString [40]; //the characters read in from the input stream
     bool bFailed = false;
     int i = 0;

     cout << "Input the huge integer";
     //get the value from the input stream
     fgets(cInputString, sizeof cInputString, stdin);

     //see if it's really an integer
     while(i < sizeof cInputString && cInputString[i] != '\0')
     {
          if (cInputString[i] < '0' ||
               cInputString[i] > '9' ||
               cInputString[i] == '-');
          else
               bFailed = true;
          i++;
     }

     //if it's an integer, set the value of iTheNumber
     if (!bFailed)
     {
          i = 0;
          while(i < sizeof cInputString && cInputString[i] != '\0')
          {
             cTheNumber[i] = cInputString[i];
             i++;
          }
     }

  return ;
}

void HugeInteger::outputHugeInteger()
{
          int i = 0;
          while(i < sizeof cTheNumber && cTheNumber[i] != '\0')
          {
             cout <<  cTheNumber[i];
             i++;
          }

  return ;
}

//Program file to test HugeInteger Class

#include "HugeInteger.h"

#include <iostream>

using namespace std;

void pause();

int main()
{
  cout << "We are indeed in main";
  HugeInteger a;
  a.inputHugeInteger;
  cout << '\n';
  a.outputHugeInteger;
  cout << '\n';
  pause;
  return 0;
  }
0
Comment
Question by:pflugg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 8159649
Hmm, your 'main()' function looks a bit bogus - shouldn't that be

int main()
{
 cout << "We are indeed in main";
 HugeInteger a;
 a.inputHugeInteger (); // <-- !
 cout << '\n';
 a.outputHugeInteger (); // <-- !
 cout << '\n';
 pause;
 return 0;
 }
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8159671
Corrections:

1) add line
void outputHugeInteger();

to class definition

2)

a.inputHugeInteger();
a.outputHugeInteger();

You missed ()
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 8159700
jkr, sorry, you are first.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:jkr
ID: 8159730
>>jkr, sorry, you are first.

Just being lucky :o)

BTW, to elaborate:

a.inputHugeInteger

*without* the function brackets is a valid expression, but a NULL expression - nothing is done. It is like writing

int i = 1;

i;

0
 

Author Comment

by:pflugg
ID: 8159731
Gee -- I'm missing the forest for the trees.... Thanks!
0
 
LVL 86

Expert Comment

by:jkr
ID: 8159781
You are welcome :o)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question