Help with C++ coding

This is a discussion on Help with C++ coding within the C++ Programming forums, part of the General Programming Boards category; Ok thankyou So as I was saying Could anyone describe this code, (I am so lost, i really don't understand), ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    50

    Help with C++ coding

    Ok thankyou
    So as I was saying
    Could anyone describe this code, (I am so lost, i really don't understand), in pseuocode

    Code:
    #include <iostream>
    
    using namespace std;
    
    class Counter
    {
    public:
    	Counter();
    	Counter(int initialValue);
    	~Counter(){}
    	int GetItsVal()const { return itsVal; }
    	void SetItsVal(int x) {itsVal = x; }
    	Counter Add(const Counter &);
    
    private:
    	int itsVal;
    };
    
    Counter::Counter():
    itsVal(0)
    {}
    
    Counter::Counter(int initialValue):
    itsVal(initialValue)
    {}
    
    Counter Counter::Add(const Counter & rhs)
    {
    	return Counter(itsVal+ rhs.GetItsVal());
    }
    
    int main()
    {
    	Counter varOne(2), varTwo(4), varThree;
    	varThree = varOne.Add(varTwo);
    	cout << "varThree: " << varThree.GetItsVal() << endl;
    	cout << "varTwo: " << varTwo.GetItsVal() << endl;
    	cout << "varThree: " << varThree.GetItsVal() << endl;
    
    	return 0;
    }
    and could someone please give me a definition of exploiting references, and overloading functions

    thank you so much.
    jay

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    Do you not know how to respond to a thread and need to keep creating new ones?
    As for your help read the tutorials here
    Woop?

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Other threads removed to keep everything tidy. Congrats on figuring out how to post code

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    361
    It helps if you start in main and follow the program the same way it would run.

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    50
    I love when no one helps, it makes me feel special inside.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by prog-bman
    As for your help read the tutorials here
    Quote Originally Posted by jaylc185
    I love when no one helps, it makes me feel special inside.

    main dose this:
    Creates 3 instances of the counter class named varOne, varTwo and varThree with initial values 2, 4, 0 respectivly. varThree is assigned the initial value of 0 because that is the default value, see the defination of the contructor (the member function with the same name as the class that is called when an instance is created)
    Code:
    Counter::Counter():
    itsVal(0)
    {}
    Add varTwo (4) to varOne (2) and asign it to varThree.
    Next the values are output using the GetItsVal() member function of the counter class.
    Last edited by Quantum1024; 05-19-2005 at 11:32 PM.

  7. #7
    Registered User
    Join Date
    May 2005
    Posts
    50
    Thankyou Quantum 1024

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-20-2009, 06:22 PM
  2. Coding Guideline ....!!
    By imfeelingfortun in forum Tech Board
    Replies: 8
    Last Post: 10-08-2006, 08:09 AM
  3. Before Coding
    By cyberCLoWn in forum C++ Programming
    Replies: 16
    Last Post: 12-15-2003, 02:26 AM
  4. Coding Contest....
    By Koshare in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 10-14-2001, 05:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21