2 Replies - 1005 Views - Last Post: 23 January 2013 - 08:22 AM Rate Topic: -----

#1 teohenrui  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-January 13

C++ program student recording system

Posted 23 January 2013 - 07:21 AM

Hei everybody, I'm new to the C++ link-list feature. Now I'm having a problem with one of my program. The problem which I face is on the int main part. So, I just wanna ask if anyone can help me on the last part... What should I write under case b, c and d ? Here is the code which I have by far:

#include<iostream>
#include<string>

using namespace std;

class studentDet
{   private:
        struct node
        {
            string name;
			double cgpa;
			int id;
			string prog;
			int progcode;
			node *link;
			studentDet* next;
        }*head;          
     public:
		 studentDet();
         void InsNew(string name, int id, string prog, int progcode,double cgpa);
		 void UpdateS(string name, int id, string prog, int progcode,double cgpa);
         void PrintList();
         bool SearchId(int id);
         void DeleteNode();         
         ~studentDet();
};
///////////////////////////////////////////////////////
studentDet::studentDet()
{
     head=NULL;
}
studentDet::~studentDet()
{
   node *q;
   if( head == NULL )
        return;

   while( head != NULL )
   {
      q = head->link;
      delete head;
      head = q;
   }
}
//////////////////////////////////////////////////////

/* Inserting a New Student Node (always last) */
void studentDet::InsNew(string name, int id, string prog, int progcode,double cgpa)

{	node *newNode, *prev;
	newNode = new node;
	newNode->name = name;
	newNode->id = id;
	newNode->prog = prog;
	newNode->progcode = progcode;
	newNode->cgpa;
	newNode->link = NULL;	
    if (head == NULL)
       head = newNode;
    else
    { 	prev = head;
    	
        while ((prev->link) != NULL)
    		prev = prev->link;
    		
        prev->link = newNode;
     }
     
}


///////////////////////////////////////////////

/*Update anywhere Reinsert
void studentDet::UpdateS(string name, int id, double cgpa, char prog, int progcode);
{ node *newNode, *prev;
	newNode = new node;
	newNode->name = name;
	newNode->id = id;
	newNode->prog = prog;
	newNode->progcode = progcode;
	newNode->cgpa;
	newNode->link = NULL;


///////////////////////////////////////////


	*/

void studentDet::PrintList()
{    node *current;
    current = head;    
   
	while (current != NULL)
	{
		cout<<"\n\n------------Student Info------------"<<endl;
		cout<<"Name: \tID: \tProgramme: \tProgramme Code: \tCGPA: "<<endl;
		cout<<current->name;
		cout<<"\t"<<current->id;
		cout<<"\t\t"<<current->prog;
		cout<<"\t"<<current->progcode;
		cout<<"\t"<<current->cgpa;
		current=current->link;
	}
}
/////////////////////////////////////////
bool studentDet::SearchId(int id)
{
    node *current;
    current = head;
   	bool found;
    found = false;
    
    while ((current != NULL) && (!found))
    { 
    		if (current->id == id)
      		  found = true;
    		else
 		      current = current->link;
    }
        return found;
}
/////////////////////////////////////////////////  

/* Deleting the Last Node */
void studentDet::DeleteNode()
{   node *PreviousNode, *CurrentNode;
    if (head != NULL)
    {   if (head->link == NULL)
        {
        	delete head;
        	head = NULL;
        }
        else
        {       PreviousNode = head;
               CurrentNode = head->link;            
               while ((CurrentNode->link) != NULL) 
               {   	PreviousNode = CurrentNode;
            	    CurrentNode = CurrentNode->link;
               }            			
               PreviousNode->link = NULL;
               delete CurrentNode;
        }
     }
}
///////////////////////////////////////////////

int main()
{   
	studentDet list;
	string name;
	int id;
	char prog[20];
	int progcode;
	double cgpa;
    char selected;
	int cont;

	do {
	
		cout<<"A. Add a student information."<<endl;
		cout<<"B. Update a student information."<<endl;
		cout<<"C. Delete a student information."<<endl;
		cout<<"D. Print."<<endl;
		cout<<"E. Search."<<endl;
		cin>>selected;

		switch (selected)
		{
		case 'a':
		case 'A':
		cout<<"Please Fill In The Following Blanks"<<endl;
		cout<<"Enter Name: ";
			cin>>name;
			cout<<"\nEnter ID: ";
			cin>>id;
			cout<<"\nEnter Programme: ";
			cin>>prog;
			cout<<"\nEnter Programme Code: ";
			cin>>progcode;
			cout<<"\nEnter CGPA: ";
			cin>>cgpa;
			list.InsNew(name, id, prog, progcode, cgpa);
			
			break;

		case 'b':
		case 'B':

			
		break;

		case 'c':
		case 'C':
		
		break;

		case 'd':
		case 'D':
			void PrintList();
		
		break;

		case 'e':
		case 'f':
			break;}

	} 


	while ( cont=1);
			

    system("pause");

    getchar();        
    getchar();
    return 0;

}



Is This A Good Question/Topic? 0
  • +

Replies To: C++ program student recording system

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4231
  • View blog
  • Posts: 13,276
  • Joined: 25-December 09

Re: C++ program student recording system

Posted 23 January 2013 - 08:14 AM

Quote

What should I write under case b, c and d ?

Code to update a student ( b ), code to delete a student ( c ), and code to print the students ( d ). You may want to think about calling some of your class funcitons with the proper parameters.

You need to show what you have tried and ask specific questions. We will not write the solution for you.

Jim

This post has been edited by jimblumberg: 23 January 2013 - 08:15 AM

Was This Post Helpful? 0
  • +
  • -

#3 MathewS  Icon User is offline

  • D.I.C Regular

Reputation: 18
  • View blog
  • Posts: 346
  • Joined: 14-May 02

Re: C++ program student recording system

Posted 23 January 2013 - 08:22 AM

You have the code there.

For updating you will want to use the search function that you have implemented. create another search function that will return a pointer to the student record.

For deleting it's similar you will want to use a search to find the student to delete, then change the previous node to point to the next node. Then delete that student.
Something similar to this, just depends what type of linked list you are using, and this isn't going to be perfect.
S = Find Student;
Prev = S->prevnode;
Prev->nextnode = S->nextnode;
Next = S->next;
Next->prevnode = S->prevnode;
Delete S;



You have printing so I assume you mean E, which you can use the search function you would implement for the updating/deleting.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1