Double - double.cpp Phone Number Database An example of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// double.cpp // Phone Number Database // An example of using a doubly-linked list. / // compiler directives #include<fstream.h> #include<iostream.h> #include<iomanip.h> #include"apstring.h" # // global structures and variables struct friend_node { apstring last_name; apstring first_name; apstring phone_num; friend_node *next; friend_node *previous; }; friend_node *head_ptr; friend_node *current_ptr; // function prototypes void handle_choice(int choice); void add_record(); void insert_node(friend_node *new_rec_ptr); friend_node *position_insertion_point(apstring &lastname); void make_node_new_head(friend_node *new_rec_ptr); void add_node_to_end(friend_node *new_rec_ptr); void move_current_to_end(); void display_list(); void delete_record(); void delete_head_of_list(); void delete_end_of_list(friend_node *previous_ptr); void delete_from_middle_of_list(friend_node *previous_ptr); int verify_delete(); void delete_node(friend_node *previous_ptr); void delete_list(); void search_by_lastname(); void display_next_record(); void display_previous_record(); void load_list_from_file(); void write_list_to_file(); v // main function int main() { int choice; head_ptr = NULL; // Initialize head pointer to NULL. load_list_from_file(); // Load data from the disk file into linked list. current_ptr = head_ptr; do { // Display menu. cout << "\nFRIEND DATABASE\n"; cout << "0 - Exit program\n"; cout << "1 - Add record\n";
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cout << "3 - Search for friend by last name\n"; cout << "4 - Delete record\n"; cout << "5 - Display next record\n"; cout << "6 - Display previous record\n"; cout << "Enter choice: "; cin >> choice; handle_choice(choice); // Call function to direct flow based on choice. } while(choice != 0); // Repeat menu until user chooses to exit return 0; } // end of main function } // function to direct program flow based on user's choice void handle_choice(int choice) { switch(choice) { case 0: write_list_to_file(); if(head_ptr != NULL) { delete_list(); } break; case 1: add_record(); // add a record to the linked list break; case 2: display_list(); // display all records in linked list break; case 3: search_by_lastname(); // search for record by last name break; case 4: delete_record(); // search for record by last name break; case 5: display_next_record(); break; case 6: display_previous_record(); break; default : cout << "\nInvalid choice\n"; break; } } // Function to add record to the linked list. void add_record() { friend_node *new_rec_ptr; // Declare temporary pointer for the new node. new_rec_ptr = new friend_node; // Allocate memory for a new node and // initialize pointer to point to it. if(new_rec_ptr != NULL) // If no error allocating memory, get data { // and insert node. // Get name and phone number from the user.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/20/2011 for the course COMPUTER 12 taught by Professor Aymanboghdady during the Spring '11 term at American College of Computer & Information Sciences.

Page1 / 10

Double - double.cpp Phone Number Database An example of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online