Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I already made big part of the code, so what I need from you is to modify it to

ID: 3592946 • Letter: I

Question

I already made big part of the code, so what I need from you is to modify it to make it exactly as what the assignment instructs, including making the menu.

Here is my code:

#include <stdio.h> #include <stdlib.h> void output(struct Person *p1, struct Person *p2, struct Person *p3); void setPerson(struct Person *p1, struct Person *p2, struct Person *p3); typedef struct DATE { int month; int day; int year; } DATE; struct Person { char name[32]; DATE birthdate; char gender[5]; float salary; } person1, person2, person3; int main() { setPerson(&person1, &person2, &person3); output(&person1, &person2, &person3); system("PAUSE"); return 0; } void setPerson(struct Person *p1, struct Person *p2, struct Person *p3) { strcpy(person1.name, "Woody Parker"); person1.birthdate.month = 12; person1.birthdate.day = 18; person1.birthdate.year = 1995; strcpy(person1.gender, "Male"); person1.salary = 40000.00; strcpy(person2.name, "Mary Jane"); person2.birthdate.month = 4; person2.birthdate.day = 13; person2.birthdate.year = 1992; strcpy(person2.gender, "Female"); person2.salary = 60000.00; strcpy(person3.name, "Steve James"); person3.birthdate.month = 8; person3.birthdate.day = 10; person3.birthdate.year = 1997; strcpy(person3.gender, "Male"); person3.salary = 100000.00; } void output(struct Person *p1, struct Person *p2, struct Person *p3) { printf( "Name: %s " "Birthday: %i/%i/%i " "Gender: %s " "Salary: %.2f ", p1->name, p1->birthdate.month, p1->birthdate.day, p1->birthdate.year, p1->gender, p1->salary ); printf( "Name: %s " "Birthday: %i/%i/%i " "Gender: %s " "Salary: %.2f ", p2->name, p2->birthdate.month, p2->birthdate.day, p2->birthdate.year, p2->gender, p2->salary ); printf( "Name: %s " "Birthday: %i/%i/%i " "Gender: %s " "Salary: %.2f ", p3->name, p3->birthdate.month, p3->birthdate.day, p3->birthdate.year, p3->gender, p3->salary ); } You are to create a C program with the following menu: [A]dd a new client Dlisplay all clients acome Average for all clients Qluit A client has the following information A. Name (First, Middle Initial, Last Name) a. First name and Last Name first letter Caps and others lowercase b. Middle Initial is Uppercase B. Date of Birth a. All Rules with Dates C. Annual Income D. Gender The program will store between 0 and 1000 clients. You are to create at least 3 structs. You are to create functions for handling names, and dates. Your functions should be used to set a value for these data types and to retrieve values from these data types. Your code should be well documented. All your work will be done in functions outside of main.

Explanation / Answer

Given below is the code with output. Please don't forget to rate the answer if it helped. thank you.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


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

typedef struct{
char fname[20];
char middleInitial;
char lname[20];
}Name;

typedef struct
{
Name name;
Date birthdate;
char gender;
float salary;
}Person;


void convertNameCase(char* str);
int isLeap(int year);
int isValid(Date* d);
void inputName(Name* n);
void inputDate(Date* d);
void inputPersonDetails(Person *p);
void displayName(Name* n);
void displayDate(Date* d);
void displayPerson(Person *p);
void displayAll(Person people[], int count);
float average(Person people[], int count);

int main() {
  
Person people[1000]; // max of 1000 Person structs
int count = 0;
int choice = 0;
float avg;
  
while(choice != 4)
{
printf(" 1. Add person details ");
printf("2. Display all ");
printf("3. Average income ");
printf("4. Quit ");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1:
inputPersonDetails(&people[count]); //pass the address of the person whose details need to be input
count++;
break;
case 2:
displayAll(people, count);
break;
case 3:
avg = average(people, count);
printf("The average income is %.2f ", avg);
break;
case 4:
break;
default:
printf("Invalid menu choice! ");
}
}
return 0;
}


//converts the given name to name case i.e 1st capital and rest lower
void convertNameCase(char* str)
{
int i;
str[0] = toupper(str[0]);
for(i = 1; str[i] != ''; i++)
str[i] = tolower(str[i]);
}

int isLeap(int year)
{
if(year % 400 == 0) //divisible by 400 is leap
return 1;
else if(year % 4 == 0 && year % 100 != 0) //divisible by 4 and not divisible by 100
return 1;
else
return 0;
}


int isValid(Date* d)
{
int valid = 0; //assume its invalid
int month = d->month ,day = d->day, year = d->year;
if(d->month >= 1 && d->month <= 12 && year >= 1900)
{
if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
{
if(day >= 1 && day <= 31)
valid = 1;
}
else if(month == 4 || month == 6 || month == 9 || month == 11)
{
if(day >= 1 && day <= 30)
valid = 1;
}
else if(month == 2)
{
if(isLeap(year))
{
if(day >= 1 && day <= 29)
valid = 1;
}
else
{
if(day >= 1 && day <= 28)
valid = 1;
}
}
}
return valid;
}
void inputName(Name* n)
{
printf("Enter first name: ");
scanf("%s", n->fname);
convertNameCase(n->fname);
getchar();//get rid of new line before reading middle initial
printf("Enter middle initial: ");
scanf("%c", &n->middleInitial);
n->middleInitial = toupper(n->middleInitial);
printf("Enter last name: ");
scanf("%s", n->lname);
convertNameCase(n->lname);
}

void inputDate(Date* d)
{
while(1)
{
printf("Enter date of birth(MM DD YYYY): ");
scanf("%d %d %d", &d->month, &d->day, &d->year);
if(isValid(d))
break;
else
printf("Invalid date! ");
}

}

void inputPersonDetails(Person *p)
{
inputName(&p->name);
getchar();//getrid of newline
printf("Enter gender (M/F): ");
scanf("%c", &p->gender);
p->gender = toupper(p->gender);
inputDate(&p->birthdate);
printf("Enter salary: ");
scanf("%f", &p->salary);
}

void displayName(Name* n)
{
printf("Name: %s %c %s ", n->fname, n->middleInitial, n->lname);
}
void displayDate(Date* d)
{
printf("Date of Birth: %02d/%02d/%d ", d->month, d->day, d->year);
}
void displayPerson(Person *p)
{
displayName(&p->name);
printf("Gender: %c ", p->gender);
displayDate(&p->birthdate);
printf("Salary: %.2f ", p->salary);
printf(" ");
}

void displayAll(Person people[], int count)
{
int i;
for(i = 0; i < count; i++)
{
displayPerson(&people[i]);
}
}
float average(Person people[], int count)
{
int i;
float avg = 0;
for(i = 0; i < count; i++)
{
avg += people[i].salary;
}
if(count != 0)
avg /= count;
  
return avg;
  
}

output

1. Add person details
2. Display all
3. Average income
4. Quit
Enter your choice: 1
Enter first name: john
Enter middle initial: a
Enter last name: smith
Enter gender (M/F): m
Enter date of birth(MM DD YYYY): 02 30 1990
Invalid date!
Enter date of birth(MM DD YYYY): 02 28 1990
Enter salary: 1000
1. Add person details
2. Display all
3. Average income
4. Quit
Enter your choice: 2
Name: John A Smith
Gender: M
Date of Birth: 02/28/1990
Salary: 1000.00

1. Add person details
2. Display all
3. Average income
4. Quit
Enter your choice: 1
Enter first name: robert
Enter middle initial: t
Enter last name: williams
Enter gender (M/F): m
Enter date of birth(MM DD YYYY): 12 35 2000
Invalid date!
Enter date of birth(MM DD YYYY): 12 31 2000
Enter salary: 2000
1. Add person details
2. Display all
3. Average income
4. Quit
Enter your choice: 2
Name: John A Smith
Gender: M
Date of Birth: 02/28/1990
Salary: 1000.00

Name: Robert T Williams
Gender: M
Date of Birth: 12/31/2000
Salary: 2000.00

1. Add person details
2. Display all
3. Average income
4. Quit
Enter your choice: 3
The average income is 1500.00
1. Add person details
2. Display all
3. Average income
4. Quit
Enter your choice: 4