Question

Using struct.c, as a starting point, implement an application that creates a database of employee personal...

Using struct.c, as a starting point, implement an application that creates a database of employee personal records. Your implementation should follow these guidelines:

  • the definition of the structure PERSON should be provided in an h-file called person.h that you need to create in the src sub-directory,
    • for the content, refer to the lecture notes,
  • typdef should be used for referencing the PERSON structure,
  • an array employees[] should be declared in the main C file (that is struct.c),
  • a new C file person.c needs to be created; person.c should include implementations of the following functions:
    • addEmployee() to read the person data from the standard input and to add it to the array,
    • displayEmployee() to display the data for a single employee,
    • displayAllEmployees() to display data for all employees,
  • the main program should read in the data for a number of employees by first prompting the user for the number of employees, allocating sufficient space for the employees in the array, and then calling the addEmployee() function to populate the current element of the array.

Here are the signatures of the functions that must be declared in person.h and defined in person.c:

void addEmployee(PERSON *employee);
void displayAllEmployees(PERSON employees[], int numberOfEmployees);
void displayEmployee(PERSON *employee);

#include <stdio.h>

struct birthday {
    int month;
    int day;
    int year;
};

"struct.c"
int main(void) {
    struct birthday myBday;    // - no ‘new’ needed !
                               // then, use dot notation like in Java ! */
    scanf("%d/%d/%d", &myBday.month, &myBday.day, &myBday.year);
    printf("I was born on %d/%d/%d\n", myBday.month, myBday.day, myBday.year);

    return 0;
}

"person.c"

#include "person.h"

#define INPUT_BUFFER_SIZE;

void addEmployee(PERSON *employees){

    printf("");
    scanf("%d", &employees->age);
}
void displayAllEmployee(PERSON employees[], int numberOfEmployees){

}
void displayEmployees(PERSON *employees){

}

"person.h"

#ifndef C_TUT_PERSON_H
#define C_TUT_PERSON_H

#include <stdio.h>

typedef struct {
    int month;
    int day;
    int year;
} DATE;

typedef struct {
    char name[41];
    int age;
    float height;
    DATE bday;
} PERSON;

void addEmployee(PERSON *employee);
void displayAllEmployees(PERSON employees[], int numberOfEmployees);
void displayEmployees(PERSON *employees);
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Implemented and tested all three files. Output and comments added for better clarity.

----------------------------------------------------------person.h----------------------------------------------------------

#ifndef C_TUT_PERSON_H
#define C_TUT_PERSON_H

#include <stdio.h>

typedef struct {
int month;
int day;
int year;
} DATE;

typedef struct {
char name[41];
int age;
float height;
DATE bday;
} PERSON;

void addEmployee(PERSON *employee);
void displayAllEmployees(PERSON employees[], int numberOfEmployees);
void displayEmployees(PERSON *employees);

#endif

----------------------------------------------------------person.c----------------------------------------------------------

#include "person.h"
#include<stdio.h>
void addEmployee(PERSON *employee)
{
DATE mydate; //Date variable
printf("Enter Employee Name: "); //Accept Name
scanf("%s",employee->name);
printf("Enter Employee Age: "); //Accept Age
scanf("%d",&employee->age);
printf("Enter Date Of Birth: "); //Accept BDay
printf(" Enter Month: ");
scanf("%d",&mydate.month);
printf("Enter Day: ");
scanf("%d",&mydate.day);
printf("Enter Birthday Year: ");
scanf("%d",&mydate.year);

employee->bday = mydate;
}

void displayAllEmployees(PERSON employees[], int numberOfEmployees)
{
int i;
for(i=0;i<numberOfEmployees;i++) //Display all employees
{
printf(" Employee %d:",(i+1));
printf(" Name: %s",employees[i].name); //Name
printf(" Age: %d",employees[i].age); //Age
printf(" Birthday: %d-%d-%d",employees[i].bday.month,employees[i].bday.day,employees[i].bday.year); //B'Day
}
}

void displayEmployees(PERSON *employees) //Display single employee
{
printf(" Name: %s",employees->name);
printf(" Age: %d",employees->age);
printf(" Birthday: %d-%d-%d",employees->bday.month,employees->bday.day,employees->bday.year);
}

-----------------------------------------------------------struct.c-----------------------------------------------------------

#include "person.h"

int main(void)
{
int numberOfEmployees,i; //Initialize Variables
printf("Enter the number of Employees: "); //Accept no of employees
scanf("%d",&numberOfEmployees);

PERSON employees[numberOfEmployees];
for(i=0;i<numberOfEmployees;i++) //Accept all employees
{
printf(" Employee %d ",(i+1));
PERSON employee;
addEmployee(&employee); //Get employee details
employees[i] = employee; //Add employee to structure array
}

//Testing both the display functions
displayEmployees(&employees[0]); //Display the first employee
displayAllEmployees(employees,numberOfEmployees); //Display all employees
return 0;
}

Output:

Please comment if you have any queries or need clarification. Cheers!

Add a comment
Know the answer?
Add Answer to:
Using struct.c, as a starting point, implement an application that creates a database of employee personal...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Implement a program that: reads a number of personal records (for example, using PERSON struct from...

    Implement a program that: reads a number of personal records (for example, using PERSON struct from the earlier lab) from the standard input, creates a database of personal records, allows for adding new entries to the database, allows for deleting entries from the database, includes functions to acquire a record of personal data, and includes functions to display (print) a single selected record from the database, and also allows for printing all records in the database. NOTES: if name is...

  • #include<stdio.h> #include <stdlib.h> void read(struct Employee *e); struct Employee { int id; int age; }; int...

    #include<stdio.h> #include <stdlib.h> void read(struct Employee *e); struct Employee { int id; int age; }; int main(){ struct Employee e; read(&e); } void read(struct Employee *e){ int a,b; printf("Enter the id employee\n"); scanf("%d",&a); printf("Enter the age employee\n"); scanf("%d",&b); e->id=a; e->age=b; } Question: Declare a pointer variable of type Employee and place the address of the variable created in the above problem in that pointer variable.

  • Concurrent Key-Value Database Implement a non-persistent, concurrent key-value database using the Reader/Writers algorithm. - Use a...

    Concurrent Key-Value Database Implement a non-persistent, concurrent key-value database using the Reader/Writers algorithm. - Use a hashmap as the underlying data structure. Inspiration is ok, however the implementation must be yours. The hashmap must be able to grow to fit new elements, but it does not need to reduce its size. -- Linked lists? Positional arrays? All are fine. - Keys and values are strings (char *) - Operations are: get, put Provided files: - Implement the contract set in...

  • Hardware Inventory – Write a database to keep track of tools, their cost and number. Your...

    Hardware Inventory – Write a database to keep track of tools, their cost and number. Your program should initialize hardware.dat to 100 empty records, let the user input a record number, tool name, cost and number of that tool. Your program should let you delete and edit records in the database. The next run of the program must start with the data from the last session. This is my program so far, when I run the program I keep getting...

  • Using C, I need help debugging this program. I have a few error messages that I'm...

    Using C, I need help debugging this program. I have a few error messages that I'm not sure how to fix. Here is the code I have: /* * C Program to Print a Linked List in Reverse Order */ #include <stdio.h> #include <stdlib.h> struct node { int num; struct node *next; }; int main() { struct node *p = NULL; struct node_occur *head = NULL; int n; printf("Enter data into the list\n"); create(&p); printf("Displaying the nodes in the list:\n");...

  • Hello! I'm posting this program that is partially completed if someone can help me out, I...

    Hello! I'm posting this program that is partially completed if someone can help me out, I will give you a good rating! Thanks, // You are given a partially completed program that creates a list of employees, like employees' record. // Each record has this information: employee's name, supervisors's name, department of the employee, room number. // The struct 'employeeRecord' holds information of one employee. Department is enum type. // An array of structs called 'list' is made to hold...

  • Write a statement that calls a function named IncreaseItemQty, passing the variable addStock. Assign notebookInfo with...

    Write a statement that calls a function named IncreaseItemQty, passing the variable addStock. Assign notebookInfo with the value returned by IncreaseItemQty. #include <stdio.h> #include <string.h> typedef struct ProductInfo_struct {    char itemName[30];    int itemQty; } ProductInfo; ProductInfo IncreaseItemQty (ProductInfo productToStock, int increaseValue) {    productToStock.itemQty = productToStock.itemQty + increaseValue;    return productToStock; } int main(void) {    ProductInfo notebookInfo;    int addStock = 10;    scanf("%s", notebookInfo.itemName);    scanf("%d", &notebookInfo.itemQty);    /* Your solution goes here */    printf("Name:...

  • I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves...

    I JUST NEED HELP WITH DISPLAY PART! please help! thanks in advance // This function saves the array of structures to file. It is already implemented for you. // You should understand how this code works so that you know how to use it for future assignments. void save(char* fileName) { FILE* file; int i; file = fopen(fileName, "wb"); fwrite(&count, sizeof(count), 1, file); for (i = 0; i < count; i++) { fwrite(list[i].name, sizeof(list[i].name), 1, file); fwrite(list[i].class_standing, sizeof(list[i].class_standing), 1, file);...

  • I need help on this Systems review please! it's due by midnight monday. Question 1 Not...

    I need help on this Systems review please! it's due by midnight monday. Question 1 Not yet answered Points out of 1.00 Flag question Question text Using these declarations: int * numberPointers[3]; int * pointer; int number; Which of the following statements would generate a warning or error? Select one: a. number = pointer; b. *pointer = number; c. pointer = numberPointers; d. numberPointers[2] = &number; e. a., b., and d. f. a. and c. Question 2 Not yet answered...

  • Code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; ...

    code in C language ADT: typedef struct{ int ID; float salary; int age; }Employee; Specification: In this lab, five functions need to be implemented using the given ADT. 1. Employee* readRecord(FILE*) This function receives a FILE pointer created before. It reads a line from the provided csv file, and creates an Employee struct pointer with the information from that line then returns the pointer back to the calling function. Each line in the provided csv file contains the id, salary,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT