Question
THis program must be written in the C language. This assignment involves arrays, structs, strings and files. Write an application that can read data records
THis program must be written in the C language. This assignment involves arrays, structs, strings and files. Write an application that can read data records from a file to an array of structs. The data must be formatted to be in the proper case whereas the first letter of each word must be capital and the remaining in lower case as its read into the array of structs. Also write a function to sort the array by the last name and then by the first name. Use strcmp() to sort it. example: David Riverra would create a concatenated string such as Riverra David)
-You must swap the data in both arrays simultaneously. Also use a swap function to swap the structs and strings simultaneously as well. The application will need to find a persons record in an array of structs by using a binary search. The structs will have to store only digits of the birthdays, SSN and phone numbers. Write functions so that you can format the birthday, SSN and phone number make it appear more legible (example: 01/25/1986, 483-99-7754 and 236-880-1212) Last part of the assignment is to write the data out to a file as mailing labels.
Data required for struct is: ( add this into the code)
id An integer value representing the persons unique id within the system
first_name A string representing the first name (should be 25 chars)
last_name A string representing the last name (should be 25 chars)
address A string representing the address (should be 35 chars)
city A string representing the city (should be 25 chars)
state A string representing the state (should be 3 chars)
zip A string representing a Zip code (should be 6 chars)
phone A string representing the phone number (should be 11 chars)
birth A string representing the birth date (should be 9 chars)
ssn A string representing the Social Security number (should be 10 chars)
gender A char representing gender (should be 1 chars)
These are the functions that are needed to create this application. (Use these functions within the code as well)
main Main function with menu and data declarations.
proper Convert a string to proper case.
read Read the file into the array of structs (make sure to convert to proper case).
copy Copy all of the data from one struct to another.
swap Swap the data in two structs.
sort Sort the array of structs by last then first name (you can use selection or bubble sort).
isSorted Test an array to see if it is sorted.
find Find a persons data in the array by first and last name. Should return the index of the persons record if found, -1 otherwise. This should use a binary search.
datef Format as a date. Returns a string in a readable format for a date (i.e. 01/01/2000).
ssnf Format as a SSN. Returns a string in a readable format for an SSN (i.e. 190-89- 6543).
phonef Format as a phone number. Returns a string in a readable format for a phone number (i.e. 215-555-1212).
print Print a record to screen using the birth date, ssn and phone formats as shown in Figure 1
write Writes the records out to a file to be used as mailing labels as shown in the figures below. There should be a blank line separating each mailing label in the file.
There is no data missing from the struct, Its okay to use strtok() to express the records as they are read from the file. Since there are spaces within the data, you should use fegts() to read the lines of text instead of Fscanf() to read the formatted text from the files. This application will require a specific menu to navigate its primary functions. They are:
1: read the file
2: sort the records
3: Find a record
4: write mailing labels
5: exit
Write read function
Read a line from the file (and print it to screen)
Tokenize the line (and print data to screen)
Copy data to a struct (May want to write print to test this)
Copy all data to an array of structs
Write function to convert to proper case and test and use in read function
Write format date, ssn and phone functions
Write print function and test
Write copy function and test
Write the sort function and test
Write find function and test
Write the write mailing label function and test
Please write a C program using structs, arrays, files and strings that can give an output as the picture provided.
Please add comments in between to show what you have done so I can follow it. Thumbs up for showing that code works in command prompt or terminal.
Just an example of format. This is screen output for a struct. Figure 1 Just an of ID Name: John Summers Address: 678 S Morland St City: California State CA Zip 90012 234-878-1234 Phone 123-345-6543 SSN: Birth Date: 01/23/1976 Gender M Figure 2 As a mailing Label John Summers 678 S Morland St California, CA 90012 Just an example of format. This is screen output for a struct. Figure 1 Just an of ID Name: John Summers Address: 678 S Morland St City: California State CA Zip 90012 234-878-1234 Phone 123-345-6543 SSN: Birth Date: 01/23/1976 Gender M Figure 2 As a mailing Label John Summers 678 S Morland St California, CA 90012
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started