Thread: Can anybody help me correct this C++ code?

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    4

    Can anybody help me correct this C++ code?

    I have a problem in these 20 lines of code and can't find the answer...

  2. #2
    Registered Abuser
    Join Date
    Sep 2007
    Location
    USA/NJ/TRENTON
    Posts
    127
    solution:

    post the code.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Yeah the code might help...

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    4
    Oops!

    Just one second. Code in a second. It must have accidently deleted...

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Oh, and btw, when you post the code, let us know what the problem is. If it's a compile-time message, then give us the error message, and the line number (and point out where that generally is in the code). If it's a runtime error, describe the problem in detail.

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    4

    The code...

    Code:
    #include  “Cursor.h”
    
    template <class Object>
    Cursor<Object>: :Cursor( )
    {
    	header  =  NULL;
    	cursorPosition  =  NULL;
    }
    
    template <class Object>
    bool  Cursor<Object>: :isEmpty ( ) const
    {
    	Return  header  =  NULL;
    }
    
    template <class Object>
    void  Cursor<Object>: :insert (const  Object  & x)
    {
    
    	CNode<Object>  *newItem;
    	newItem  =  new  CNode<Object>(x, NULL);
    
    
    if   (isEmpty( ) )
    	header  =  newItem;
    else
    {
    newItem->next = cursorPosition->next;
    cursorPosition->next = newItem;
    }
    
    cursorPosition = newItem  ;
    printText ( ) ;
    
    }
    
    
    template <class Object>
    void  Cursor<Object>: : printText ( )
    {
    	CNode<Object> *p;
    
    	If (isEmpty( ) )
    {
    		cout<<’|’;
    		return;
    	}
    
    	for (p=header;p!=cursorPosition;p=p->next)
    		cout<<p->element;
    	cout<<cursorPosition->element;
    
    	cout<<’|’;
    	for (p=cursorPosition->next;p!=NULL;p=p->next)
    		cout<<p->element;
    
    }
    
    template <class Object>
    void  Cursor<Object>: :left ( )
    {
    
    	CNode<Object> *p;
    If  (isEmpty ( ) )
    	{
    		cout<<’\n|’;
    		return:
    	}
    For (p=header; p!=cursorPosition;p=p->next)
    	cout<<p->element;
    	cout<<p->element;
    	cout<<’|’;
    
    //for (p=cursorPosition->next;p!=NULL;p=p->next)
    	//cout<<p->element;
    }

    I need to know how to move the cursor position left.
    .
    .
    .
    Last edited by Amanda2; 10-03-2007 at 06:53 PM. Reason: addition.

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    903
    Google gotoxy() . That's the only solution I know but it's an awful one.

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    4

    Need a better C++ solution...

    .
    .
    .
    Need a real explanation...Thanks.
    .
    .
    .

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Why do I get the feeling this is supposed to be a simple console program, but you've gone out and grabbed the first bit of code from the net which mentions the words "cursor" and "left" without any regard to what it actually did.

    Post some of YOUR code so we can hopefully establish the context in which you're trying to manipulate the cursor.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    In the mixture of a lot of off topic back and forth between me and Desolation, my opinion of the actual problem was deleted. ggz.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my Dictionary removal code correct?
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-17-2008, 08:45 AM
  2. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  3. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 4
    Last Post: 01-16-2002, 12:04 AM