C++ coding problem..help!

Discussion in 'Web Design & Programming' started by rayda, Feb 7, 2009.

  1. rayda

    rayda Geek Trainee

    Likes Received:
    0
    Trophy Points:
    0
    this is my coding:

    Code:
    const int MAX_LIST=50;
    typedef ListItemType;
    
    class List
    {
    public:
    	List();
    	bool isEmpty() const;
    	int getLength() const;
    	
    	void insert(int index, const ListItemType& newItem,bool& success);
    	void remove(int index, bool& success);
    	void retrieve(int index, ListItemType& dataItem,bool& success) const;
    
    private:
    	ListItemType items[MAX_LIST];
    	int sizr;
    	int translate(int index) const;
    };
    
    #include "ListA.h"
    List::List() : size(0)
    {
    }
    
    bool List::isEmpty() const
    {
    	return size == 0;
    }
    
    int List::getLength() const
    {
    	return size;
    }
    
    void List::insert(int index, const ListItemType& newItem, bool& success)
    {
    	success=(index>=1)&&(index<=size+1)&&(size<MAX_LIST);
    	if(success)
    	{
    		for(int pos=size; pos>=index; --pos)
    			items[translate(pos+1)]=items[translate(pos)];
    		items[translate(index)]=newItem;
    		++size;
    	}
    }
    
    void List::remove(int index, bool& success)
    {
    	success=(index>=1)&&(index<=size);
    	if(success)
    	{
    		for(int fromPosition=index+1; fromPosition<=size;++fromPosition)
    			items[translate(from position-1)]=items[translate(fromPosition)];
    		--size;
    	}
    }
    
    void List::retrieve(int index, ListItemType& dataItem, bool& success) const
    {
    	success=(index>=1)&&(index<=size);
    	if(success)
    		dataItem=items[translate(index)];
    }
    
    int List::translate(int index)const
    {
    	return index-1;
    }
    
    #include "ListA.h"
    int main()
    {
    	List aList;
    	ListItemType dataItem;
    	bool success;
    
    	aList.insert(1,20,success);
    	aList.remove(1,success);
    	aList.retrieve(1,dataItem,success);
    	int translate(1);
    	return (0);
    }
    i get an error during compling.
    the error shown is:cannot open include file 'ListA.h'.No such file or directory.

    why??:confused::confused:
     
  2. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
    hi rayda

    Can you not remove the part where you include the ListA.h file, in this case

    Code:
    #include "ListA.h"
    Or if don't you need the ListA file, create it, I think the header files (.h) are used to define the class and what methods etc it will contain.
     
  3. rayda

    rayda Geek Trainee

    Likes Received:
    0
    Trophy Points:
    0
    if i need the ListA.h..
    how to create it?..
     
  4. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
    what software are you using to code?

    just create a new file, then select to save as "ListA.h"
     
  5. thomas234

    thomas234 Big Geek

    Likes Received:
    0
    Trophy Points:
    16
    Wont ListA.h contain some of the code that you need? Have you followed a tutorial for this code?
     
  6. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63

Share This Page