C++ Implementing student registration program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #16
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

    Then when you are ready post a new question in this thread.

    Comment

    • Warly girl
      New Member
      • Nov 2007
      • 25

      #17
      iam so sorry
      okey , i tray to corect my mistake

      Student(string studentName)
      {
      studentName=nam e;
      }

      is this true now ?

      Comment

      • Warly girl
        New Member
        • Nov 2007
        • 25

        #18
        plz i want to ask :
        bool canRegisterMore ();
        ^
        why they put this method in private "with variables"
        not with other method in the public ?

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #19
          Originally posted by Warly girl
          iam so sorry
          okey , i tray to corect my mistake

          Student(string studentName)
          {
          studentName=nam e;
          }

          is this true now ?
          Your assignment is backwards. it should be name = studentName - the thing on the left receives the value. Also, you still have not declared the type. it should be
          [code=cpp]
          Student::Studen t()
          {
          string name = "";
          }
          void setName(string studentName)
          {
          name = studentName;
          }
          string getName()
          {
          return name;
          }
          [/code]
          Last edited by sicarie; Nov 2 '07, 06:29 PM. Reason: Confusing constructor with class...

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #20
            [code=cpp]
            Student::Studen t()
            {
            name = "";
            }
            void setName(string studentName)
            {
            name = studentName;
            }
            string getName()
            {
            return name;
            }
            [/code]

            Should have done this in the same post, but I'm working on 3 things at once here.

            So, first of all, this is a constructor (not a class), so you need to specify a return type. Student::Studen t() will specify the default constructor (which needs nothing to be passed to it) to allow you to create Student objects. From there, it creates a string variable called name (should be private, but that's a class issue, not a constructor issue). Actually, now that I think about it, you probably don't have to declare it there, so you were right before.

            Anyway, then you have your get and set methods outside of the constructor that will allow you to modify the private variable name.

            Comment

            • Warly girl
              New Member
              • Nov 2007
              • 25

              #21
              thaanks alot
              this is a deafult consractor , so how if i want to pass value in constructor ?

              Comment

              • sicarie
                Recognized Expert Specialist
                • Nov 2006
                • 4677

                #22
                Originally posted by Warly girl
                thaanks alot
                this is a deafult consractor , so how if i want to pass value in constructor ?
                The way you had it, only with the assignment swiched to name=studentNam e;

                Comment

                • Warly girl
                  New Member
                  • Nov 2007
                  • 25

                  #23
                  okey
                  now in this method
                  bool canRegisterMore ()

                  i wrote

                  {
                  if (currentCourses >4)
                  return false;
                  }

                  is this a correct syntax of bollean method ?

                  Comment

                  • Ganon11
                    Recognized Expert Specialist
                    • Oct 2006
                    • 3651

                    #24
                    Yes, but what if the student has less than 4 classes? Where do you return true?

                    Comment

                    • Warly girl
                      New Member
                      • Nov 2007
                      • 25

                      #25
                      Fine , so i will write

                      bool canRegisterMore ()
                      {
                      if (currentCourses >4)
                      return false;
                      else
                      return true;
                      }

                      is this correct ?
                      but i want to aske about something
                      why they put this method as a praivte ? not in public with other methods
                      and when i will write the cpp file
                      i must write it implementation or not ?

                      Comment

                      • sicarie
                        Recognized Expert Specialist
                        • Nov 2006
                        • 4677

                        #26
                        Originally posted by Warly girl
                        Fine , so i will write

                        bool canRegisterMore ()
                        {
                        if (currentCourses >4)
                        return false;
                        else
                        return true;
                        }

                        is this correct ?
                        but i want to aske about something
                        why they put this method as a praivte ? not in public with other methods
                        and when i will write the cpp file
                        i must write it implementation or not ?
                        You want the variable currentCourses to be private. However, you don't want the method canRegisterMore () to be private, because that is what you have decided will set the variable, you want that to be public.

                        Comment

                        • Warly girl
                          New Member
                          • Nov 2007
                          • 25

                          #27
                          okey
                          now I finish the implementation of the header class and i want you to see it and give me your opinion and tell me about my mistake plz..

                          Code:
                          #include”student.h”
                          Student::Student(string studentName)
                          {
                          Name=studentName;
                          }
                          
                          bool Student::canRegisterMore()
                          {
                          if (currentCourses>=4)
                          return false;
                          else
                          return true;
                          }
                          
                          
                          	
                          bool Student::registerCourse()
                          {
                          if(canRegisterMore()==true)
                          {
                          currentCourses++;
                          return true;
                          }
                          	else
                          return false;
                          }
                          
                          void Student::dropCourse()
                          {
                          if(currentCourses!=0)
                          currentCourses--;
                          
                          }

                          Comment

                          • Warly girl
                            New Member
                            • Nov 2007
                            • 25

                            #28
                            then i stop ! i do not know what shall i do in next step
                            and what must i write in this method : print()
                            i think to write cout of : student name . id and number of coursses
                            but how can i get it !

                            Comment

                            • PuzzleC
                              New Member
                              • Nov 2007
                              • 9

                              #29
                              Spoonfeeding is not allowed

                              Comment

                              • Warly girl
                                New Member
                                • Nov 2007
                                • 25

                                #30
                                ^
                                !! what do you mean !!?
                                i did not do any thing wrong !
                                i just try to learn by asking some qustion !!

                                Comment

                                Working...