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

First, the Python program prompts user to enter user information (name, email, and phone number). Then...
First, the Python program prompts user to enter user information (name, email, and phone number). Then it displays a menu called “Fish Information” that has the following fish type: 1. Cat Fish 2. Red Fish 3. Any other fish Let user choose the fish type that he/she got and input the length of the fish. Then the program will determine what should be done with this particular fish. Based on the following criteria: Criteria: Length: FISHTYPE - Cat Fish <10:...
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()); }...
( C programming ) Write a program that will process an arbitrary number of grades each...
( C programming ) Write a program that will process an arbitrary number of grades each time the program is run. (Hints: sentinel-controlled iteration.) If grade >= 90, its corresponding letter grade is A. If 80 <= grade < 90, its corresponding letter grade is B. If 70 <= grade < 80, its corresponding letter grade is C. If 60 <= grade < 70, its corresponding letter grade is D. If grade < 60, its corresponding letter grade is F....
C# Write a program in C# that prompts the user for a name, Social Security number,...
C# Write a program in C# that prompts the user for a name, Social Security number, hourly pay rate, and number of hours worked. In an attractive format, dis- play all the input data as well as the following: » Gross pay, defined as hourly pay rate times hours worked » Federal withholding tax, defined as 15% of the gross pay » State withholding tax, defined as 5% of the gross pay » Net pay, defined as gross pay minus...
C programming Get a number from the user and write a program that checks to see...
C programming Get a number from the user and write a program that checks to see if the inputted number is equal to x*x+x and x must be greater than 0. For example, if the user inputs 12. The program should check to see if 12 = x*x+x. In this case it is true because 3*3+3 = 12.
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT