parse errors

This is a discussion on parse errors within the C++ Programming forums, part of the General Programming Boards category; Hey everyone, Really struggling with a piece of code, I need to input data from a keyboard as a string ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    3

    Unhappy parse errors

    Hey everyone, Really struggling with a piece of code, I need to input data from a keyboard as a string and save it so that I can print it back to the screen later.
    At the moment I keep getting a "parse error" after having checked thorugh 2 C++ books and the internet I'm none the wiser.

    Any help please?

    Craig Harper

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    3
    thanks for any help CH
    Attached Files Attached Files

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    This is his code:
    Code:
    //Cheers for any help CH
    
    // Craig harper Code for student/person class
    // 12/08/2003
    // Problem lines are marked with comments
    
    
    
    #include <stdio.h>
    #include <iostream>
    #include <stdlib.h>
    
    
    class Person
    {
    public:
           Person()  {
                     };
           ~Person() {
                     };
    
           unsigned long int getLibraryNumber();
           void SetLibraryNumber (unsigned long int);
           char GetSurname();
           void SetSurname(char);
           char GetFirstName();
           void SetFirstName(char);
           char GetTitle();
           void SetTitle(char);
    
    protected:
    
           unsigned long int LibraryNumber;
           char Surname[50];
           char Forename[30];
           char Title[5];
    
    };
    
    class Student
    {
          public:
          Student()       {
                          };
          ~Student()      {
                          };
    
          char GetDepartment();
          void SetDepartment(char);
          int GetCourse();
          void SetCourse(int);
    
          protected:
          char Department[30];
          int Course;
    
          };
    
    void doEnterStudents();
    void doEnterStaff();
    void doPrintRecordsStudents();
    void doPrintRecordsStaff();
    
    
    void doEnterStudents()
    {
    int Counter;
    char Surname[50], Name[30], title[5], department[30];
    int LibNo, course;
    
    for (Counter =0; Counter <10; Counter++)
    
    Student.counter  = new Student ;           //parse error before '.'
    cout << "What is your library number?\n";
    cin >> LibNo;
    Student.SetLibraryNumber(LibNo);           //parse error before '.'
    cout << "What is your surname?\n";
    cin.getline(Surname, 50, '\n');
    Student.SetSurname(Surname);               //parse error before '.'
    cout << "What is your First Names?\n";
    cin >> Name;
    Student.SetFirstName(Name);                //parse error before '.'
    cout << "What is your Title?\n";
    cin >> title;
    Student.SetTitle(title);                   //parse error before '.'
    cout << "what is your department?\n";
    cin >> department;
    Student[Counter].SetDepartment(Dept);           //parse error before '.'
    cout << "what is your Course Number?\n";
    cin >> course;
    Student[Counter].SetCourse(course);
    system ("PAUSE");
    }
    
    void doEnterStaff()
    {
    cout << "the enter staff will go here";
    system ("PAUSE");
    return ;
    }
    
    void doPrintRecordsStaff()
    {
    cout << "Print Staff will go here";
    system ("PAUSE");
    return ;
    }
    
    void doPrintRecordsStudents()
    {
    cout << "Print students will go here";
    system ("PAUSE");
    return ;
    }
    
    
    
    int main(int argc, char *argv[])
    {
      int menuChoice;
      cout << "Please chose your menu choice\n";
      cout << "1: Enter The New Students\n";
      cout << "2: Enter The New Staff\n";
      cout << "3: Print All Staff\n";
      cout << "4: Print All Students\n";
      cout << "5: Exit this program\n";
    
      cin >> menuChoice;
      switch (menuChoice)
             {
             case 1: doEnterStudents;
    
             case 2: doEnterStaff;
                     break;
             case 3: doPrintRecordsStudents;
                     break;
             case 4: doPrintRecordsStaff;
                     break;
             case 5: cout << "Thankyou good bye";
             break;
             default:
             cout << "Thats not in the menu";
             break;
    
    
      system ("pause");
       int holdScreen;
      std::cin >> holdScreen;
      return 0;
    
    }
    
    }
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    first problem I see is here:
    Code:
    for (Counter =0; Counter <10; Counter++)
    
    Student.counter  = new Student ;           //parse error before '.'
    cout << "What is your library number?\n";
    cin >> LibNo;
    Student.SetLibraryNumber(LibNo);           //parse error before '.'
    cout << "What is your surname?\n";
    cin.getline(Surname, 50, '\n');
    Student.SetSurname(Surname);               //parse error before '.'
    cout << "What is your First Names?\n";
    cin >> Name;
    Student.SetFirstName(Name);                //parse error before '.'
    cout << "What is your Title?\n";
    cin >> title;
    Student.SetTitle(title);                   //parse error before '.'
    cout << "what is your department?\n";
    cin >> department;
    Student[Counter].SetDepartment(Dept);           //parse error before '.'
    cout << "what is your Course Number?\n";
    cin >> course;
    Student[Counter].SetCourse(course);
    system ("PAUSE");
    The only thing that's part of the loop is

    Student.counter = new Student ;

    This means that you're throwing away 9 instances of Student. Plus, I don't even see where you're trying to delete them
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Plus, there is no such thing as Student.counter. In addition, you're trying to use the class name Student as if it is an instance.

    What you probably want is this:

    Student student; //create an instance of Student called student

    student.SetLibraryNumber(LibNo); // call a method

    etc...
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    Any particular reason why the member variables of the classes are protected and not private ? You dont seem to use any inhertance so there shouldnt be any reason as far as I can see.

    You should probably place your menu inside a do-while loop
    Code:
    do
    {
      cout << "Please chose your menu choice\n";
      cout << "1: Enter The New Students\n";
      cout << "2: Enter The New Staff\n";
      cout << "3: Print All Staff\n";
      cout << "4: Print All Students\n";
      cout << "5: Exit this program\n";
      cin >> menuChoice;
      // more code here...
    } while (menuChoice != 5);
    I think FillYourBrain has pointed out some other stuff aswell.

  7. #7
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Was there any point to even declaring your constructor and destructor?

    Code:
           Person()  {
                     };
           ~Person() {
                     };
    Those are just empty methods. Why not let the compiler do that for you? Or, better still, stick somethin in there which will be useful.
    Away.

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    3

    thanks but...

    Cheers for the help, i'm trying to set up a small program that will allow a user to enter 10 students. Thats what I thought i would get in the "for" loop. and fib what did you mean about deleting something I wasn't trying to delete anything just store it in the memory so it can be printed later.

    thanks again for your help
    CH
    Last edited by comvimes; 08-12-2003 at 01:49 PM.

  9. #9
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    blahblah = new Student;
    the "new" keyword is dynamic allocation in C++. Meaning you are grabbing a piece of memory from the operating system to use. "new" allocates. "delete" de-allocates. If you do not de-allocate, we have what is called a memory leak. naughty
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:59 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  3. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 07:51 PM
  5. C Parse errors
    By aimalk in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 05:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21