943,948 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 764
  • C++ RSS
Dec 8th, 2008
0

please guy's i need help ASAP with my c++ assignmnet

Expand Post »
hi guy's , iam a new member i got stuck with my c++ assigment. i really want's your help

the program reads in a series of student data sets from the keyboard, stores
them in an ordered linked list of records, supports editing an existing record, and displays a
summary of all students entered. Each student’s record should contain the following fields:
First name
Last name
ID #
Midterm grade
Final Exam Grade
The linked list should be sorted by last name. The program should be menu driven, with the
following menu options:
Enter new student
Edit existing student (search by name)
Display list
Exit
The following details apply:
- Each student data record should be dynamically allocated
- The records should be stored in a linked list
- The records in the linked list should be sorted alphabetically by last name
- When editing is selected, the user should be prompted for the last name of the student record to edit.
--------------------------
this is what i wrote so far

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. #define SIZE 100
  7.  
  8. char ans;
  9.  
  10. int main ()
  11. {
  12.  
  13. cout <<" Welcome to bos3ayed C++ writer company "<<endl;
  14. cout << " this program help you to orginzing your student information";
  15. cout<<". first name , last name , ID, first midterm grade, and final"<<endl;
  16. cout <<endl<<endl;
  17. cout<< "Choose what do you want to do from this menu (a,b,c,d)"<<endl;
  18. cout<<"a) Enter new student"<<endl;
  19. cout<<"b) Edit existing student ( serch by name)"<<endl;
  20. cout<<"c) Display list "<<endl;
  21. cout<<"d) Exit"<<endl;
  22. cin>> ans;
  23.  
  24. }
  25.  
  26. class student_list
  27. {
  28. private:
  29. char First_name [SIZE];
  30. char Last_name [SIZE];
  31. int ID;
  32. float mid_grade,final_grade;
  33.  
  34. public:
  35. student_list *next;
  36. };
  37.  
  38. student_list::student_list() {
  39. student_list *temp , *head;
  40. temp = new student_list; // dynamiclly allocationg
  41. temp -> next = NULL;
  42. cout << "Enter student first name "<<endl;
  43. cin >> temp-> First_name;
  44. cout << "Enter student last name "<<endl;
  45. cin>> temp-> Last_name;
  46. cout<< "please enter student ID "<<endl;
  47. cin>>temp->ID;
  48. cout<<"please enter midterm grade"<<endl;
  49. cin>> temp->mid_grade;
  50. cout<<"please enter final grade"<<endl;
  51. cin>> temp->final_grade;
  52. }
  53.  
  54. student_list *head,*ptr,*tmp;
  55. head=NULL;
  56.  
  57. while () {
  58.  
  59. ptr=new student_list;
  60. temp=head;
  61. head=ptr;
  62. head->next=tmp;
  63.  
  64. }
----------------------------
thanks in advance;
Last edited by Ancient Dragon; Dec 8th, 2008 at 9:58 pm. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
q8y_4u is offline Offline
4 posts
since Dec 2008
Dec 8th, 2008
0

Re: please guy's i need help ASAP with my c++ assignmnet

Not sure where to start on this one... You haven't really followed the instructions. The instructions state that EACH student data record should be dynamically allocated. Instead your student list creates a static sized array of 100 records. What you need to do is make a StudentRecord class which stores info about one student. Your StudentList class should have add/remove/search methods. The add method should create a new instance of a StudentRecord object (dynamic allocation) and add it to the list. The code to ask for student details should NOT be in the StudentList class, but in the main and then passed to the add method.

Also, a menu-driven system should have a loop, otherwise you can only do one operation.
Reputation Points: 33
Solved Threads: 18
Junior Poster in Training
mahlerfive is offline Offline
77 posts
since Aug 2008
Dec 8th, 2008
0

Re: please guy's i need help ASAP with my c++ assignmnet

You can't have a function that has the same name of your class, how can you tell what's what?
You have some code outside the main function or any other functions, that doesn't seem right.

Hope this helps ^^
Reputation Points: 26
Solved Threads: 9
Junior Poster in Training
brechtjah is offline Offline
92 posts
since Nov 2008
Dec 11th, 2008
0

Re: please guy's i need help ASAP with my c++ assignmnet

thank you guy's thats helped

i did most of the codes exept when i create the link list and stored them it dose not save them alphabeticallly by last name , and when editing i confused alot of stuff i dont know how to search for them by last name and edit one of them like for example change their grade. Can you guys help me

this is the code


#include <iostream>

using namespace std;

#define SIZE 100


struct student_list
{
char First_name [SIZE];
char Last_name [SIZE];
int ID;
float mid_grade,final_grade;
student_list *next; // pointer to next link
};
student_list *head=NULL;
student_list *current;
int option =0;

void enter_student (){

student_list *temp,*start;
temp = new student_list; // dynamiclly allocationg

cout << "Enter student first name "<<endl;
cin >> temp-> First_name;
cout << "Enter student last name "<<endl;
cin>> temp-> Last_name;
cout<< "please enter student ID "<<endl;
cin>>temp->ID;
cout<<"please enter midterm grade"<<endl;
cin>> temp->mid_grade;
cout<<"please enter final grade"<<endl;
cin>> temp->final_grade;
temp -> next = NULL;

if (head == NULL ){
head = temp;
current = head;
}
else {
start=head;
while (start ->next !=NULL){
start=start->next;
}
start->next=temp;
}
}

void display_lists(){
student_list *temp;
temp=head;
cout<<endl;
if(temp==NULL)
cout<<"you didnt enter any thing at all!! your list is empty"<<endl<<endl;

else{

while(temp !=NULL){
cout<<"student name: "<<temp->Last_name;
cout<<","<<temp-> First_name<<endl;
cout<<"ID number: "<<temp->ID<<endl;
cout<<"first midterm grade: "<<temp->mid_grade<<endl;
cout<<"final exam grade: "<<temp->final_grade<<endl<<endl;
temp = temp -> next;
}
cout<< "LIST ENDED !"<<endl;
}
}

void edit(){
student_list *temp,*y;
int strcmp(char *name1,char *name2);

temp = head;
head = head -> next;
cout<<"enter student last name please: "<<endl;
cin>>name1-;
name2=name2->next;

if (name1 = name2){
return 0;
}
else if ( name1>name2){
return >0;
}
else if (name2>name1){
retun <0;
}
if(strcmp(y->name1,temp->name1)==0)
}

int main ()
{

head = NULL;
while ( option != 4){

cout <<"Welcome to bos3ayed C++ writer company "<<endl;
cout << " this program help you to orginzing your student information";
cout<<". first name , last name , ID, first midterm grade, and final"<<endl;
cout <<endl<<endl;
cout<< "Choose what do you want to do from this menu (1,2,3,4)"<<endl;
cout<<"1) Enter new student"<<endl;
cout<<"2) Edit existing student ( serch by name)"<<endl;
cout<<"3) Display list "<<endl;
cout<<"4) Exit"<<endl;
cin>> option;

switch (option){
case 1 : enter_student();
break;
case 3 : display_lists();
break;
case 2 : edit ();
break;


}
}
return 0;
system("pause");
}


--------------------------------------------------------------------------
thanks in advance,
Last edited by q8y_4u; Dec 11th, 2008 at 7:16 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
q8y_4u is offline Offline
4 posts
since Dec 2008
Dec 11th, 2008
1

Re: please guy's i need help ASAP with my c++ assignmnet

Please use code tags when posting code, preferably the language-specific version so we get syntax highlighting. It makes the code MUCH easier to read.

If you want the linked list to be ordered by last name, the convention is to put the record in the list where it belongs.

If the first record added is for "James Smith" then it is the only record. If we now want to add a record for "Bill Wilson", it should be added after "James Smith". If we then add a record for "Carol Fisher" if goes before "James Smith". Repeat as additional records are added and the list will always be sorted by last name.

So the code ends up looking something like:
c++ Syntax (Toggle Plain Text)
  1. // preinitialize the new record's next to null
  2. newstudent -> next = null;
  3.  
  4. student_list * prev = null;
  5. student_list * curr = head;
  6. // while there are more records to look at on the list
  7. while (curr != null)
  8. {
  9. // should the new record come before the 'current' record in the list?
  10. if (strcmp(newstudent -> Last_Name, curr -> Last_Name) < 0)
  11. {
  12. newstudent -> next = curr;
  13. break
  14. }
  15. prev = curr;
  16. curr = prev -> next;
  17. }
  18.  
  19. if (prev == null)
  20. head = newstudent
  21. else
  22. prev -> next = newstudent
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Dec 11th, 2008
0

Re: please guy's i need help ASAP with my c++ assignmnet

thank you i did the alphabetical order . now i am trying to edition one of the link list that i created like for example changing the name or grade or id.
this is the code



C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include < stdlib.h>
  3. using namespace std;
  4. #define SIZE 100
  5.  
  6. class student_list
  7. {
  8. public:
  9. char First_name [SIZE];
  10. char Last_name [SIZE];
  11. int ID;
  12. float mid_grade,final_grade;
  13. student_list *next; // pointer to next link
  14. };
  15.  
  16. student_list *head=NULL;
  17. student_list *current;
  18. int option =0;
  19.  
  20. void enter_student (){
  21.  
  22. student_list *temp,*ptr,*front,*back;
  23. temp = new student_list; // dynamiclly allocationg
  24. cout << "Enter student first name "<<endl;
  25. cin >> temp-> First_name;
  26. cout << "Enter student last name "<<endl;
  27. cin>> temp-> Last_name;
  28. cout<< "please enter student ID "<<endl;
  29. cin>>temp->ID;
  30. cout<<"please enter midterm grade"<<endl;
  31. cin>> temp->mid_grade;
  32. cout<<"please enter final grade"<<endl;
  33. cin>> temp->final_grade;
  34. temp -> next = NULL;
  35.  
  36. if (head == NULL ){
  37. head = temp;
  38.  
  39. }
  40. else {
  41.  
  42. front=head;
  43. if (front->Last_name > temp->Last_name){
  44.  
  45. head=temp;
  46. temp->next=front;
  47. }
  48. else
  49. while ( front->Last_name < temp->Last_name){
  50. back=front;
  51. front=front->next;
  52. }
  53.  
  54. }
  55.  
  56. }
  57.  
  58.  
  59. void display_lists(){
  60. student_list *temp;
  61. temp=head;
  62. cout<<endl;
  63. if(temp==NULL)
  64. cout<<"list is empty!"<<endl<<endl;
  65.  
  66. else{
  67.  
  68. while(temp !=NULL){
  69. cout<<"student name: "<<temp->Last_name;
  70. cout<<","<<temp-> First_name<<endl;
  71. cout<<"ID number: "<<temp->ID<<endl;
  72. cout<<"first midterm grade: "<<temp->mid_grade<<endl;
  73. cout<<"final exam grade: "<<temp->final_grade<<endl<<endl;
  74. temp = temp -> next;
  75. }
  76. cout<< "LIST ENDED !"<<endl;
  77. }
  78. }
  79.  
  80. void edit(){
  81.  
  82. char edit[SIZE];
  83. student_list *temp;
  84. cout<<"please enter the student last name"<<endl;
  85. cin>> edit;
  86.  
  87. while (edit,temp!=NULL){
  88. if (stcmp(
  89. cout<<"enter new student first name"<<endl;
  90. cin>> temp->First_name;
  91. cout<<"enter new student last name"<<endl;
  92. cin>>temp->Last_name;
  93. cout<<"enter new student ID"<<endl;
  94. cin>>temp->ID;
  95. cout>>"enter new first midterm grade"<<endl;
  96. cin<<temp->mid_grade;
  97. cout"enter new final grade"<<endl;
  98. cin>>temp->final_grade;
  99.  
  100. }
  101.  
  102. int main ()
  103.  
  104. {
  105.  
  106. head = NULL;
  107. cout <<"Welcome to bos3ayed C++ writer company "<<endl;
  108. cout << " this program help you to orginzing your student information";
  109. cout<<". first name , last name , ID, first midterm grade, and final"<<endl;
  110. cout <<endl<<endl;
  111. while ( option != 4){
  112. cout<< "Choose what do you want to do from this menu (1,2,3,4)"<<endl;
  113. cout<<"1) Enter new student"<<endl;
  114. cout<<"2) Edit existing student ( serch by name)"<<endl;
  115. cout<<"3) Display list "<<endl;
  116. cout<<"4) Exit"<<endl;
  117. cin>> option;
  118.  
  119. switch (option){
  120. case 1 : enter_student();
  121. break;
  122. case 3 : display_lists();
  123. break;
  124. case 2: edit();
  125. break;
  126.  
  127.  
  128.  
  129. }
  130. }
  131. return 0;
  132. system("pause");
  133. }

---------------------------------------
thanks in advance
Reputation Points: 10
Solved Threads: 0
Newbie Poster
q8y_4u is offline Offline
4 posts
since Dec 2008
Dec 11th, 2008
0

Re: please guy's i need help ASAP with my c++ assignmnet

Name search: You start at the head and while there are still entries on the list, you compare the names. If they match, you found it. (if the list is still in alphabetical order, you can stop when you find a name > than the one you're looking for.)

ID search: You start at the head and while there are still entries on the list, you compare the IDs. If they match, you found it.

Once you have found it, you need to be careful about the updates. It is usually best form to remove the one you found, update it and re-add it. (Because if the field that specifies the list order changes, you need to re-position the record in the list.)
Reputation Points: 344
Solved Threads: 116
Practically a Master Poster
Murtan is offline Offline
670 posts
since May 2008
Dec 13th, 2008
0

Re: please guy's i need help ASAP with my c++ assignmnet

thank youuuuuu veeeeeeeeeeeery much i finished it
Reputation Points: 10
Solved Threads: 0
Newbie Poster
q8y_4u is offline Offline
4 posts
since Dec 2008
Dec 13th, 2008
0

Re: please guy's i need help ASAP with my c++ assignmnet

I haven't seen any excutive-able code in the main( )
and you should declear when to exit the prog . i think , lucky……
Reputation Points: 10
Solved Threads: 2
Newbie Poster
AHUazhu is offline Offline
17 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: What should be my arguments for function called in main()
Next Thread in C++ Forum Timeline: unkown reason for error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC