SUBJECT: FUNDAMENTALS OF C PROGRAMMING (C 90) NEED THIS CORRECTED WITHIN 2 HOURS !! Here I my code I wrote in C but howe
Posted: Mon May 02, 2022 12:25 pm
SUBJECT: FUNDAMENTALS OF C PROGRAMMING (C 90) NEED THIS
CORRECTED WITHIN 2 HOURS !!
Here I my code I wrote in C but however when I compile it on Ed,
there is some difference between my output and the
expected output. Looking at the expected
output, please modify my current code so that the output
is exactly the same as the expected output. Will give an
upvote if my output and the expected output are the same. Send the
modified code in which the output matches exactly the expected
output. Do not use C 99 or C 11 for the code only C
90.
MY CODE:
#include
#include
#include
/*********************************************************
List preprocessing directives - you may define your own.
*********************************************************/
#define MAX_COMPANY_SIZE 5
#define MAX_NAME_SIZE 11
/**********************************************************
* List structs - you may define struct date and struct employee
only. Each
* struct definition should have only the fields mentioned in the
assignment
* description.
*******************************************************************************/
typedef struct {
unsigned int day;
unsigned int month;
unsigned int year;
}
date_t;
typedef struct {
char name[MAX_NAME_SIZE];
float fte;
unsigned int level;
date_t birthday;
}
employee_t;
void printMenu(void);
void addEmployee(employee_t employeeList[], int * size);
void deletelastEmployee(int * size);
void displayemployeeList(employee_t employeeList[], int
size);
void saveList(employee_t employeeList[], int size, char
dbFileName[]);
int readList(employee_t employeeList[], char dbFileName[]);
int main(void)
{
employee_t employeeList[MAX_COMPANY_SIZE];
char dbFileName[] = "database.txt";
int current_size = 0, option;
do {
printMenu();
printf("Enter your choice>\n");
scanf("%d", & option);
getchar();
if (option < 1 || option > 6)
{
printf("Invalid choice.");
}
else {
switch (option)
{
case 1:
addEmployee(employeeList, & current_size);
break;
case 2:
if (current_size == 0)
printf("List is empty");
else
{
deletelastEmployee( & current_size);
}
break;
case 3:
if (current_size == 0)
printf("List is empty");
else
{
displayemployeeList(employeeList, current_size);
}
break;
case 4:
saveList(employeeList, current_size, dbFileName);
break;
case 5:
{
FILE * fptr = fopen(dbFileName, "r");
if (fptr == NULL)
printf("Read error");
else
{
current_size = readList(employeeList, dbFileName);
}
break;
}
}
}
}
while (option != 6);
return 0;
}
void printMenu(void)
{
printf("\n\n"
"1. add employee\n"
"2. delete last employee\n"
"3. display employee list\n"
"4. save the employee list to the database\n"
"5. read the employee list from the database\n"
"6. exit the program\n");
}
void addEmployee(employee_t employeeList[], int *
current_size)
{
if (( * current_size) < MAX_COMPANY_SIZE)
{
employee_t temp;
printf("Enter name>");
scanf("%10s", * & temp.name);
while ((getchar()) != '\n');
/*produce and validate the read input by user*/
while (1)
{
printf("Enter birthday: day>");
scanf("%u", & temp.birthday.day);
scanf("%l[^\n]", & temp.birthday.day);
if (temp.birthday.day < 1 || temp.birthday.day > 31)
printf("Invalid day. ");
else
break;
}
/* User input should be produced and validated. */
while (1)
{
printf("Enter birthday: month>");
scanf("%u", & temp.birthday.month);
scanf("%l[^\n]", & temp.birthday.month);
if (temp.birthday.month < 1 || temp.birthday.month >
12)
printf("Invalid month. ");
else
break;
}
/* User input should be produced and validated. */
while (1)
{
printf("Enter birthday: year>");
scanf("%u", & temp.birthday.year);
scanf("%l[^\n]", & temp.birthday.year);
if (temp.birthday.year < 1800 || temp.birthday.year >
2017)
printf("Invalid year. ");
else
break;
}
while (1)
{
/* User input should be produced and validated. */
printf("Enter FTE>");
scanf("%f", & temp.fte);
if (temp.fte < 0.0 || temp.fte > 1.0)
printf("Invalid FTE. ");
else
break;
}
while (1)
{
/* User input should be produced and validated. */
printf("Enter level>");
scanf("%u", & temp.level);
scanf("%l[^\n]", & temp.level);
if (temp.level < 7 || temp.level > 18)
printf("Invalid level. ");
else
break;
}
employeeList[( * current_size)] = temp;
( * current_size) ++;
} else
printf("Maximum number of employees reached.\n");
}
void deletelastEmployee(int * current_size)
/* Remove the final employee from the employee list.. */
{
* current_size -= 1;
}
void displayemployeeList(employee_t employeeList[], int
current_size)
/* Request that the employee list be displayed. */
{
printf("%-10s %-10s %-5s %s\n", "Name", "Birthday", "FTE",
"Level");
printf("%-10s %-10s %-5s %s\n", "----------", "----------",
"-----", "-----");
int i;
for (i = 0; i < current_size; i++) {
printf("%-10s %.2u-%.2u-%.4u %5.3f %-u\n", employeeList.name,
employeeList.birthday.day,
employeeList.birthday.month, employeeList.birthday.year,
employeeList.fte, employeeList.level);
}
}
void saveList(employee_t employeeList[], int current_size, char
dbFileName[])
{
FILE * fptr = fopen(dbFileName, "w");
int i;
/* Verifying the databse.txt file's existence */
if (fptr == NULL)
{
printf("File not Found\n");
exit(1);
}
/* The employee list is printed and saved to the database.txt file.
*/
for (i = 0; i < current_size; i++)
{
fprintf(fptr, "%s %u %u %u %f %u\n", employeeList.name,
employeeList.birthday.day,
employeeList.birthday.month, employeeList.birthday.year,
employeeList[i].fte, employeeList[i].level);
}
fclose(fptr);
}
int readList(employee_t employeeList[], char dbFileName[])
{
FILE * fptr = fopen(dbFileName, "r");
int i = 0;
while (fscanf(fptr, "%s %u %u %u %f %u", employeeList[i].name,
& employeeList[i].birthday.day, &
employeeList[i].birthday.month, &
employeeList[i].birthday.year, & employeeList[i].fte, &
employeeList[i].level) != EOF)
{
i++;
}
fclose(fptr);
return i;
}
My Outputs:
EXPECTED OUTPUTS:
Feedback 6. exit the program Enter your choice> 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> Name Birthday FTE Level --- ---- Bob 01-07-1948 1.000 18 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database L
X Test 11 1 paint Your program exited with signal 6 (SIGABRT - Aborted) DIFF SPLIT DIFF YOUR OUTPUT EXPECTED *** stack smashing detected ***: terminated
6. exit the program Enter your choice> 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> . Name Birthday FTE Level ---- ---- Bob + Noman + Sue + Good_emp + Cate_em 01-07-1948 1.000 18 25-11-1975 0.800 11 21-05-1963 1.000 16 11-01-1985 1.000 09 31-08-1995 0.500 07 1. add employee 2. delete last employee 3. display employee List 4. save the employee list to the database 5. read the employee list from the database ad the ENG 9: 27/04
Feedback Your program exited with signal 6 (SIGABRT - Aborted) DIFF SPLIT DIFF YOUR OUTPUT EXPECTED 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice Enter name>Enter birthday: day>Enter birthday: nonth>Enter birthday: year Enter FTE>Enter levels 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice Enter name>Enter birthday: day>Enter birthday: month>Enter birthday: year>Enter FTE>Enter levels 1. add employee 2. delete last emplover 2 Mn o
Feedback 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database S. read the employee list from the database 6. exit the program Enter your choices Enter name>Enter birthday: day>Enter birthday: month>Enter birthday: year>Enter FTE>Enter levels 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> Enter name> Enter birthday: day>Enter birthday: nonth>Enter birthday: year>Enter FTE>Enter level 1. add employee 2. delete last employee 3. display employee List 4. Save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choices Enter name>Enter birthday: day> Enter birthday: month>Enter birthday: year>Enter FTE>Enter levels a
Feedback 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> Name Birthday FTE Level Bob Noman Sue Good_emp Cate_em 01-07-1948 1.000 18 25-11-1975 0.800 11 21-05-1963 1.000 16 11-01-1985 1.000 09 31-08-1995 0.500 07 1. add employee C
1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> List is full 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database s. read the employee list from the database 6. exit the program Enter your choice>
CORRECTED WITHIN 2 HOURS !!
Here I my code I wrote in C but however when I compile it on Ed,
there is some difference between my output and the
expected output. Looking at the expected
output, please modify my current code so that the output
is exactly the same as the expected output. Will give an
upvote if my output and the expected output are the same. Send the
modified code in which the output matches exactly the expected
output. Do not use C 99 or C 11 for the code only C
90.
MY CODE:
#include
#include
#include
/*********************************************************
List preprocessing directives - you may define your own.
*********************************************************/
#define MAX_COMPANY_SIZE 5
#define MAX_NAME_SIZE 11
/**********************************************************
* List structs - you may define struct date and struct employee
only. Each
* struct definition should have only the fields mentioned in the
assignment
* description.
*******************************************************************************/
typedef struct {
unsigned int day;
unsigned int month;
unsigned int year;
}
date_t;
typedef struct {
char name[MAX_NAME_SIZE];
float fte;
unsigned int level;
date_t birthday;
}
employee_t;
void printMenu(void);
void addEmployee(employee_t employeeList[], int * size);
void deletelastEmployee(int * size);
void displayemployeeList(employee_t employeeList[], int
size);
void saveList(employee_t employeeList[], int size, char
dbFileName[]);
int readList(employee_t employeeList[], char dbFileName[]);
int main(void)
{
employee_t employeeList[MAX_COMPANY_SIZE];
char dbFileName[] = "database.txt";
int current_size = 0, option;
do {
printMenu();
printf("Enter your choice>\n");
scanf("%d", & option);
getchar();
if (option < 1 || option > 6)
{
printf("Invalid choice.");
}
else {
switch (option)
{
case 1:
addEmployee(employeeList, & current_size);
break;
case 2:
if (current_size == 0)
printf("List is empty");
else
{
deletelastEmployee( & current_size);
}
break;
case 3:
if (current_size == 0)
printf("List is empty");
else
{
displayemployeeList(employeeList, current_size);
}
break;
case 4:
saveList(employeeList, current_size, dbFileName);
break;
case 5:
{
FILE * fptr = fopen(dbFileName, "r");
if (fptr == NULL)
printf("Read error");
else
{
current_size = readList(employeeList, dbFileName);
}
break;
}
}
}
}
while (option != 6);
return 0;
}
void printMenu(void)
{
printf("\n\n"
"1. add employee\n"
"2. delete last employee\n"
"3. display employee list\n"
"4. save the employee list to the database\n"
"5. read the employee list from the database\n"
"6. exit the program\n");
}
void addEmployee(employee_t employeeList[], int *
current_size)
{
if (( * current_size) < MAX_COMPANY_SIZE)
{
employee_t temp;
printf("Enter name>");
scanf("%10s", * & temp.name);
while ((getchar()) != '\n');
/*produce and validate the read input by user*/
while (1)
{
printf("Enter birthday: day>");
scanf("%u", & temp.birthday.day);
scanf("%l[^\n]", & temp.birthday.day);
if (temp.birthday.day < 1 || temp.birthday.day > 31)
printf("Invalid day. ");
else
break;
}
/* User input should be produced and validated. */
while (1)
{
printf("Enter birthday: month>");
scanf("%u", & temp.birthday.month);
scanf("%l[^\n]", & temp.birthday.month);
if (temp.birthday.month < 1 || temp.birthday.month >
12)
printf("Invalid month. ");
else
break;
}
/* User input should be produced and validated. */
while (1)
{
printf("Enter birthday: year>");
scanf("%u", & temp.birthday.year);
scanf("%l[^\n]", & temp.birthday.year);
if (temp.birthday.year < 1800 || temp.birthday.year >
2017)
printf("Invalid year. ");
else
break;
}
while (1)
{
/* User input should be produced and validated. */
printf("Enter FTE>");
scanf("%f", & temp.fte);
if (temp.fte < 0.0 || temp.fte > 1.0)
printf("Invalid FTE. ");
else
break;
}
while (1)
{
/* User input should be produced and validated. */
printf("Enter level>");
scanf("%u", & temp.level);
scanf("%l[^\n]", & temp.level);
if (temp.level < 7 || temp.level > 18)
printf("Invalid level. ");
else
break;
}
employeeList[( * current_size)] = temp;
( * current_size) ++;
} else
printf("Maximum number of employees reached.\n");
}
void deletelastEmployee(int * current_size)
/* Remove the final employee from the employee list.. */
{
* current_size -= 1;
}
void displayemployeeList(employee_t employeeList[], int
current_size)
/* Request that the employee list be displayed. */
{
printf("%-10s %-10s %-5s %s\n", "Name", "Birthday", "FTE",
"Level");
printf("%-10s %-10s %-5s %s\n", "----------", "----------",
"-----", "-----");
int i;
for (i = 0; i < current_size; i++) {
printf("%-10s %.2u-%.2u-%.4u %5.3f %-u\n", employeeList.name,
employeeList.birthday.day,
employeeList.birthday.month, employeeList.birthday.year,
employeeList.fte, employeeList.level);
}
}
void saveList(employee_t employeeList[], int current_size, char
dbFileName[])
{
FILE * fptr = fopen(dbFileName, "w");
int i;
/* Verifying the databse.txt file's existence */
if (fptr == NULL)
{
printf("File not Found\n");
exit(1);
}
/* The employee list is printed and saved to the database.txt file.
*/
for (i = 0; i < current_size; i++)
{
fprintf(fptr, "%s %u %u %u %f %u\n", employeeList.name,
employeeList.birthday.day,
employeeList.birthday.month, employeeList.birthday.year,
employeeList[i].fte, employeeList[i].level);
}
fclose(fptr);
}
int readList(employee_t employeeList[], char dbFileName[])
{
FILE * fptr = fopen(dbFileName, "r");
int i = 0;
while (fscanf(fptr, "%s %u %u %u %f %u", employeeList[i].name,
& employeeList[i].birthday.day, &
employeeList[i].birthday.month, &
employeeList[i].birthday.year, & employeeList[i].fte, &
employeeList[i].level) != EOF)
{
i++;
}
fclose(fptr);
return i;
}
My Outputs:
EXPECTED OUTPUTS:
Feedback 6. exit the program Enter your choice> 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> Name Birthday FTE Level --- ---- Bob 01-07-1948 1.000 18 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database L
X Test 11 1 paint Your program exited with signal 6 (SIGABRT - Aborted) DIFF SPLIT DIFF YOUR OUTPUT EXPECTED *** stack smashing detected ***: terminated
6. exit the program Enter your choice> 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> . Name Birthday FTE Level ---- ---- Bob + Noman + Sue + Good_emp + Cate_em 01-07-1948 1.000 18 25-11-1975 0.800 11 21-05-1963 1.000 16 11-01-1985 1.000 09 31-08-1995 0.500 07 1. add employee 2. delete last employee 3. display employee List 4. save the employee list to the database 5. read the employee list from the database ad the ENG 9: 27/04
Feedback Your program exited with signal 6 (SIGABRT - Aborted) DIFF SPLIT DIFF YOUR OUTPUT EXPECTED 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice Enter name>Enter birthday: day>Enter birthday: nonth>Enter birthday: year Enter FTE>Enter levels 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice Enter name>Enter birthday: day>Enter birthday: month>Enter birthday: year>Enter FTE>Enter levels 1. add employee 2. delete last emplover 2 Mn o
Feedback 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database S. read the employee list from the database 6. exit the program Enter your choices Enter name>Enter birthday: day>Enter birthday: month>Enter birthday: year>Enter FTE>Enter levels 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> Enter name> Enter birthday: day>Enter birthday: nonth>Enter birthday: year>Enter FTE>Enter level 1. add employee 2. delete last employee 3. display employee List 4. Save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choices Enter name>Enter birthday: day> Enter birthday: month>Enter birthday: year>Enter FTE>Enter levels a
Feedback 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> Name Birthday FTE Level Bob Noman Sue Good_emp Cate_em 01-07-1948 1.000 18 25-11-1975 0.800 11 21-05-1963 1.000 16 11-01-1985 1.000 09 31-08-1995 0.500 07 1. add employee C
1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database 5. read the employee list from the database 6. exit the program Enter your choice> List is full 1. add employee 2. delete last employee 3. display employee list 4. save the employee list to the database s. read the employee list from the database 6. exit the program Enter your choice>