Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Debug my program

Posted on 1997-04-24
3
Medium Priority
?
290 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
  • 2
3 Comments
 

Author Comment

by:student040597
ID: 1162950
Edited text of question
0
 

Accepted Solution

by:
Apocalypse earned 60 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

824 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