Write a program (attach source file of your program and include its source code your answer script too )
that does the following
[HINT] Implement a linked list and traverse the linked list [20]
Source code:-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//a structure of a single entry in the phonebook defined as a
contact
typedef struct {
//each contact is defined with a name limited to 20
characters
char name[20];
//and a telephone number
//using char because printing of an integer starting
with a 0 is not possible
//treating as a string instead will enable
printing
char telephone[20];
char email[20];
}Contact;
//a function that prints the information on a contact on
position "position"
//takes a pointer to the array of contacts later created in the
main
void printContact (Contact *contacts,int position)
{ printf("Name:");
printf("%s\n",contacts[position].name);
printf(" Telephone number:");
printf("%s\n",contacts[position].telephone);
printf("Email:");
printf("%s\n",contacts[position].email);
}
//a function that prints out all the contacts in the
phonebook
//takes a pointer pointing to the phonebook array and a number
showing the number of contacts already entered in the
phonebook
void printPhonebook(Contact *contacts,int number)
{
if(number==0)
{
printf("The phone book is
empty!");
}
else{
//counter
int i;
//starting from 0th index to index
number-1 do in a cycle
for (i=0;i<number;i++)
{
//print each
contact information...
//through
calling the function printContact and taking i as the wanted
position each time
printf("%d.",i+1);
printContact(contacts,i);
}
}
}
//a function that adds a new contact in the phonebook on index
"index" where number is the number of contacts already existing in
the phonebook
void addContact(Contact *contacts, int index)
{
printf("Add a new contact:\n");
printf("Name:");
scanf("%s",contacts[index].name);
printf("Telephone number:");
scanf("%s",contacts[index].telephone);
printf("Email Address:");
scanf("%s",contacts[index].email);
}
int main()
{
printf("************PHONEBOOK************");
//initializing size of counter
size_t contactCounter=0;
//define a counter of type Contact
Contact *contactsPtr;
//allocate memory using calloc
//check difference between calloc and malloc?
contactsPtr=(Contact*)calloc(0,sizeof(Contact));
//define an integer variable select in which the wanted option of
the menu is entered by the user
int select;
//do in a cycle while
do{
printf("\nChoose\n"
"1- ADD A CONTACT\n"
"2- SHOW THE PHONEBOOK\n"
"3- EXIT\n");
printf("\nSelect option:");
//store user intput in variable select
scanf("%d",&select);
//clear the input buffer?
getchar();
//set up menu options matching corresponding functions
switch(select)
{case 1: //Add a contact
//increase variable contactCounter
as the user chose to add a contact
contactCounter++;
//reallocate memory of the contacts
ptr by increasing size by 1
contactsPtr=(Contact*)realloc(contactsPtr,
contactCounter*sizeof(Contact));
//call the function
addContact
addContact(contactsPtr,contactCounter-1);
break;
case 2: //Show the phone book
//calling the function
printPhonebook
printPhonebook(contactsPtr,contactCounter);
break;
case 3: //Exit
break;
default: printf("You entered an invalid selection.
Please try again\n");
break;
}
}while(select!=3);
printf("Goodbye!");
//pause the program until user inputs any character
getchar();
//return value
return 0;
}
-----------------------------------------------------------------------------------------------------------
Output:-
*****************************************************************************************
if you are satisfy with my answer then please ,please like it.
*********************************************************************************
if you have any issue with my code then please write in comment section before downvoting my answer.
Write a program (attach source file of your program and include its source code your answer...
This program is used to create a phonebook for storing contact information into a text file. The program begins by asking the user to provide a name for the file that will contain their phone book information. It will then ask the user to provide the names and numbers of their contacts. It should keep asking the user for contact information until they type in Done (case-sensitive). After the user types Done, store all contact information into the file name...
USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot be viewed from outside of the private class. //only the class functions within the class can access private members. private: string name; string email; string phone; //the public class is accessible from anywhere outside of the class //however can only be within the program. public: string getName() const { return name; } void setName(string name) { this->name = name; } string getEmail() const {...
Linux & Unix Write a bash program to indent the code in a bash source file. Conditions: The source file will contain only printing characters, spaces, and newlines. It is not necessary to check for invalid input. The source file will not contain comments (words beginning with #). Requirements: Read from standard input, write to standard output. Code inside while statements should be indented 2 spaces. Be sure your program includes all of the following: ...
Write this in a C program please. Structures on Disk The Problem Your task is to write a program that stores and retrieves structures in a file on disk. The file of structures must remain on the disk once your program ends. You should be able to store structures to the file and retrieve from the file after restarting the program. The record that you will be writing to file has the following structure: struct contact {unsigned long phone_number; long...
In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. MUST BE IN PYTHON FORMAT Create the folllowing objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...
In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. Must Be In Python Format Create the following objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...
(Count the occurrences of each keyword) Write a python program that reads in a Python source code file and counts the occurrence of each keyword in the file. Your program should prompt the user to enter the Python source code filename.
You should implement several functions that the Phone Contacts program will need Each function with take in data through the parameters (i.e., variables names listed in parentheses) and make updates to data structure that holds the contact information, return, or print information for a particular contact. The parameters needed are listed in the table below and each function is described below that 1. Make an empty dictionary and call it 'contacts'. Where in your code would you implement this? Think...
C# ONLY INCLUDE BOTH PSUDEO CODE AND SOURCE CODE!!!! Design (pseudocode) and implement (source code) a program (name it IndexOfLargest) to find the index of the first largest value in the array. Note that the largest value may appear more than once in the array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method findIndex() that takes a single-dimensional...
Write a program that does the following in Python Code: Stores the following three lists: last_name = ["Smith", "Jones", "Williams", "Bailey", "Rogers", "Pyle", "Rossington"] first_name =["Lisa", "Bill", "Jay", "Sally", "Walter","Jake","Gary"] phone_number =["240-233-1921", "301-394-2745", "571-321-8934", "703-238-3432", "703-947-9987", "301-945-3593", "240-671-3221"] Has a function named combine_lists() that takes in last_names, first_names and phone_numbers as lists and returns a dictionary called phone_book that uses last_name as the key and a list consisting offirst_name and phone_number. Has a main function that iterates through the phone_book...