Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write to similiar like this: #include <stdio.h> #include <string.h> typedef stru

ID: 3554773 • Letter: W

Question

Write to similiar like this:

#include <stdio.h>

#include <string.h>

typedef struct name {

   char firstname[16];

   char lastname[20];

   char phoneNumber[11];

   } phoneBookRecord;

void printerFunction{ phoneBookRecord[]};

main ()

{

  

   phoneBookRecord addressBook[20];

   strcpy(addressBook[0].firstName,

Please turn in two separate .e source files as solutions for the given problems on Blackboard. Please submit all files only once, and all in one place. Remember to add your name, class section, title and date at the top of each file (similar to HW-1) and also to have standard file names. Each file name have to follow this naming standard: Your last name_Asignment Number_Program name.c (e.g. smith_ assignment3_ textStatistics. c) Your task is to write a Phonebook program. Your program should be able to add new contacts to its database, also it should be able to search for contacts using the names of the contacts provided as input by user. To do so you should create a structure named Phonebook. It must contain two members, name and phoneNumber (Char array with maximum length of 10 only numbers). Your phonebook must hold at least 10 entries. You program needs to perform following tasks using functions and present the following menu choices to the user: Add a new record to phonebook Search for a particular record based on name of the contact Display the list of the contacts in the phonebook Quit the program You will need an array of your structure, with size 10. To make life easier even- time you run your program, you can add some contact information inline your code, so you don't need to enter information even- time you want to test your program. It is better to write your program using 3 functions, a function for adding information to your program, a function for searching through your saved contact info and a function for displaying everything. You can have more or less functions depending on your design.

Explanation / Answer

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

//typedef struct to define what's in the phonebook
typedef struct PhoneBookContacts
{
    char Name[20];
    char Surname[20];
    char PhoneNumber[20];
} phone;

//Function prototypes
void AddEntry (phone[]);
void PrintEntry (phone[]);
void Sort (phone[]);
int counter = 0; //Global counter variable used to keep track of number of contacts

//Begin main function
int main (void)
{
    phone phonebook[20]; //Phonebook instance
    char userChoice; //Variable to use to select menu choice

    while (userChoice != 'Q') {
        printf ("*************** ");
        printf ("Please enter a command: ");
        printf("'1': Add an entry ");
        printf("'2': Sort entries ");
        printf("'3': Print the phonebook ");
        printf("'4': Quit ");
        printf ("*************** ");

        scanf("%s", &userChoice); //Stores menu choice into variable userChoice

        // Add Contact
        if (userChoice == '1')
            AddEntry(phonebook);

     

        //Print Contacts
        if (userChoice == '2')
            PrintEntry(phonebook);

        //Sort Contacts
        if (userChoice == '3')
            Sort(phonebook);

        //Quit
        if (userChoice == '4') {
            printf("Phonebook will now quit.");
            return 0;
        }
    }
}

//Function Definition to Add Contacts to the Phonebook
void AddEntry (phone phonebook[]) {
    counter++; //global counter increase

    printf(" First Name: ");
    scanf("%s", phonebook[counter-1].Name); //counter-1 b/c arrays start at 0

    printf("Last Name: ");
    scanf("%s", phonebook[counter-1].Surname);

    printf("Phone Number (XXX-XXX-XXXX): ");
    scanf("%s", phonebook[counter-1].PhoneNumber);

    printf(" %s added to phonebook ", phonebook[counter-1].Name); //tell user friend added
}

// Function def to print contacts
void PrintEntry (phone phonebook[]) {
    int x = 0;
    printf(" Phonebook entries: ");

    for ( x = 0; x < counter; x++) {
        printf(" (%d) ", x+1); //Show contact number
        printf("Name: %s %s ", phonebook[x].Name, phonebook[x].Surname); //Name
        printf("Number: %s ", phonebook[x].PhoneNumber); //Number
    }
}

void Sort (phone phonebook[]) {
    phone temp;
    int i; int j;

    for (i=0; i<19; i++) {
        for (j=i+1; j<19; j++) {
            if (strcmp(phonebook[i].Surname, phonebook[j].Surname) > 0) {
                temp=phonebook[i];
                phonebook[i]=phonebook[j];
                phonebook[j]=temp;
            }
        }
    }
}