C Program You are to create a C program with the following menu: [A]dd a new cli
ID: 3591730 • Letter: C
Question
C Program
You are to create a C program with the following menu:
[A]dd a new client
[D]isplay all clients
[I]ncome Average for all clients
[Q]uit
A client has the following information:
Name (First, Middle Initial, Last Name)
First name and Last Name first letter Caps and others lowercase
Middle Initial is Uppercase
Date of Birth
All Rules with Dates
Annual Income
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. Your code will be well documented.
Explanation / Answer
include <stdio.h>
struct client
{
char fname[80];
char mname[80];
char lname[80];
int d;
int m;
int y; char Gender[10];
int income;
};
//function declarations of necessary functions
void accept(struct client[], int);
void display(struct client[], int);
void incomeavg(struct client[], int);
int main()
{
struct client data[999];
int n, choice, account_no, amount, index;
printf("Client Data ");
printf("Number of client records you want to enter? : ");
scanf("%d", &n);
accept(data, n);
do
{
printf(" Client Data Menu : ");
printf("Press 1 to enter a new record. ");
printf("Press 2 to display all records ");
printf("Press 3 to display income average for all clients ");
printf("Press 0 to exit ");
printf(" Enter choice(0-3) : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
accept(data, n);
break;
case 2:
display(data, n);
break;
case 3:
incomeavg(data, n);
break;
}
while (choice != 0);
return 0;
}
void accept(struct client list[999], int s)
{
int i;
for (i = 0; i < s; i++)
{
printf(" Enter data for Record #%d", i + 1);
printf(" Enter first name:(first letter caps ");
gets(list[i].fname);
printf(" Enter middle name:(first letter caps ");
gets(list[i].fname);
printf(" Enter last name:(first letter caps ");
gets(list[i].fname);
printf("Enter date of birth (DD MM YYYY) :");
scanf("%d %d %d", &list[i].d, &list[i].m, &list[i].y);
printf("Enter Annual Income:");
scanf("%d, &list[i].income);
printf(" Enter Gender(M/F)";
gets(list[i].gender);
}
}
void display( struct client list[999], int s);
{
int i;
printf(" Full Name, DOB, Annual Income, Gender");
for (i=0;i<s;i++)
{
printf(%s %s %s %s %d %d %d %d %d %s ",list[i].fname,list[i].mname,list[i].lname,list[i].d,list[i].m,list[i].y,list[i].income,list[i].gender);
}
}
void incomeavg(struct client list[999], int s)
{
int i, avg=0;
for (i = 0; i < s; i++)
{ avg=avg+list[i].income;
}
}
//in case of any doubts feel free to ask in the comments
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.