Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Read the images and generate the same output! DO NOT CHANGE THE CMSC 2 5 7 - P 2 . C file. This is the


Read the images and generate the same output! DO NOT CHANGE THE CMSC257-P2.C file. This is the p2-support.c file:#define _GNU_SOURCE //strcasestr is a nonstandard GNU extension,

//we need this line while serching for matching last name

#include

#include

#include

#include "p2-support.h"



void create_record ()// specify parameters. Clues are in the initalize function.

{

//define function. Clues are in the initalize function

//do not forget to increase total number of employees in the database

}

void print_title ()// you can keep this fuction or remove if needed

{

printf ("No. ID Name Email Salary Hire Date

");

printf ("--- ----- ------------- ------------ ---------- --/--/----

");

}

//fix save function. Save array into file: database_updated in the same format with the

//database file.

void save (dataBase_ptr db)// this function is for saving the database into a text file

{

FILE *dbfu;

dbfu = fopen ("database_updated", "w");//open an Std IO file to write into

if (dbfu == NULL)

{

 printf ("File cannot be created");

 return;

}

for (int i = 0; i  db->total; i++)

{

 fprintf (dbfu,//add format specifiers here, db->emp[i].ID,

 //add other members);

}

fclose (dbfu);//close file after writing

return;

}

void display_menu (struct DataBase *db)

{

int input = 0;

while (input != 8)

{

 puts

 ("

**************************************************************");

 printf

 (  "********** Employee Database - Total Employees: %03**********

",

 );//you need to fix this line so that total employees in the database is printed

 puts

 ("**************************************************************

");

 puts ("Choose one of the menu options below:");

 puts ("1. Sort by ID");

 puts ("2. Sort by Hire Date");

 puts ("3. Display all employees");

 puts ("4. Search employees by ID");

 puts ("5. Search employees by Last Name");

 puts ("6. Delete employee by ID");

 puts ("7. Save");

 puts ("8. Exit");

 scanf ("%d", &input);

 switch (input)

 {

 case 1:

 //call the function you defined for sorting by ID

 break;

 case 2:

 //call the function you defined for sorting by Hire Date

 break;

 case 3:

 //call the function you defined for displaying employees

 break;

 case 4:

 //call the function you defined for searching employees by ID

 break;

 case 5:

 //call the function you defined for searching employees by Last Name

 break;

 case 6:

 //call the function you defined for deleting employee by ID

 break;

 case 7:

 save (db);

 break;

 case 8:

 //free all allocated memory

 printf("Bye!

");

 break;

 }

}

}

This is the p2-support.h file: ////////////////////////////////////////////////////////////////////////

//

// File : p2-support.h

// Description : Header file for project2

#ifndef P2Header //To prevent double inclusion of header

#define P2Header //To prevent double inclusion of header

#include

#define byID 1

#define byNAME 2

#define dbSIZE 100

#define idSIZE 6

#define nameSIZE 10

#define emailSIZE 20

typedef struct date// do not modify

{

int day;

int month;

int year;

}date;

typedef struct Employee

{

char ID[idSIZE];

//declare other members

}employee, *employee_ptr;

typedef struct DataBase

{

//a pointer to first element of empoloyee array

//number of employees in database

}*dataBase_ptr;

// Functional Prototypes

// Function : initialize

// Description : This function creates an array in the database

//  then initalializes each array elemet with the data

//  in the given file

// Inputs : a pointer to DataBase struct

// Output : none

void initialize (dataBase_ptr);

//Write formal comments for each function header.

//In the same format with the initialize function

void create_record ();//specify parameters types. Clues are in the initalize function.

void print_title ();

void display_menu (dataBase_ptr);

//other function headers here

void save(dataBase_ptr);

#endif //To prevent double inclusion of header This is the CMSC257-p2.c file(DO NOT CHANGE): #include

#include

#include

#include "p2-support.h"

FILE* dbf;//File structure for Standard I/O

int main (int argc, char* argv[]){

dbf = NULL;

//Read file if a file name is entered

if(argc == 2)

 dbf = fopen ("argv[1]", "r");

//Read database file if no file name is entered

else if (argc ==1)

 dbf = fopen ("database", "r");

else

 printf("Program can read one file only at a time");

if (dbf ==NULL)

{

 printf("File does not exist.

Enter a valid file name when running the program. Such as: ./p2 database");

 return 0;

}

struct DataBase* db;

db = malloc(sizeof(struct DataBase));

initialize (db);

display_menu(db);

Metafclose (dbf);//close file

return 0;

}

void initialize (struct DataBase *db) {

db->emp =malloc (sizeof (struct Employee) * 100);

db->total = 0;

char ID[idSIZE];

char first_name[nameSIZE];

char last_name[nameSIZE];

char email[emailSIZE];

double salary;

char line[100];

date hire_date;

for (;;)

{

fgets (line, 100, dbf);//get a line from the file

sscanf (line, "%%%%%lf %d/%d/%d

", ID, first_name, last_name, email, &salary, &hiredate.month, &hire_date.day, &hire_date.year);

create_record(ID, first_name, last_name, email, salary, hire_date, db);

if (feof (dbf))

break;

}

}

{image text in transcribed 

a !!! !!! docs.google.com VEIKOUS 10-f...t Lowes.com Bing Outsunny Vin...t Lowes.com Copy of project2 .DOCX File Edit View Insert Format Tools Help A100% Normal... . 5 VCU 5 2 fotobudo betod dedecke besedestakaaban 0 0 0 Time... Create a Makefile to build your program. 0 Copy of project2 .DOCX File Edit View Insert Format Tools Help A100% Headin... Step 2: Define a structure with the tag name Employee (within p2-support.h), with the following members: ID (ID): a character string with a size of 6 First Name (first_name): a character string with a size of 10 Last Name (last_name): a character string with a size of 10 Email address (email): a character string with a size of 20 Employee Salary (salary): a double type. Hire Date (hire_date): a date type. (use the date type given in the header file.) Then your "DataBase" struct should be defined (within p2-support.h) as: A dynamic array of employees. (Note that you cannot declare a dynamic array within the struct definition. You only need to create a pointer to point to the dynamic array within the definition. The array is already allocated within the initialize function) A variable to hold the number of current employees in the database (type of int). Read all comments in the file carefully. There are hints and instructions. 12 + B VEIKOUS 10-f...t Lowes.com Bing Outsunny Vin...t Lowes.com Copy of... Print Formatting Displaying Menu: Time... Step 3: Implement functions for displaying the main display_menu the menu in the p2-support.c file, add headers for functions into the p2-support.h file. I 3 14 + Displaying employees (Menu item 3): No: 3 characters left aligned UA B I U docs.google.com Menu title: 62 charters long Total employees should always be printed as right aligned and 3 characters. 0 A C 0 4 de you are intsheu'check the lo camint section to prepart and the thes to desdotmined. **** Employee Database - Total Employees: 010 ********** C Outsunny 9.7...at Lowes.com 2 M ID: 5 characters, right aligned and zero filled. Name: Limited to 13 characters, first name, and last name is combined when printing. Truncate to 13 characters if needed. But, do not change the original database. Salary: 10 characters. The first character is always a $ sign. The salary amount is right aligned with two digits after the decimal point. I + IMDb Share Share A A !!! VEIKOUS 10-f...t Lowes.com Bing Outsunny Vin...t Lowes.com Copy of project2 .DOCX File Edit View A ........ e V Insert Format Tools Help 100% - Headin... - Anmmmm 7. Save 8. Exit 1 >> EIKOUS 10-f...t Lowes.com MM of project2 .DOCX Edit View A 100% - Choose one of the menu options below: 1. Sort by ID 2. Sort by Hire Date 3. Display all employees 4. Search employees by ID 5. Search employees by Last Name 6. Delete employee by ID 7. Save 8. Exit Step 3: Implement functions for displaying the main display_menu the menu in the p2-support.c file, add headers for functions into the p2-support.h file. Read all comments in the file carefully. There are hints and instructions. The main menu of your program should print as follows: *** Employee Database Total Employees: 0101 Insert Format Tools Help Headin... Note that there is an integer indicating the number of employees in the title. Following is the description of each menu option: Bing Time... - 1. Sort records with ID numbers from lowest to highest. 2. Sort records with hire date from earliest to most recent. 3. Display all records as ordered in the database. 4. Display the employee with the given ID. Will print a message if an employee with a given ID does not exist. 5. Search the database by last name and display employee(s) partially or completely matching with the given string. This option may result in multiple hits; for example, there might be more than one entry with the same last name but a different first name. 6. Delete one record with the matching ID from the list. Print a message if no match. 7. Save the database to another file named as database_updated. 8. Exit the program. It should also deallocate all dynamically allocated memory. Part of the program is given to simplify your job: Employee Database Name Choose one of the menu options below: 1. Sort by ID 2. Sort by Hire Date 3. Display all employees Time... ......... 4. Search employees by ID 5. Search employees by Last Name 6. Delete employee by ID 7. Save 8. Exit. 3 No. ID 00001 Chris Boyle 00002 Paul Green. 00003 Wei Martin 00006 Chris Reddy. Email Outsunny Vin...t Lowes.com 2 Total Employees: 010 6 14 + docs.google.com 14 + B I UA Salary docs.google.com Hire Date --/--/---- cb@vcu.edu $200000.01 01/08/2023 pg@vcu.edu $ 2700.45 08/05/2022 wm@vcu.edu $ 98999.99 01/10/2023 cr@vcu.edu. $ 23040.67 07/08/2022 00007 Mitch Martine mitch@vcu.ed $ 78999.88 12/15/2022 00000 Duid Deu $100000 01 1110 (2000 B I U I A 6 20 + Share + Shar A a = ||| Q !!! VEIKOUS 10-f...t Lowes.com Copy of project2.docx... Copy of project2.DOCX File Edit View Insert Format Tools Help. 5 d A 0 I A 100% - Headin... 14 + B I fututzw. A...... 7. Save 8. Exit 3 No. ID 7 --/--/---- 6 00014 Christine Blu cb@vcu.edu $40009.99 12/20/2022 8 Choose one of the menu options below: 1. Sort by ID 2. Sort by Hire Date. 3. Display all employees 4. Search employees by ID 5. Search employees by Last Name. 6. Delete employee by ID Bing 8. Exit 16 Name Employee Database - Total Employees: 009 ID Hire Date --/--/---- 00001 Chris Boyle cb@vcu.edu $200000.01 01/08/2023 00002 Paul Green pg@vcu.edu $ 2700.45 08/05/2022 00003 Wei Martin. wm@vcu.edu $ 98999.99 01/10/2023 10000 DETEUTEGES 00007 Mitch Martine mitch@vcu.ed $ 78999.88 12/15/2022 $100000.01 11/10/2022 $ 23040.67 01/01/2020 $40009.99 12/20/2022 $ 1000.37 10/25/2022 8500.01 01/09/2023 00008 David Boyle db@vcu.edu. 00009 Chris Magenta cj@vcu.edu 00014 Christine Blu cb@vcu.edu 00015 Paula Brown. pb@vcu.edu. 00105 Stephen Black sb@vcu.edu $ 6 Time... Choose one of the menu options below: 1. Sort by ID 2. Sort by Hire Date 3. Display all employees 4. Search employees by ID Outsunny Vin...t Lowes.com 5. Search employees by Last Name 6. Delete employee by ID 7. Save chegg can't post more... Name VEIKOUS 10-f...t Lowes.com Email Employee Database Total Employees: 009 Enter the Last Name you are searching for ma Salary Hire Date --/--/---- 00003 Wei Martin. wm@vcu.edu. $ 98999.99 01/10/2023 00007 Mitch Martine mitch@vcu.ed $ 78999.88 12/15/2022 00009 Chris Magenta cj@vcu.edu $ 23040.67 01/01/2020 Name Bing Y Email Copy of project2.DOCX File Edit View Insert Format Tools Help. Headin... A 100% - t...... bost by t 2. Sort by Hire Date 3. Display all employees 4. Search employees by ID 5. Search employees by Last Name: 6. Delete employee by ID. 7. Save 8. Exit docs.google.com Salary Time.... Enter the ID you are searching for 14 No. ID Email Outsunny Vin...t Lowes.com 7 docs.google.com Choose one of the menu options below: 1. Sort by ID 2. Sort by Hire Date. 3. Display all employees 4. Search employees by ID 5. Search employees by Last Name 6. Delete employee by ID 14 + Salary --/--/---- 00014 Christine Blu cb@vcu.edu $40009.99 12/20/2022 B I 4 fuurl. Employee Database - Total Employees: 009 Hire Date U A 5mm 0 6 + Copy of project2.docx... D + Share Share 0 B G A A A

Step by Step Solution

There are 3 Steps involved in it

Step: 1

It seems like you have provided the code for the files p2supportc and p2supporth but there are some ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Operating System questions

Question

What are null values, and why are they a problem?

Answered: 1 week ago

Question

show an emotion when they really dont feel it (simulation).

Answered: 1 week ago