By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,108 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,108 IT Pros & Developers. It's quick & easy.

C++ Implementing student registration program

P: 25
Hi

i have a qustion plz help me to understand and solve it
Expand|Select|Wrap|Line Numbers
  1. Phase One Problem description
  2. You are required to implement a student registration system. The system keeps information about the students including their id, which is an automatic number issued by the system, a name, and current number of courses. It is important to keep the count of courses a student is currently enrolled in since he is only allowed to register for 4 courses at any given point in time. The system should facilitate course registration and dropping through appropriate functions. The system should also keep record of the date in which the student enrolled.
  3. Information about courses is also needed. For each course, the id and number of credits is stored. The id of the course is a single string composed of two parts: a two character code specifying the major (e.g. CS for Computer Science, MA for Mathematics, EC for economics.. etc) and a serial number, which, unlike the code, is generated by the system.
  4.  
  5. Task A
  6. Create a header file for the class student which contains the following header, then write its implementation file.                
  7.  
  8. #ifndef STUDENT_H_
  9. #define STUDENT_H_
  10.  
  11. #include <iostream>
  12. #include <string>
  13. using namespace std;
  14.  
  15. class Student{
  16.     private:
  17.         static int serialId;
  18.         const int id;
  19.         string name;
  20.         int currentCourses;
  21.         bool canRegisterMore();
  22.  
  23.     public:
  24.         Student(string studentName);
  25.  
  26.         bool registerCourse();
  27.  
  28.         void dropCourse();
  29.  
  30.         void printDetails();
  31.  
  32. };
  33. #endif /*STUDENT_H_*/
  34.  
Just help me to know the meaning of each line , and what is the work of each function

i hope to see you help in quick time
thanks.
Nov 2 '07 #1
Share this Question
Share on Google+
31 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
Well, instead of me going through each line, why don't you post which lines you're having trouble with so we can concentrate on those?
Nov 2 '07 #2

P: 25
Thank you for your post
but i did not undarstand the qustion above the code because iam not in good level to undrstand all english word

i just want you to explain it , so i will no what i shall do
sorry of my bad language
but i just in level one and i want your help plz
then i will try to write the code and i want you correct my mistake

iam waiting for you
Nov 2 '07 #3

sicarie
Expert Mod 2.5K+
P: 4,677
Part of programming is being able to look at an assignment and break it down into separate, easy to manage parts. So, what part are you working on right now, just the Task A, or the number 2?
Nov 2 '07 #4

P: 25
sorry, but i dont undarstand what do you mean
but i can say
iam working in task A
but i did not undarstand this qustion
Expand|Select|Wrap|Line Numbers
  1. You are required to implement a student registration system. The system keeps information about the students including their id, which is an automatic number issued by the system, a name, and current number of courses. It is important to keep the count of courses a student is currently enrolled in since he is only allowed to register for 4 courses at any given point in time. The system should facilitate course registration and dropping through appropriate functions. The system should also keep record of the date in which the student enrolled.
  2. Information about courses is also needed. For each course, the id and number of credits is stored. The id of the course is a single string composed of two parts: a two character code specifying the major (e.g. CS for Computer Science, MA for Mathematics, EC for economics.. etc) and a serial number, which, unlike the code, is generated by the system.
  3.  
  4.  
i want a simple explaning to it , so maybe i will know how to solve task A
Nov 2 '07 #5

sicarie
Expert Mod 2.5K+
P: 4,677
Okay, well, they way I look at this would be at least 2 classes - a student class and a course class. The student class will need the information above (as will the course class), and then you will have to create a main to allow creating and modifying students to add/drop courses (maybe creating courses as well).

You're really going to have to come up with a more specific question than "I don't understand this" for us to help - I can read it and understand it. What part of it are you having trouble conceptualizing as code?
Nov 2 '07 #6

P: 25
thanks alot , you are patient of my qustions
okey .. may you start with me step by step? because iam junior in C++


Expand|Select|Wrap|Line Numbers
  1. Student(string studentName);
first, this is constructor and i know that we always use it for initializing , but here i do not no what to put in the body of it ? i do not know what the need of it
Nov 2 '07 #7

sicarie
Expert Mod 2.5K+
P: 4,677
information about the students including their id, which is an automatic number issued by the system, a name, and current number of courses. It is important to keep the count of courses a student is currently enrolled in since he is only allowed to register for 4 courses at any given point in time. The system should facilitate course registration and dropping through appropriate functions. The system should also keep record of the date in which the student enrolled.
So this is where you will get your data types that you need. I would recommend just sticking with the default constructor first (no string initialization yet), as it will be easier to just have get/set methods.

Student( )

Then what variables can you see in the above that you will need for the Student class to have?
Nov 2 '07 #8

P: 25
okey it is easy now

i will initializ these data inside the constructor

{
name =0;
id=0;
currentCourses=0;
}

is it correct ??
Nov 2 '07 #9

sicarie
Expert Mod 2.5K+
P: 4,677
okey it is easy now

i will initializ these data inside the constructor

{
name =0;
id=0;
currentCourses=0;
}

is it correct ??
Partially. This is why I haven't written any code yet - you identified the right variables, but the implementation is not quite correct. This is a 'constructor' so these values will be created when the object Student is created. This means your variables need types. You have the right types being assigned to two of them, but you need to tell the compiler what type everything is.

For example - is 0 a name? And then for id and currentCourses, you just need to prepend them with their declarations - which you have correctly identified as integers.

But this comes into an issue - where are you going to decide what the id is? These should be unique, so you need to make sure that there are no other existing students with this id. The easiest (not best) solution is to create an int in your main(), and use that to trigger your setID() method, just be sure to increment it every time it is used.
Nov 2 '07 #10

P: 25
Partially. This is why I haven't written any code yet - you identified the right variables, but the implementation is not quite correct. This is a 'constructor' so these values will be created when the object Student is created. This means your variables need types. You have the right types being assigned to two of them, but you need to tell the compiler what type everything is.

For example - is 0 a name? And then for id and currentCourses, you just need to prepend them with their declarations - which you have correctly identified as integers.
Yes, thats right , but where i need to write the type ?
you mean thats why we must write the variables as parameter , like student name here :

Student(string studentName)
and then i write
studentName=0;
or what !!


But this comes into an issue - where are you going to decide what the id is? These should be unique, so you need to make sure that there are no other existing students with this id. The easiest (not best) solution is to create an int in your main(), and use that to trigger your setID() method, just be sure to increment it every time it is used.
okey , can i put function to test the id ?
and put inside it if statment ?
Nov 2 '07 #11

sicarie
Expert Mod 2.5K+
P: 4,677
Yes, thats right , but where i need to write the type ?
you mean thats way we must write the variables as parameter , like student name here :

Student(string studentName)
and then i write
studentName=0;
or what !!
Well, even looking at that it's incorrect = is 0 a string like you're passing? I wouldn't pass anything to your constructor yet - you don't have to have the variables instantiate immediately upon creation (though it's a good idea to at least set them to 0 or an empty string just in case you do forget to set them later). Then after the object is created, you should have a get*() and set*() method for each so that you can manipulate them (because I'm sure you wouldn't violate good programming practice and set them as public variables). Such as getID() and setID(int i_IDNum), or getName() and setName(string s_Name).

The type goes directly in front of the declaration of the variable, as I said before.

okey , can i put function to test the id ?
and put inside it if statment ?
Yep. That sounds like a good idea.
Nov 2 '07 #12

P: 25
Oh my God
i did not undarstand any thing about constructor
ah. it is very difucult
Nov 2 '07 #13

sicarie
Expert Mod 2.5K+
P: 4,677
Here, this is a pretty good site with good code examples. I would recommend going through that to learn a bit more about OOP.
Nov 2 '07 #14

P: 25
thanks alot , i will read more and more
but i need to solve task1 today , because it must be with me tomorow in college

so , pllllllllllllllllz may you help me and give me the solve of it
i was very tired , thats why i was absent in many lecture
now just help me in this task because no time
and i promise you ,, i will work hard and undarstand good
and solve the next tasks in next week
of course with your help

so , may you solve it ? for just this time ?
Nov 2 '07 #15

sicarie
Expert Mod 2.5K+
P: 4,677
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.
Nov 2 '07 #16

P: 25
iam so sorry
okey , i tray to corect my mistake

Student(string studentName)
{
studentName=name;
}

is this true now ?
Nov 2 '07 #17

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

sicarie
Expert Mod 2.5K+
P: 4,677
iam so sorry
okey , i tray to corect my mistake

Student(string studentName)
{
studentName=name;
}

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
Expand|Select|Wrap|Line Numbers
  1. Student::Student()
  2. {
  3.    string name = "";
  4. }
  5. void setName(string studentName)
  6. {
  7.    name = studentName;
  8. }
  9. string getName()
  10. {
  11.    return name;
  12. }
  13.  
Nov 2 '07 #19

sicarie
Expert Mod 2.5K+
P: 4,677
Expand|Select|Wrap|Line Numbers
  1. Student::Student()
  2. {
  3.    name = "";
  4. }
  5. void setName(string studentName)
  6. {
  7.    name = studentName;
  8. }
  9. string getName()
  10. {
  11.    return name;
  12. }
  13.  
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::Student() 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.
Nov 2 '07 #20

P: 25
thaanks alot
this is a deafult consractor , so how if i want to pass value in constructor ?
Nov 2 '07 #21

sicarie
Expert Mod 2.5K+
P: 4,677
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=studentName;
Nov 2 '07 #22

P: 25
okey
now in this method
bool canRegisterMore()

i wrote

{
if (currentCourses>4)
return false;
}

is this a correct syntax of bollean method ?
Nov 2 '07 #23

Ganon11
Expert 2.5K+
P: 3,652
Yes, but what if the student has less than 4 classes? Where do you return true?
Nov 2 '07 #24

P: 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 ?
Nov 2 '07 #25

sicarie
Expert Mod 2.5K+
P: 4,677
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.
Nov 3 '07 #26

P: 25
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..

Expand|Select|Wrap|Line Numbers
  1. #include”student.h”
  2. Student::Student(string studentName)
  3. {
  4. Name=studentName;
  5. }
  6.  
  7. bool Student::canRegisterMore()
  8. {
  9. if (currentCourses>=4)
  10. return false;
  11. else
  12. return true;
  13. }
  14.  
  15.  
  16.  
  17. bool Student::registerCourse()
  18. {
  19. if(canRegisterMore()==true)
  20. {
  21. currentCourses++;
  22. return true;
  23. }
  24.     else
  25. return false;
  26. }
  27.  
  28. void Student::dropCourse()
  29. {
  30. if(currentCourses!=0)
  31. currentCourses--;
  32.  
  33. }
Nov 3 '07 #27

P: 25
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 !
Nov 3 '07 #28

P: 9
Spoonfeeding is not allowed
Nov 3 '07 #29

P: 25
^
!! what do you mean !!?
i did not do any thing wrong !
i just try to learn by asking some qustion !!
Nov 4 '07 #30

Expert 100+
P: 671
Your intentions and efforts are good. You’ve tried honestly to write code. But take a step back and look at what is happening here. You’re making no efforts to dissect a problem. When faced with a question, a function to implement, a constructor to write, there is no sign that you made an effort to think about it. You simply throw up your hands and say, “help me, because I don’t understand this”.

You ask us what to write for print(). Think about it carefully. Try and see if you can make it work. If it doesn’t work, figure out why it didn’t. You cannot keep running to someone and asking, “is this the right idea?”. You need to be able to think, experiment, and figure things out.

Part of being a computer programmer is being able to try out possible solutions, and deal with a bad idea. Our assistance here has crossed the line. You need to try out things yourself. When something doesn’t work, come back here. If you have no idea what you’re doing, then you’ve either not been doing your coursework properly, or you need to reread your books and notes.

We aren’t being mean. You can’t learn if someone keeps telling you what the right answer is all the time.
Nov 4 '07 #31

P: 25
Thanke you
i cant say any thing because you was talking very polite
and most thanks to all helpful person here
and iam sorry


good buy
: (
Nov 5 '07 #32

Post your reply

Sign in to post your reply or Sign up for a free account.