Link to home
Start Free TrialLog in
Avatar of student040597
student040597

asked on

Debug my program

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;
      }

}






Avatar of student040597
student040597

ASKER

Edited text of question
ASKER CERTIFIED SOLUTION
Avatar of Apocalypse
Apocalypse

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Edited text of question