how do I do math calculations from within a class?

I need to do math claculations from within a class and then display it to the screen after every instance of that call. Take a look at how I have it, I'm getting all sorts of errors right now. Take a look, I have comments by where I think the problems are.

#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>

using namespace std;




class theShares
{
private:
      string name;
      string shares;
      string tClose;
      string high;
      string low;
      string pClose;
      double gain;


public:


      void setname(string theName)
      {
            name=theName;
      }

      void setshares(string theShares)
      {
            shares=theShares;
      }

      void settClose(string dayClose)
      {
            tClose=dayClose;
      }

      void sethigh(string theHigh)
      {
            high=theHigh;
      }

      void setlow(string theLow)
      {
            low=theLow;
      }

      void setpClose(string oldClose)
      {
            pClose=oldClose;
      }

      void setgain(double pGain)        //HERE I'M SETTING THE VOID
      {
            gain=pGain;
      }

      double getgain()
      {
            return (tClose - pClose) / pClose * 100;      //AND THEN HERE IS WHERE I'M DOING THE CLACULATIONS
      }

      string getname()
      {
            return name;
      }

      string getshares()
      {
            return shares;
      }

      string gettClose()
      {
            return tClose;
      }

      string gethigh()
      {
            return high;
      }

      string getlow()
      {
            return low;
      }

      string getpClose()
      {
            return pClose;
      }

      friend istream &operator >> (istream &stream, theShares &myShares)
      {
            
            stream >> myShares.name;
            stream >> myShares.shares;
            stream >> myShares.tClose;
            stream >> myShares.high;
            stream >> myShares.low;
            stream >> myShares.pClose;
            stream.get();
      
            return stream;
      }

      friend ostream &operator << (ostream &stream, theShares &myShares)
      {
            
            
            cout << "stock Name:  ";
            stream << myShares.getname() ;
            
            cout <<  "\n num of shares:  ";
            stream << myShares.getshares();

            cout << "\ntoday close:   ";
            stream << myShares.gettClose();

            cout << "\nthe high:  ";
            stream << myShares.gethigh();

            cout << "\nthe low:  ";
            stream << myShares.getlow();

            cout << "\nprevious close:  ";
            stream << myShares.getpClose();

            cout << "\npercent gain:  ";
            stream << myShares.getgain();          //AND FINALLY HERE IS WHERE I NEED IT TO GO TO THE SCREEN.

            
            



            return stream;
      }
      
      };


void main()
{
      
      double number = 100;
      double gain;
      theShares myShares;

      ifstream inFile("c:\\teststock.txt");

            while(!inFile.eof())
            {
                  inFile >> myShares;

                  
            

                  cout << myShares;
                  
            
            }

      

      
}


stallion5000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rcarlanCommented:
You cannot perform calculations with strings.
May I suggest you change the tClose and pClose data members to double.
You can also use strtod to parse a string and retrieve the number it represents.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stallion5000Author Commented:
Ok, good stuff. I remember strtod, but I'm not sure I'm using it right. Here is what I did, I did my calculations in main. I'm not sure that was a good move, it probably is not because I'm getting errors, but take a look and let me know what you think

#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>

using namespace std;




class theShares
{
private:
      string name;
      string shares;
      string tClose;
      string high;
      string low;
      string pClose;
      


public:


      void setname(string theName)
      {
            name=theName;
      }

      void setshares(string theShares)
      {
            shares=theShares;
      }

      void settClose(string dayClose)
      {
            tClose=dayClose;
      }

      void sethigh(string theHigh)
      {
            high=theHigh;
      }

      void setlow(string theLow)
      {
            low=theLow;
      }

      void setpClose(string oldClose)
      {
            pClose=oldClose;
      }

      

      string getname()
      {
            return name;
      }

      string getshares()
      {
            return shares;
      }

      string gettClose()
      {
            return tClose;
      }

      string gethigh()
      {
            return high;
      }

      string getlow()
      {
            return low;
      }

      string getpClose()
      {
            return pClose;
      }

      friend istream &operator >> (istream &stream, theShares &myShares)
      {
            
            stream >> myShares.name;
            stream >> myShares.shares;
            stream >> myShares.tClose;
            stream >> myShares.high;
            stream >> myShares.low;
            stream >> myShares.pClose;
            stream.get();
      
            return stream;
      }

      friend ostream &operator << (ostream &stream, theShares &myShares)
      {
            
            
            cout << "stock Name:  ";
            stream << myShares.getname() ;
            
            cout <<  "\n num of shares:  ";
            stream << myShares.getshares();

            cout << "\ntoday close:   ";
            stream << myShares.gettClose();

            cout << "\nthe high:  ";
            stream << myShares.gethigh();

            cout << "\nthe low:  ";
            stream << myShares.getlow();

            cout << "\nprevious close:  ";
            stream << myShares.getpClose();

            

            
            



            return stream;
      }
      
      };


void main()
{
      
      double number = 100;
      double gain, t, p;
      theShares myShares;

      ifstream inFile("c:\\teststock.txt");

            while(!inFile.eof())
            {
                  inFile >> myShares;

                  
            

                  cout << myShares;
                  char* stop;
                  t = strtod(tClose.c_str(), &stop);
                  p = strtod(pClose.c_str(), &stop);
                  gain = (t-p)/p*100;
                  cout << gain;

                  
            
            }

      

      
}


0
stallion5000Author Commented:
Never mind I got it. Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.