Reference no: EM132395657
Contacts
Assignment 1
The two (2) assignments this semester will revolve around building a Contact system that is searchable and efficient.
In the first assignment, you will build a Contact structure that contains other structures representing the contact Name, Address and phone Numbers.
Milestone 1
Download or clone Assignment 1
Open the project file for MS1 and look inside. You will find a file named contacts.h. The .h extension identifies this file as a header file. Header files contain declarations of structs and function prototypes. In this header file, the struct Name is already declared.
Structure Name has three (3) members: firstName, a C string that can hold up to 30 characters middleInitial, a C string that can hold up to 6 characters, and lastName, a C string that can hold up to 35 characters.
struct Name
{
char firstName[31]; char middleInitial[7]; char lastName[36];
};
Declare two (2) more structures named Address, and Numbers, in the header file, contacts.h
Structure Address has five (5) members: streetNumber, street, apartmentNumber, postalCode, and
city.
streetNumber: int, (logic for this field should enforce values greater than 0) street: C string, up to 40 characters
apartmentNumber: int, (logic for this field should enforce values greater than 0) postalCode: C string, up to 7 characters
city: C string, up to 40 characters
Structure Numbers has three (3) members: cell, home, and business. These are all C strings that can hold up to 10 characters.
Milestone 2
Application Logic
Open the project file for MS2 and look inside. You will find a source file named a1ms2.c. Use this file and in it code the main() function by implementing the following. Make sure that your project contains the contacts.h header file from milestone 1:
• Declare a variable of type Name (use a self-describing variable name) to be used for storing a
contact's full name
- Initialize each member to an empty C string
• Declare a variable of type Address (use a self-describing variable name) to be used for storing a contact's address information
- Initialize the members so numeric values are set to zero and char arrays are set to an empty C string
• Declare a variable of type Numbers (use a self-describing variable name) to be used for storing a
contact's phone(s) information
- Initialize each member to an empty C string
• Display to the screen a welcome message:
>Contact Management System<
Contact Name
• Prompt the user to enter the required member data for the Name type. First, ask for the first name:
>Please enter the contact's first name: <
- Read and store the C string value the user enters into the appropriate Name member
• Prompt the user if a middle initial(s) value needs to be entered (see figure: 1.2.1 above regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered proceed with the next member entry otherwise
prompt for the middle initial(s):
- >Please enter the contact's middle initial(s): <
- Read and store the C string value the user enters into the appropriate Name member
• Prompt the user to enter the last name:
>Please enter the contact's last name: <
- Read and store the C string value the user enters into the appropriate Name member
Contact Address
• Prompt the user to enter the required member data for the Address type. First, ask for the street number:
>Please enter the contact's street number: <
- Read and store the number entered by the user into the appropriate Address member
- Hint: Review the specifications for this structure member's valid values
• Prompt the user to enter the street name:
>Please enter the contact's street name: <
- Read and store the C string value the user enters into the appropriate Address member
• Prompt the user if an apartment number needs to be entered (see figure: 1.2.1 above regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered proceed with the next member entry otherwise
prompt for the apartment number:
- >Please enter the contact's apartment number: <
- Read and store the number entered by the user into the appropriate Address member
- Hint: Review the specifications for this structure member's valid values
• Prompt the user to enter the postal code:
>Please enter the contact's postal code: <
- Read and store the C string value the user enters into the appropriate Address member
• Prompt the user to enter the city:
>Please enter the contact's city: <
- Read and store the C string value the user enters into the appropriate Address member
Contact Numbers
• Prompt the user to enter the required member data for the Numbers type. First, prompt the user if a cell phone number needs to be entered (see figure: 1.2.1 above regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered proceed with the next member entry otherwise
prompt for the cell phone number:
- >Please enter the contact's cell phone number: <
- Read and store the number entered by the user into the appropriate Numbers member
• Prompt the user if a home phone number needs to be entered (see figure: 1.2.1 above regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered proceed with the next member entry otherwise prompt for the home phone number:
- >Please enter the contact's home phone number: <
- Read and store the number entered by the user into the appropriate Numbers member
• Prompt the user if a business phone number needs to be entered (see figure: 1.2.1 above regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered don't prompt for this value otherwise prompt for
the business phone number:
- >Please enter the contact's business phone number: <
- Read and store the number entered by the user into the appropriate Numbers member
Test the above logic and your 3 structures by referring to the below sample output (input's are
identified in RED). Your output should match exactly:
Milestone 2 Reflection
Please provide answers to the following in a text file named reflect.txt.
In three or more paragraphs and a minimum of 150 words, explain what you learned while doing these first two milestones. In addition to what you learned, your reflection should also include the following:
• Can you think of a more efficient way to ask a user to add the required information to each data field? Justify your thoughts with an example.
• Discuss the differences between a C string and a primitive character array. What would happen if you attempt to display the contents of a primitive character array (not a C string) using the printf specifier "%s"?
Milestone 3
A struct is a data type that contains data members, as you have seen in MS1 and MS2. Up to now the members of our structs have always been comprised of the primitive data types that are part of the C language (int, float, double, char, and arrays of these types). The C language defines a data member as a member of any type, other than its own type. So, this means that a struct can contain not only the primitive types but also any type that we ourselves create.
Open the project file for MS3 and look inside. Modify the contacts.h header file to include your work from MS2 and declare another struct named Contact. Contact has three (3) data members, user-defined types Name, Address and Numbers. The Name type member should be called "name", the Address type member should be called "address", and the Numbers member should be called "numbers".
Milestone 4
The focus of this milestone is to change the data input process to use functions.
Open the project file for MS4 and look inside. Review the contacts.h file and copy the contents from your work in MS3 where the comments indicate.
Define the following function prototypes in contacts.h
NOTE:
Only code the prototypes - NOT the full definitions in this file. For additional help on defining functions and function prototypes please refer to the file functionsAndHeaderFiles.pdf in this milestone directory.
Below is a list of the function prototypes with a full description of what each function should do.
void getName(struct Name *name) - Receives a pointer to a Name and performs the actions described below.
• Prompt the user to enter the required member data for the Name type. First, ask for the first name:
>Please enter the contact's first name: <
- Read and store the C string value the user enters into the appropriate Name member
• Prompt the user if a middle initial(s) value needs to be entered (see figure: 1.2.1 in milestone 2 above regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered proceed with the next member entry otherwise
prompt for the middle initial(s):
- >Please enter the contact's middle initial(s): <
- Read and store the C string value the user enters into the appropriate Name member
• Prompt the user to enter the last name:
>Please enter the contact's last name: <
- Read and store the C string value the user enters into the appropriate Name member
void getAddress(struct Address *address) - Receives a pointer to an Address and performs the actions described below.
• Prompt the user to enter the required member data for the Address type. First, ask for the street number:
>Please enter the contact's street number: <
- Read and store the number entered by the user into the appropriate Address member
- Hint: Review the specifications for this structure member's valid values
• Prompt the user to enter the street name:
>Please enter the contact's street name: <
- Read and store the C string value the user enters into the appropriate Address member
• Prompt the user if an apartment number needs to be entered (see figure: 1.2.1 in milestone 2 regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered proceed with the next member entry otherwise
prompt for the apartment number:
- >Please enter the contact's apartment number: <
- Read and store the number entered by the user into the appropriate Address member
- Hint: Review the specifications for this structure member's valid values
• Prompt the user to enter the postal code:
>Please enter the contact's postal code: <
- Read and store the C string value the user enters into the appropriate Address member
• Prompt the user to enter the city:
>Please enter the contact's city: <
- Read and store the C string value the user enters into the appropriate Address member
void getNumbers(struct Numbers *numbers) - Receives a pointer to a Numbers and performs the actions described below.
• Prompt the user to enter the required member data for the Numbers type. First, prompt the user if a cell phone number needs to be entered (see figure: 1.2.1 in milestone 2 above regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered proceed with the next member entry otherwise
prompt for the cell phone number:
- >Please enter the contact's cell phone number: <
- Read and store the number entered by the user into the appropriate Numbers member
• Prompt the user if a home phone number needs to be entered (see figure: 1.2.1 in milestone 2 above regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered proceed with the next member entry otherwise
prompt for the home phone number:
- >Please enter the contact's home phone number: <
- Read and store the number entered by the user into the appropriate Numbers member
• Prompt the user if a business phone number needs to be entered (see figure: 1.2.1 in milestone 2 above regarding optional values for example prompt)
- Evaluate the entered value; if an ‘n' is entered don't prompt for this value otherwise prompt for
the business phone number:
- >Please enter the contact's business phone number: <
- Read and store the number entered by the user into the appropriate Numbers member
Open the file contacts.c and define the full function definitions (where the comments instruct). Hint: The logic for these functions are already done from MS2 found in file a1ms2.c
Milestone 4 Reflection
Please provide answers to the following in a text file named reflect.txt.
In three or more paragraphs and a minimum of 150 words, explain what you learned from doing milestones three and four. In addition to what you learned, your reflection should also include the following:
• An explanation of why you think this assignment has asked you to code a struct, Contact, that holds three other structs as data members.
• An explanation why it would be poor design to pass a pointer to type Contact as an argument in the functions getName, getAddress, and getNumbers.
Attachment:- Contacts.rar