473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C++ Implementing student registration program

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
31 16299
sicarie
4,677 Expert Mod 4TB
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
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
4,677 Expert Mod 4TB
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
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
4,677 Expert Mod 4TB
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
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
4,677 Expert Mod 4TB
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
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
4,677 Expert Mod 4TB
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
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
4,677 Expert Mod 4TB
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
Oh my God
i did not undarstand any thing about constructor
ah. it is very difucult
Nov 2 '07 #13
sicarie
4,677 Expert Mod 4TB
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
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
4,677 Expert Mod 4TB
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
iam so sorry
okey , i tray to corect my mistake

Student(string studentName)
{
studentName=name;
}

is this true now ?
Nov 2 '07 #17
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
4,677 Expert Mod 4TB
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
4,677 Expert Mod 4TB
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
thaanks alot
this is a deafult consractor , so how if i want to pass value in constructor ?
Nov 2 '07 #21
sicarie
4,677 Expert Mod 4TB
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
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
3,652 Expert 2GB
Yes, but what if the student has less than 4 classes? Where do you return true?
Nov 2 '07 #24
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
4,677 Expert Mod 4TB
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
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
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
Spoonfeeding is not allowed
Nov 3 '07 #29
^
!! what do you mean !!?
i did not do any thing wrong !
i just try to learn by asking some qustion !!
Nov 4 '07 #30
oler1s
671 Expert 512MB
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
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

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

Similar topics

0
by: faiza | last post by:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim objconn As New OleDbConnection("PROVIDER=MICROSOFT.JET.OLEDB.4.0;Data...
0
by: chilli | last post by:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'load Dim objconn As New...
4
by: kotoro | last post by:
I'm in an intro to computer programming course and just for the purposes of my test drivers and personal implementation, I would like to know if it is possible to force the program to wait for the...
3
by: Synapse | last post by:
hi everyone..im trying to create a student list program using linked list that will display all my info of students..but it seems theres a little prob. after i enter my first student the program will...
14
by: xtheendx | last post by:
I am writing a gradbook type program. It first allows the user to enter the number of students they want to enter. then allows them to enter the first name, last name, and grade of each student. The...
0
by: andrewst | last post by:
Originally posted by Taijixp Ask your teacher for help. -- Posted via http://dbforums.com
2
by: nirav11 | last post by:
# include <iostream> # include <fstream> # include <iomanip> # include <cstdlib> // needed for exit () using namespace std; int main() { ifstream inFile; ofstream outFile;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.