158k views
5 votes
Create a linked list for library patrons. Put at least 8 patrons in the list. (You should hard code this data.) Ask for a person's name. Tell if the person is in the list or not. If the person is in the list, show the person's information. Data fields are: Name, Library card number, Street, City, Zip

User Jbmilgrom
by
6.7k points

1 Answer

2 votes

Answer:

Step-by-step explanation:

#include <bits/stdc++.h>

using namespace std;

/* Link list node */

class Node

{

public:

string Name;

long Library_card_number;

string Street;

string City;

long Zip;

Node* next;

};

/* Given a reference (pointer to pointer) to the head

of a list and an int, push a new node on the front

of the list. */

void push(Node** head_ref,string name,long lcn,string street,string city,long zip)

{

/* allocate node */

Node* new_node = new Node();

/* put in the key */

new_node->Name = name;

new_node->Library_card_number = lcn;

new_node->Street = street;

new_node->City = city;

new_node->Zip = zip;

/* link the old list off the new node */

new_node->next = (*head_ref);

/* move the head to point to the new node */

(*head_ref) = new_node;

}

/* Checks whether the value x is present in linked list */

Node* search(Node* head, string x)

{

Node* current = head; // Initialize current

while (current != NULL)

{

if (current->Name == x)

return current;

current = current->next;

}

return NULL;

}

/* Driver program to test count function*/

int main()

{

/* Start with the empty list */

Node* head = NULL;

int x = 21;

/* Use push() to construct below list

14->21->11->30->10 */

push(&head, "Joe",1,"hippy Street","Bay area",2009);

push(&head, "Marie",2,"lippy street","san jose",2010);

push(&head, "Harry",3,"gippy Street","Bay area",2009);

push(&head, "Ashish",4,"dippy street","san jose",2010);

push(&head, "Zuck",5,"sippy Street","Bay area",2009);

push(&head, "Gates",6,"kippy street","san jose",2010);

push(&head, "Page",7,"pippy Street","Bay area",2009);

push(&head, "Brin",8,"dippy street","san jose",2010);

string name;

cout<<"Enter name of the person to search: ";

cin>>name;

Node* z = search(head,name);

if(z!=NULL){

cout<<"\\Person found in the list"<<endl;

cout<<"Name: "<<z->Name<<endl;

cout<<"Library Card Number: "<<z->Library_card_number<<endl;

cout<<"Street: "<<z->Street<<endl;

cout<<"City: "<<z->City<<endl;

cout<<"Zip: "<<z->Zip<<endl;

}else{

cout<<"No person found with the name "<<name<<endl;

}

return 0;

}

User TheKvist
by
6.8k points