Hi guys. Thanks for yesterday's help.I still have a few problems. The AddMiddleNode function doesnt not work properly even though I worked it out alot of times. And then there's the DeleteNode function. Whenever i prompt it to delete a roll number, it deletes all of them except the one next to it. Theres also the Status struct that I have NO idea what to do with it. But I want to resolve the other errors first.
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string>
usingnamespace std;
/* The menu options are defined here */
#define ADD 1
#define DELETE 2
#define MODIFY 3
#define SEARCH 4
#define DISPLAY 5
#define EXIT 6 // if you add some thing after this make sure to modify the condition
// of the do while loop.
/************************************/
/* The constant fileds */
constint LEN_NAME =10;
constint LEN_EMAIL =20;
constint LEN_TELNO =15;
/*Enumerated types for the status of the students */
enum StatusT {REGISTERED, ENROLLED, GRADUATED, CLOSED, DROPEDOUT };
// This Corresponds to above enum to convert the values into string
char *StatusStr[] = {"Registered", "Enrolled", "Graduated", "Closed", "Dropedout"};
/* The declaration of the student recrod type node. You can declare
* as many variable of this type as you like. Each one of them is
* going to have the same fields/atributes but of their own.
*/
struct NodeT {
int RollNo;
char Name[LEN_NAME];
char Section;
char Email[LEN_EMAIL];
char TelNo[LEN_TELNO];
int delRoll;
StatusT Status;
NodeT *Next;
};
/* This is a global variable
* Should always points to the first node of list
*/
NodeT *Head = NULL;
/* Prototypes of the functions used in the C++ program file.
* If you add a new function in your program do not forget to
* put its prototype here. Any prototype declaration in the program file
* will heart your grade.
*/
void AddNewNode();
void AddFirstNode(NodeT*);
void AddLastNode(NodeT*);
void DeleteNode();
void ModifyNode();
void DisplayNode(NodeT*);
void DisplayCompleteList();
bool AddMiddleNode(NodeT*);
NodeT *GetNewNode();
NodeT *SearchNode();
#include "LinkList.h" // This is our own header file
/*****************MAIN*****************/
int main(){
int choice;
NodeT *NewNode;
NodeT *Record;
while(1){
do {
cout << "\n\n\n\n\n";
cout << "============================" << endl;
cout << " MAIN MENU " << endl;
cout << "============================" << endl;
cout << " "<< ADD <<": Add a new record" << endl;
cout << " "<< DELETE <<": Delete a record" << endl;
cout << " "<< MODIFY <<": Modify a record" << endl;
cout << " "<< SEARCH <<": Search a record" << endl;
cout << " "<< DISPLAY<<": Display" << endl;
cout << " "<< EXIT <<": Exit" << endl;
cout << "============================" << endl;
cout << " Your choice :";
cin >> choice;
} while ((choice < ADD) || (choice > EXIT));
switch (choice){
case ADD : if(Head == NULL)
Head = GetNewNode();
else
AddNewNode();
break;
case DELETE : DeleteNode(); /* Call the Approprecordriate functions */
break;
case MODIFY : ModifyNode(); /* Call the appropriate functions */
break;
case SEARCH : SearchNode(); /* Search and dispalay the of a student */
break;
case DISPLAY: DisplayCompleteList(); /* shoudl display the complete list */
break;
case EXIT : cout<<"Thankyou for using this program...Good day"<<endl;
system("pause");
return 0;
} // switch(choice)
} // while(1)
system("pause");
} //main()
.
.
.
.
/*****************AddNewNode*****************/
void AddNewNode(){
NodeT *NewNode;
NewNode = GetNewNode();
NodeT *Current;
Current = Head;
while(Current->Next != NULL)
Current= Current->Next;
//Current= Current->Next;
if(NewNode->RollNo < Head->RollNo)
AddFirstNode(NewNode);
elseif( NewNode->RollNo > Current->RollNo )
AddLastNode(NewNode);
else
AddMiddleNode(NewNode);
/* Do the required declarations
*
*
* Make sure step I and step II have been done
*
*
* Now check the first possibility: i.e. adding in the front of list.
* else check for second possibility: i.e adding at the end of list.
* else it is to be added in the middle.
*
*/
}
/*****************AddMiddleNode*****************/
bool AddMiddleNode(NodeT *NewNode){
NodeT *Current;
Current = Head;
bool check = false;
while(Current->Next != NULL)
{
if(check = false)
{
if(Current->Next->RollNo > NewNode->RollNo)
{
NewNode->Next = Current->Next;
Current->Next = NewNode;
NewNode = NULL;
}
Current= Current->Next;
check = true;
}
}
returntrue; // This is a dumy statement to resolve the compiler error
}
.
.
.
.
/*****************DeleteNode*****************/
void DeleteNode(){
NodeT *temp, *temp1, *ptr;
temp1 = new NodeT;
cout << "Enter Roll# to delete: ";
cin >> temp1->delRoll;
while (Head != NULL && Head->RollNo <= temp1->delRoll)
{
temp = Head->Next;
delete[] Head;
Head = temp;
}
if (Head == NULL)
return;
ptr = Head;
while (ptr->Next != NULL)
{
if (ptr->Next->RollNo = temp1->delRoll)
{
temp = ptr->Next->Next;
delete[] ptr->Next;
ptr->Next = temp;
}
else
ptr = ptr->Next;
}
return;
/*
* Ask the user which node s/he wants to delete
* search the required node in the list
* if the node is found then remove it form the list
* free the memory reserved for the node by using delete operator.
*
* Make sure to handel differnt possibilites that may arrise due to
* deletion of the node.
*
*/
}