Thread: interface, implementation, & application files

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    25

    interface, implementation, & application files

    Hi all,
    This program works well. The the object of data type of class used to count something.
    However, the compiler generated the error when I broke this program into 3 parts:
    - The interface file, Problem5.h, contains the class definition.
    - The implementation file, Problem5.cpp, contains the class's member functions, #include "Problem5.h" was written.
    - The application file used to test above class, #include "Problem5.h" was written.

    * When I compiled them, it was fine. However, when I ran them, it seemed to get trouble with the linker.
    The weird thing is, the program works perfectly when I broke the program into 2 parts, the file contains the definiton of class and its member functions' definition, called Problem5.h; and the file contains the main() function.
    Everyone can help me out please. Here is the code:

    Code:
    #include <iostream>
    using namespace std;
    
    class CounterType
    {
    public:
      CounterType();//Default Constructor
    
      CounterType(int number); //Constructor
      
    
      void increase();
      
    
      void decrease();
      
    
      int get();
      
      void output(ostream& numberout);
      
    
    private:
      int count;
      void check();
    
    };
    
    // <---- interface file
    int main()
    {
    	CounterType myclass;
    	CounterType fortest(100);
    	int countvalue,i;
    	for (i=0;i<10;i++)
    	{
    		myclass.increase();
    		if ((i==3)||(i==7))
    			myclass.decrease();
    	}
    	countvalue=fortest.get();
    	cout<<"The first object that counts from 1-->10, except 3&7 :";
    	myclass.output(cout);
    	cout<<endl<<endl;
    	cout<<"The second object that is initilized with 100: "<<countvalue<<endl<<endl;
    
    	return 0;
    }
    //<---- application (drive) file
    
    CounterType::CounterType() : count(0)
    {
    }
    
    CounterType::CounterType(int number)
    {
    	count=number;
    	check();
    }
    
    void CounterType::check()
    {
    	if (count<0)
    	{
    		cout<<"Count contains negative number. No negative number is allowed!\n\n";
    		exit(1);
    	}
    }
    
    void CounterType::increase()
    {
      count++;
      check();
    }
    
    void CounterType::decrease()
    {
      if (count > 0)
        count--;
    	check();
    }
    
    int CounterType::get()
    {
      return count;
    }
    
    void CounterType::output(ostream& numberout)
    {
      numberout << count;
    }
    //<----- implementation file
    Last edited by trongsi; 04-08-2006 at 08:57 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  2. Running the application (.exe) files on other PCs
    By csonx_p in forum Windows Programming
    Replies: 11
    Last Post: 06-11-2008, 09:31 PM
  3. multilayer perceptron application
    By ritchie888 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2008, 02:17 PM
  4. Replies: 2
    Last Post: 02-11-2002, 01:03 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM