Solved

Debug my program

Posted on 1997-04-24
3
271 Views
Last Modified: 2008-03-06
Thanks.  Tonight I'll check your answers

You wrote ... I'd leave the code in ...
Could you complete this sentence?
You may always reply by e-mail

tom.cornelis@glo.be


Below you find an assignment with its solution.
There are still 3 errors, ( I indicated them with //?? and a description ),
could you correct them?
Could you adjust  the program so the program asks in case 3 (3. Retrieve
all data) for the name of the student from whom you want to retrieve the
data?
Is this a good solution?


Assignment:


      Develop a class where the following data is                 kept:
            +name student
            +street
            +zipcode
            +city
            +course (number, title, number of                                  hours); the number of courses is not
             known in advance

      Next seperate member functions must be used:
            +input of the personal data
            +addition of a course; courses must be                                    kept in a binary tree
            +retrieve all data; courses must be                                          shown in the sequence of their
             course number

Solution:


class CCOURSE
{
      int iNumber;
      int iHours;
      char *cName[100];      
      CCOURSE *Uppointer;            
      CCOURSE *Leftpointer;
      CCOURSE *Rightpointer;
public:
      CCOURSE ( );
      ~CCOURSE ( );       
      void setData(int newNumber, int newHours, char *newName);
      void printCourse ( );
};



CCOURSE::CCOURSE (void)
{
      Uppointer=Leftpointer=Rightpointer=0;
}



CCOURSE::~CCOURSE
//??Multiple declaration for 'CCOURSE::~CCOURSE'
{
        if ( Leftpointer ) delete Leftpointer;
        if ( Rightpointer ) delete Rightpointer;
}



void CCOURSE::printCourse()
{
      if ( Leftpointer ) Leftpointer->printCourse ( );
            cout<<"name: "<<cName<<"\n"
            <<"of "<<iHours<<" hours\n";
      if ( Rightpointer ) Rightpointer->printCourse ( );
}



void CCOURSE::setData(int newNumber, int newHours, char *newName)
{
      iNumber=newNumber; iHours=newHours; strcpy(cName,newName);
}



class CPERSONAL
{
      CPERSONAL *nextStudent;
      char name[ 100 ];
      char street[ 100 ];
      char zipcode[ 100 ];
      char city[ 100 ];
      CCOURSE* root;

      public:
      CPERSONAL ( );
      ~CPERSONAL ( );
      void setData( /*char* Name, char* Street, char* ZipCode, char*
      City*/  /*what you need*/);
      void printCourse ( );
};



CPERSONAL::CPERSONAL ()
//?? Type qualifier 'CPERSONAL' must be a struct or class name
//?? Declaration terminated incorrectly
{
        Root=NULL;
}



CPERSONAL::~CPERSONAL
{
      if ( Root ) delete Root;
}



void CPERSONAL::printCourse ( )
{
      cout << "Name:  " << CPERSONAL.name << endl;
      cout << "Street:  " << CPERSONAL.street << endl;
      cout << "Zipcode:  " << CPERSONAL. zipcode << endl;
      cout << "City:  " << CPERSONAL.city << endl;

      cout<<"Courses";
      if ( Root )
      {
            cout<<":\n"; Root->printCourse();
      }
      else cout<<" haven't defined yet!\n";
}



void CPERSONAL::setData ( )
{
      cout << " INPUT OF PERSONAL DATA " << endl;
      cout << " Please enter name " << endl;
      cin >> Name >> endl;
      cout << " Please enter street " << endl;
      cin >> Street >> endl;
      cout << " Please enter ZipCode " << endl;
      cin >> ZipCode >> endl;
      cout << " Please enter City "
      cin >> City >> endl;
}



void Display_Menu (&iChoice)
{
      do
      {
      cout << "WELCOME TO THE PROGRAM" << endl;
      cout << "Enter your choice" << endl;
      cout <<  "1. Enter a new student" << endl;
      cout <<  "2. Add a course" << endl;
      cout <<  "3. Retrieve all data" << endl;
      cout <<  "4. Quit" << endl;
      cin >> iChoice;
      }
      while ( iChoice4 );
}



void Retrieve_all_data(CPERSONAL *student)
{
      cout << "Here are all data:" << endl;

      if ( student!=NULL ) {
            do
                  {
//?? remove this line?      student->printCourse ( );
                  student=student->next;
                  }
            while ( student!=NULL );
            }
      else
            {
            cout << " You haven't entered a student yet" << endl;
            }
      
      if student->root==NULL
            {
                  cout << " You haven't entered any courses" << endl;
            }
      else
            {
                  cout << " Courses:" << endl;
                  student->printCourse ( );

            }
}



void CCOURSE::addCourse(CCOURSE *newOne)
{
      if ( iNumber > newOne->iNumber )
            {
            if ( LeftDownCourse==NULL )
                  {
                  LeftDownCourse=newOne;
                  newOne->UpCourse=this;
                  }
            else LeftDownCourse->addCourse(newOne);
            }
      else
            {
            if  ( RightDownCourse==NULL)
                  {
                  RightDownCourse=newOne;
                  newOne->UpCourse=this;
                  }
            else RightDownCourse->addCourse(newOne);
            }
}



void CCOURSE::setData ( )
{
      CCOURSE *newCourse;
      newCourse=new CCOURSE;

      cout<< "Give courseNumber" << endl;
      cin>> CCOURSE.iNumber >> endl;
      cout<< "Give # hours" << endl;
      cin>> CCOURSE.iHours >> endl;
      cout<< "give Title" << endl;
      cin>> CCOURSE.sTitle >> endl;
}



void main (void)
{
      CPERSONAL *student=NULL;
      CPERSONAL *newStudent;
      int iChoice;

      do
      {
            Display_Menu (iChoice)
            switch (iChoice)
            {
                  case 1 :
//?? no declaration, OK?
                  newStudent=new CPERSONAL;
                  newStudent->setData ( );
                  newStudent->next=student;
                  student=newStudent;
                  break;

                  case 2 :

                  newCourse->setData ( );
                  student->addCourse(newCourse);
                  break;
                  
                  case 3 :

                  Retrieve_all_data( *student );
                  break;

                  case 4 :

                  cout << "Exiting program" << endl;
                  break;
            }
      }
      while ( iChoice!=4 );


      while ( student!=NULL )
      {
            newStudent=student->next;
            delete student;
            student=newStudent;
      }

}






0
Comment
Question by:student040597
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:student040597
ID: 1162950
Edited text of question
0
 

Accepted Solution

by:
Apocalypse earned 20 total points
ID: 1162951
I'm not sure if this is an error or a typo, but you don't
you need parans for the destructor definition?? You're missing them from the code you've given.

The second error looks fine, I can't see anything wrong with. Make sure it's in the proper position so that the definition is after the declaration.

The third and fourth question marks look fine, I'd leave the code in....

I hope this helps a little bit

As for the third error
0
 

Author Comment

by:student040597
ID: 1162952
Edited text of question
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel/Word Add-in in what language? 5 164
Find Visual Studio Tools 2 137
How to convert MFC APP to Win32 APP. 19 134
Create a path if not exists 7 128
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question