In this assignment, you will write one (1) medium size C program. The program needs to be structured using multiple functions, i.e., you are required to organize your code into distinct logical units. The following set of instructions provide the specific requirements for the program. Make sure to test thoroughly before submitting.
Write a program,
named program1.c, that
reads and processes
employee records (data
about an employee).
Each employee record
must be stored
using a struct that
contains the following
fields:
• Name o All
alphabetic. o Max of
60 characters long. o
Includes first, middle,
and last name,
separated by spaces.
It is not necessary
to split the name
into separate fields.
- Mailing Address
o This field
is a struct
embedded within the
employee struct, containing
the following fields:
- Street address (max
49 chars). § City
name (max 29
chars).
- Two-character state
abbreviation. No spaces.
- Zip code (5-digit
number). No spaces.
Process as character
data.
- Annual salary (a
float). No punctuation
or dollar sign.
The database consists
of a collection of
employee records. You
may assume that
this program is for
a small business,
so no more than
50 employee records
need to be stored.
However, the exact
number is not known
beforehand.
Users will enter
all of the data
for each employee
in a single line
of text: • Records
may be typed at
the console or
stored in a file.
Hence, it is
important to test
using both interactive
user input and
input redirection. o Make
sure to test for
end of file. • Each
record is in the
form of comma-separated
values. • There is
a new-line character
at the end of
each record, i.e.,
only one record per
line.
The program responds
to two commands:
:Q
Exits the program
:P Displays the
contents of the
database
Sample data
Kyle N. Jones,123 Any Street,Raleigh,NC,27615,25000 Eileen Maria
Garces,915 Oak Circle,Plano,TX,75074,65000
Assume that employee
records will always
be entered using
the format described
above, i.e.,
name,address,city,state,zip,salary. Note
that individual fields
may contain
spaces. You may
also assume that
all of the fields
will contain data,
i.e., it is not
necessary to handle
missing fields.
Implementation
Your program must
be structured using
multiple functions, in
addition to main,
as follows:
void parse_data(char * buffer, struct employee * employee); void
get_next_field(char * buffer, char * field); void
print_employee_db(int total_employees, struct employee
employees[]); void print_employee(struct employee employee);
1. The parse_data function
parses a line of
data and stores the
contents in an
employee struct. Both
fields are passed-in
by reference.
2. The get_next_field function
reads the next data
field in the input
and stores its
contents in
a string (character
array). Both fields
are passed-in by
reference.
3. The print_employee_db
function displays the
contents of the
employee database on
the console.
4. The print_employee function
displays the contents
of one employee
record on the
console.
The number of
employees is not
known in advance
and your program
cannot ask the user
how many. The
program must continue
processing employee records
until the user
enters “:Q” to quit
the program or the
end of file is
detected in the
input.
Output
The program’s output
must be formatted
exactly as in the
examples shown below.
It is recommended
that you use the
following formatting strings,
where appropriate:
"Enter employee data [:Q to exit, :P to show database]:\n" "Done.
Good bye!\n" "\nCurrent Employee Database: \n" "\n\n"
"\nEmployee Record:\n----------\n\tName: %s\n" "\tStreet Address:
%s \n" "\tCity: %s \n" "\tState: %s \n" "\tZip: %s \n" "\tSalary:
$%.2f \n----------\n"
Some sample runs
are provided below.
User input is in
bold typeface.
Sample #1
Enter employee data [:Q to exit]: :Q Good bye!
Sample #2
Enter employee data [:Q to exit, :P to show database]: Kyle N.
Jones,123 Any Street,Raleigh,NC,27615,25000 Enter employee data [:Q
to exit, :P to show database]: :P
Current Employee Database:
Employee Record: ---------- Name: Kyle N. Jones Street Address: 123
Any Street City: Raleigh State: NC Zip: 27615 Salary: $25000.00
----------
Enter employee data [:Q to exit, :P to show database]: :Q Done.
Good bye!
Sample #3
Enter employee data [:Q to exit, :P to show database]: Kyle N.
Jones,123 Any Street,Raleigh,NC,27615,25000 Enter employee data [:Q
to exit, :P to show database]: Eileen Maria Garces,915 Oak
Circle,Plano,TX,75074,65000 Enter employee data [:Q to exit, :P to
show database]: :P
Current Employee Database:
Employee Record: ---------- Name: Kyle N. Jones Street Address: 123
Any Street City: Raleigh State: NC Zip: 27615 Salary: $25000.00
----------
Employee Record: ---------- Name: Eileen Maria Garces Street
Address: 915 Oak Circle City: Plano State: TX Zip: 75074 Salary:
$65000.00 ----------
Enter employee data [:Q to exit, :P to show database]: :Q Done.
Good bye!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
struct Employee
{
char name[60];
struct Address
{
char street[49];
char city[29];
char state[2];
char zip[5];
}address;
float salary;
};
struct Employee employee[50];
void get_next_field(char * buffer, char * field)
{
sscanf(buffer, "%[^,]", field);
}
void parse_data(char * buffer, struct Employee * emp)
{
char sal[10];
get_next_field(buffer, emp->name);
buffer = strstr(buffer, ",") + 1;
get_next_field(buffer, emp->address.street);
buffer = strstr(buffer, ",") + 1;
get_next_field(buffer, emp->address.city);
buffer = strstr(buffer, ",") + 1;
get_next_field(buffer, emp->address.state);
buffer = strstr(buffer, ",") + 1;
get_next_field(buffer, emp->address.zip);
buffer = strstr(buffer, ",") + 1;
get_next_field(buffer, sal);
emp->salary = atof(sal);
}
void print_employee(struct Employee emp)
{
printf("%s ",emp.name);
printf("%s ",emp.address.street);
printf("%s ",emp.address.city);
printf("%s ",emp.address.state);
printf("%s ",emp.address.zip);
printf("%f \n",emp.salary);
}
void print_employee_db(int n, struct Employee employees[])
{
int i;
printf("\n******** Employees Data **********\n\n");
printf("\n-----------------------------------------");
printf("\nName\t\tStreet\t\tcity\tstate\tzip\tsalary\n");
printf("\n-----------------------------------------");
for(i=0; i<n; i++)
{
printf("\n");
print_employee(employee[i]);
}
printf("\n-----------------------------------------");
}
int main()
{
FILE *f;
int i, n = 2;
char buffer[150];
char ch;
do{
printf("\nEnter employee data [:Q to exit, :P to show
database]:");
scanf("%c", &ch);
fflush(stdin);
switch(ch)
{
case 'Q':
case 'q': printf("Q Good bye! ");
exit(0);
case 'P':
case 'p':
f = fopen("file.txt", "r");
if(f==NULL)
{
printf("File cannot be open\n");
getch();
return 1;
}
for(i=0; i<n; i++){
//canf(f,"%[^\n]", buffer);
fgets(buffer, 150, f);
parse_data(buffer, &employee[i]);
}
print_employee_db(n, employee);
fclose(f);
break;
default: f = fopen("file.txt", "a");
if(f==NULL)
{
printf("File cannot be open\n");
getch();
return 1;
}
gets(buffer);
fprintf(f, "%s \n", buffer);
n++;
fclose(f);
}
}while(1);
fclose(f);
getch();
return 0;
}
Output:
Enter employee data [:Q to exit, :P to show database]:p
******** Employees Data **********
-----------------------------------------
Name Street city state zip salary
-----------------------------------------
Kyle N. Jones 123 Any Street Raleigh NC27615 27615 25000.000000
Eileen Maria Garces 915 Oak Circle Plano TX75074 75074 65000.000000
-----------------------------------------
Enter employee data [:Q to exit, :P to show database]:
In this assignment, you will write one (1) medium size C program. The program needs to...
Write a program in C++: Using classes, design an online address book to keep track of the names first and last, addresses, phone numbers, and dates of birth. The menu driven program should perform the following operations: Load the data into the address book from a file Write the data in the address book to a file Search for a person by last name or phone number (one function to do both) Add a new entry to the address book...
Lab Assignment – Database Implementation and Security In this lab you will create a Microsoft Access database of employee information and secure the table username and password security. Steps Enter data for five employee records. Each record should have fields: Employee ID (5 digits), First Name, Last Name, Home Address, Hire Date Create a query that displays Employee ID, First Name and Last Name. Create a form that requires entering username and password to access employee table. Error message should...
****Using C and only C**** I have some C code that has the function addRecord, to add a record to a linked list of records. However, when I run it, the program exits after asking the user to input the address. See picture below: Here is my code: #include<stdio.h> #include<stdlib.h> struct record { int accountno; char name[25]; char address[80]; struct record* next; }; void addRecord(struct record* newRecord) //Function For Adding Record at last in a SinglyLinkedList { struct record *current,*start,*temp;...
C++: Array of contact info Design a contact struct, that takes your phone struct and address struct along with a c string for a name to create a record of contact information. ( C++: Design a Struct Design two structs address and phone Address has the following attributes: street address, city name, state code, zip code. phone has 3 numbers: area code, prefix and suffix test these by writing a program that creates one of each and fills them with...
Customer Accounts This program should be designed and written by a team of students. Here are some suggestions: Write a program that uses a structure to store the following information about a customer account: • Name • Address • City, state, and ZIP • Telephone number • Account balance • Date of last payment The structure should be used to store customer account records in a file. The program should have a menu that lets the user perform the following...
In C program Consider a file that contains employee records, called "empstat.txt." The data for each employee consist of the employee’s last name (up to 20 characters), employee id number (up to 11 characters), gross pay for the week (double), taxes deducted (double) for the week, and net pay (double) for the week. Create a struct to hold the employee information. Write a void function called writeEmpFile that prompts the user to enter last name, id number, gross pay and...
In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...
Lab Assignment – Database Implementation and Security In this lab you will create a Microsoft Access database of employee information and secure the table username and password security. Steps Enter data for five employee records. Each record should have fields: Employee ID (5 digits), First Name, Last Name, Home Address, Hire Date Create a query that displays Employee ID, First Name and Last Name. Create a form that requires entering username and password to access employee table. Error message should...
C++ : Please include complete source code in answer This program will have names and addresses saved in a linked list. In addition, a birthday and anniversary date will be saved with each record. When the program is run, it will search for a birthday or an anniversary using the current date to compare with the saved date. It will then generate the appropriate card message. Because this will be an interactive system, your program should begin by displaying a...
Write a program that uses a structure to store the following data about a customer account: Name Address City, state, and ZIP Telephone number Account Balance Date of last payment The program should use an vector of at least 20 structures. It should let the user enter data into the vector, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface. Input Validation: When the data for...