Could someone help me with this using c++? Part II: Application of Doubly Linked
ID: 673425 • Letter: C
Question
Could someone help me with this using c++?
Part II: Application of Doubly Linked List
You will implement a phone book of students. The phone book stores the last name, first name, 9-digit UIN, one phone number of each student. Students may have the same first name & last name.
Your phone book program will read a file of student data when it starts.
Your phone book program provides an interface for users to search in the phone book.
• The user will be asked to input the last name to search.
• If the program finds people with the same last name, the user will be asked to input the first name.
• Again if more than one people have that last and first name, the user will be asked to input the UIN for search.
Finally, the program will print the student record on screen.
• Data Structure
To speed up the search in the phone book, the data will be stored in a vector of 26 sorted doubly linked list. Each element of the vector, i.e. each doubly linked list, corresponds to an alphabet letter. For example, the first element of the vector, i.e. the first doubly linked list, v[0], corresponds to the letter ’A’. For examples, student records “Leyk, Teresa, 123456789”, “Lee, Bill, 000000000” and “Lee, Bill, 000000001” should be stored in the linked list at v[11], which corresponds to letter ’L’.
Again to speed up the search, each doubly linked list must be maintained in sorted order by last name, first name and UIN. For example, in that linked list, Lee people must be stored before Leyk, and “Lee, Bill, 000000000” must be store before “Lee, Bill, 000000001”.
Explanation / Answer
#include <iostream>
#include <string> //not necessary if you use char arrays
using namespace std;
int main()
{
struct Student
{
string First_name; // or char First_name[] with the max number of characters allowed in a First_name
string last_name; // or char First_name[] with the max number of characters allowed in a First_name
int UIN;
int phone_no
Student *next; //pointer to the next student
};
Student *head;
head = NULL;
Student *newStudent;
Student *Student_ptr;
newStudent = new Student;
newStudent->First_name = "Lee"
newStudent->Last_name = "Jan"
newStudent->UIN = "000000001"
newStudent->Phone_no = "0987654321"
newStudent->next = NULL;
if(!head)
head = newStudent;
else
{
Student_ptr = head;
while(Student_ptr -> next)
Student_ptr = Student_ptr -> next;
Student_ptr->next = newStudent;
}
return 0;
}
string S_First_name;
string S_Last_name;
int S_UIN;
int S_Phone_no;
for (int i = 0; i < 2; i++)
{
cout << "what is the students First_name: ";
cin >> S_First_name;
cout << "what is the students last_name: ";
cin >> S_last_name;
cout << "what is "<< S_UIN << "'s UIN: ";
cin >> S_UIN;
cout << "what is student phone number: ";
cin >> S_Phone_no;
Student *newStudent;
Student *Student_ptr;
newStudent = new Student;
newStudent->First_name = S_First_name;
newStudent->Last_name = S_Last_name;
newStudent->UIN = S_UIN
newStudent->Phone_no = S_Phone_no
newStudent->next = NULL;
if(!head)
head = newStudent;
else
{
Student_ptr = head;
while(Student_ptr -> next)
Student_ptr = Student_ptr -> next;
Student_ptr->next = newStudent;
}
cout << endl;
}
Student *Display_ptr;
Display_ptr = head;
while (Display_ptr)
{
cout << Display_ptr->First_name << endl;
cout << Display_ptr->Last_name << endl;
cout << Display_ptr->UIN<< endl;
cout << Display_ptr->Phone_no<<endl;
Display_ptr = Display_ptr->next;
cout << endl;
}