QUESTION: You can assume the following format for the text file :
U0001 45 89 55
U0002 89 11 8
U0003 77 23 11
U0009 22 90 99
U0010 67 45 23
U0011 86 34 56
The functional specfications of the functions are:
insertStudent – insert a student with the relevant information. The student node is to be inserted into the appropriate location in the list to ensure order is according to descending order of the average score.
updateStudent – updates the student identified by the student no, to the marks indicated.If the average score of the marks requires a change in the position of the node, the node needs to be shifted in order to preserve the descending order of the list. If the student cannot
be found, nothing is done.
my problem is the studentid it must be in char*no,instead of int.as for the function,void insertStudent(studentNode*& head, char *no, int s1=0, int s2=0, int s3=0)i nt sure whether i hv impement the function right or wrong.i nt sure hw to ensure the list to be in order according to descending order of the average score.
pls correct mi if i am wrong.as for the updateStudent the function,it must implement it tis way,void updateStudent(studentNode *head, const char *no, int s1,int s2, int s3).i realli do nt knw wat to do.i am so stuck.could you pls help mi.i am greatly appreciated for all the help from you.
using namespace std;
studentNode *next ;
void initializeList(studentNode*& head);
void read(studentNode*& head);
void insertStudent(studentNode*& head, char *no, int s1=0, int s2=0, int s3=0);
void updateStudent(studentNode *head, const char *no, int s1,int s2, int s3);
studentNode* head = NULL;
void initializeList(studentNode*& head)
head=NULL;//empty linked list
void read(studentNode*& head)
cout << "Filename: ";
cin >> filename;
if (temp == NULL)
cout << "An error occured: " << endl;
//To insert a node into the list
void insertStudent( studentNode*& head, char *no, int s1=0, int s2=0, int s3=0)
if( head == 0) // empty list, insert at head
head = new studentNode( no, s1, s2, s3, 0) ;
double avg = (s1 + s2 + s3) / 3.0 ; // average score
// search in list to determine correct place
studentNode* prev = head ;
studentNode* curr = head->next ;
while(prev != 0)
if( (curr == 0) || (curr->average() < avg))
// insert after prev, before curr
prev->next = new studentNode(no, s1, s2, s3, curr);
prev = curr;
curr = curr->next;
I have already mentioned that you need to put average in your structure. That way it will be easier to verify your software.
Moreover, it is good that you are using char string because that is what isdigit () takes. Also, you would not have to verify an int number because you already know it has to contain digits by definition.