Question

In: Computer Science

Programming C: Write a program for a Rolodex of contact information (e.g., name, phone number, email)...

Programming C: Write a program for a Rolodex of contact information (e.g., name, phone number, email) implemented as a linked list. The program will ask the user to enter a new contact information, retrieve/print a person’s contact information, and to delete a person. It will maintain the linked list in alphabetical order by last name. It will also allow the user to search for a person’s contact information by last name. Assume that all last names are unique.

Solutions

Expert Solution

//C program

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct node{
   char firstName[20];
   char lastName[20];
   int phoneNumber;
   char email[25];
   struct node*next;
}Node;

void Insert(Node** head, Node* new_node)
{
Node* current;
  
if (*head == NULL || strcmp((*head)->lastName,new_node->lastName)>0)
{
new_node->next = *head;
*head = new_node;
}
else
{

current = *head;
while (current->next!=NULL && strcmp(current->lastName,new_node->lastName)<0)
{
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}

void print(char *name,Node*head) {
   while(head &&strcmp(head->lastName,name)!=0)head = head->next;
   if(!head){
       printf("Not found in list \n");
       return;
   }
   printf("Name : %s %s \n",head->firstName,head->lastName);
   printf("Phone Number : %d\n",head->phoneNumber);
   printf("Email : %s\n\n",head->email);
  
}
void deletion(Node**head,char*name){
   Node* temp = *head, *prev;
if (temp != NULL && strcmp(temp->lastName,name)==0)
{
*head = temp->next;
free(temp);
return;
}
while (temp != NULL && strcmp(temp->lastName,name)!=0)
{
prev = temp;
temp = temp->next;
}

if (temp == NULL) return;
prev->next = temp->next;
  
free(temp);
}

int main(){
   Node*head=NULL;
   int choice;
   char first[20],last[20],email[25];
   int phone;
  
   do{
       printf("\n1:insert\n2:print\n3:Delete\n4:Quit\nEnter choice : ");
       scanf("%d",&choice);
       switch(choice){
           case 1:{
               printf("Enter first name : ");
               scanf("%s",first);
               printf("Enter last name : ");
               scanf("%s",last);
               printf("Enter phone number : ");
               scanf("%d",&phone);
               printf("Enter Email : ");
               scanf("%s",email);
               Node*newNode = (Node*)malloc(sizeof(Node));
               strcpy(newNode->firstName, first);
               strcpy(newNode->lastName, last);
               newNode->phoneNumber= phone;
               strcpy(newNode->email, email);
               Insert(&head,newNode);
              
               break;
           }
           case 2:{
               printf("Enter last name : ");
               scanf("%s",last);
               print(last,head);
               break;
           }
           case 3:{
               printf("Enter last name : ");
               scanf("%s",last);
               deletion(&head,last);
               break;
           }
           case 4:{
               printf("\nthank you!\n");
               break;
           }
           default:{
               printf("Invalid choice\n");
               break;
           }
       }
   }while(choice!=4);
  
   return 0;
}

//sample output


Related Solutions

C++ program: Define a structure to hold the contact's information including: name, phone number, and a...
C++ program: Define a structure to hold the contact's information including: name, phone number, and a pointer to the next node on the list. Each node on the list will be a contact instead of a number (like the example in the book). struct ContactNode { string name; string phoneNumber; ContactNode *next; } Define a class containing the structure, private member variable head (that will point to the beginning of the list) and the following member functions: A constructor that...
Write a class named ContactEntry that has fields for a person’s name, phone number and email...
Write a class named ContactEntry that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five ContactEntry objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. I repeat, NO-ARG constructors....
Using the given file, ask the user for a name, phone number, and email. Display the...
Using the given file, ask the user for a name, phone number, and email. Display the required information. These are the Files that I made: import java.util.Scanner; public class Demo5 { public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.println("New number creation tool"); System.out.println("Enter name"); String name = keyboard.nextLine(); System.out.println("Enter phone number"); String phoneNumber = keyboard.nextLine(); System.out.println("Enter email"); String email = keyboard.nextLine(); Phone test1 = new SmartPhone(name, phoneNumber, email); System.out.print(test1); System.out.println("Telephone neighbor: " + ((SmartPhone) test1).getTeleponeNeighbor()); }...
In.java A phone number has the format (xxx)yyy-zzzz ( e.g.(942)731-2262 ). Write a program that reads...
In.java A phone number has the format (xxx)yyy-zzzz ( e.g.(942)731-2262 ). Write a program that reads a string and formats it as a phone number. First it should check that the string has exactly 10 symbols. If it does, the program will print the formatted version. If the string does not have exactly 10 symbols, print Invalid and do not process it. You do NOT need to verify that the symbols in the string are digits. Sample run 1... This...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
Write a C program for a library automation which gets the ISBN number, name, author and...
Write a C program for a library automation which gets the ISBN number, name, author and publication year of the books in the library. The status will be filled by the program as follows: if publication year before 1985 the status is reference else status is available. The information about the books should be stored inside a linked list. The program should have a menu and the user inserts, displays, and deletes the elements from the menu by selecting options....
Write a C++ program to display toy name
Write a C++ program to display toy name
java programming write a program with arrays to ask the first name, last name, middle initial,...
java programming write a program with arrays to ask the first name, last name, middle initial, IDnumber and 3 test scores of 10 students. calculate the average of the 3 test scores. show the highest class average and the lowest class average. also show the average of the whole class. please use basic codes and arrays with loops the out put should look like this: sample output first name middle initial last name    ID    test score1 test score2...
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
C PROGRAMMING Build a hotel management program. The user will register their name and put their...
C PROGRAMMING Build a hotel management program. The user will register their name and put their check-in time and check-out time. They can choose their type of room they stay (Deluxe room, junior suite room, suite room, presidential suite room). Then, the program will determine the total price. *NOTE - Using modular, user-friendly, and array usage programming. Please don't use struct/structure and pointer. - Please give explanation about the code.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT