Tuesday, August 18, 2009

CHEAT 1



#include
using namespace std;

struct node {
char name[20]; // Name of up to 20 letters
int age;
float height;
node *nxt; // Pointer to next node
};
node *start_ptr = NULL;

void add_node_at_end () {
node *temp, *temp2; // Temporary pointers
// Reserve space for new node and fill it with data
temp = new node;
cout < cin >> temp->name;
cout << "Please enter the age of the person : ";
cin >> temp->age;
cout << "Please enter the height of the person : ";
cin >> temp->height;
temp->nxt = NULL; // Set up link to this node

if (start_ptr == NULL)
start_ptr = temp;
else {
temp2 = start_ptr;
// We know this is not NULL - list not empty!
while (temp2->nxt != NULL) {
temp2 = temp2->nxt; // Move to next link in chain
}
temp2->nxt = temp;
}
}

void display_node(){
node *temp;

temp = start_ptr;
do {
if (temp == NULL)
cout << "End of list" << endl;
else {
// Display details for what temp points to
cout <name << endl;
cout << "Age : " <<>age << endl;
cout << "Height : " <<>height << endl;
cout << endl; // Blank line // Move to next node (if present)
temp = temp->nxt; }
} while (temp != NULL);

}

void delete_start_node() {
node *temp; temp = start_ptr;
start_ptr = start_ptr->nxt;
delete temp;
cout<<"The first record has been deleted"<}


int main(){

int choice;
do{
cout< cout<<"[2] Display Record"< cout<<"[3] Delete Record"< cout<<"[4] Exit"< cout<<"Choice:";
cin>>choice;

switch(choice){
case 1:
{add_node_at_end();
break;}
case 2:
{display_node();
break;}
case 3:
{delete_start_node();
break;}
default:
cout<<"Thank You...";
}
}while(choice!=4);

system("PAUSE");
return 0;

}

E postLabels=

No comments:

Post a Comment