السلام عليكم
اواجه صعوبه في اتمام اسايمنت بلغه السي ارجو منكم المساعده
الموضوع:
A company offers a loan for its employees .the company ranking the employees from rank 6 for beginners (as the lowest rank) to rank 1 for seniors (as the highest rank). The company applies pre-conditions to enable employees to get the loan. These conditions are :
1-the maximum amount of loan allowed must not exceed 3 times the salary.
2-the minimum rank of employee must be 4.
The deduction amount is calculated depending on the salary and the rank of the employee. The deduction policy is as follows:
Rank of employee deduction
1 salary*5%
2 salary*4%
3 salary *3%
4 salary*2%
the company needs to implement a menu-driven program to store and display information about the loan of its employees.
1-A menu structure should be implemented which contains the following menu items
A-add information of a new employee
B-display employee information.
C-display all employees information
D-exit system
2- a function to input the detailed information of a new employee of the company and stores it in employee file. The information is:
Employee number
Employee name
Employee salary
Employee rank
3-function to display employee information.
4- function to all employees information in the company
The menu structure should be updated to include the following entries.
A-enter loan details
B-answer queries
C-display report
5-a function to input information about the employee loan. store the information in the loan file if an employee satisfy the pre-conditions of the loan, otherwise do not store it and display a massage to inform the employee. The information is:
Employee number
Amount of the loan
Date of the loan
6-a function to calculate the deduction amount depending on the salary and rank of the employee and store it in the loan file
7- a function to answer the following queries:
a- how many employees get a loan
b- is an employee have a loan or not
c-what is the total amount of deductions
8-a function to display a loan report containing the following information:
Employee number
Employee name
Amount of the loan
Deduction amount
وهذي محاولتي فيه:
#include <stdio.h>
void main()
{
int request;
void add_new_employee();
void disp_employee_info();
void disp_all_employees_info();
void Exit_system();
/* display Menu options */
printf("Please select one of the following options:\n");
printf("1 - Add Information of a new employee\n");
printf("2 - Display an Employee Information\n");
printf("3 - Display all Employees Information\n");
printf("4 - Exit System\n");
scanf("%d", &request);
/* Processing user's request */
while (request !=4) {
switch (request) {
case 1:
/* function to add information of an new employee */
add_new_employee();
break;
case 2:
/* function to display an employee information */
disp_employee_info();
break;
case 3:
/* function to display all employees information */
disp_all_employees_info();
break;
default:
/* wrong data entry for menu item selection */
printf("Invalid Option ... try again");
}
}
/* End of Program */
}
void add_new_employee(EmplNo,EmplName,EmplSalary,EmplRank);
{
int EmplNo;
char EmplName[30];
double EmplSalary;
int EmplRank;
char MoreEmpl='y';
FILE *cfptr;
if ((cfptr=fopen("Employees.dat","a"))==NULL)
{
printf("Can not open file\n");
} // end if
else {
while (MoreEmpl !='n');
{
printf ("Enter Employee Number, Employee Name, Employee Salary, Employee RankCode\n");
scanf("%d %s %lf %d",&EmplNo,EmplName,&EmplSalary,&EmplRank);
fprintf(cfptr,"%d %s %lf %d\n",EmplNo,EmplName,EmplSalary,EmplRank);
printf ("Do you want anther Employee");
scanf("%s",&MoreEmpl);
}
fclose(cfptr);
} // end else
} // end add_new_employee function
void disp_employee_info()
{
FILE *fptr;
int empno;
char empname[30];
double empsalary;
int emprank;
char seemore='y';
int eno;
if ((fptr=fopen("employees.dat","r"))==NULL) {
printf("Error in opening Employee File for reading employees information\n");
}
else {
while (seemore=='y' || seemore=='Y')
{
rewind(fptr);
printf("Enter Employee Number to display employee information ");
scanf("%d\n",&eno);
while ( !feof(fptr))
{
fscanf(fptr,"%d %s %lf %d\n",&empno,empname,&empsalary,&emprank);
if (empno == eno) {
printf("Employee Number : %d\n", empno);
printf("Employee Name : %s\n", empname);
printf("Employee Salary: %lf\n",empsalary);
printf("Employee Rank : %d\n",emprank);
break; }
}
printf("Do you wish to see another employee information [Y/N]: ");
scanf("%c",&seemore);
}
}
fclose(fptr);
}
void disp_all_employees_info()
{
FILE *fptr;
int empno;
char empname[30];
double empsalary;
int emprank;
if ((fptr=fopen("employees.dat","r"))==NULL) {
printf("Erron in opening Employee File for reading employees information\n");
}
else {
while ( !feof(fptr))
{
fscanf(fptr,"%d %s %lf %d\n",&empno,empname,&empsalary,&emprank);
printf("Employee Number : %d\n", empno);
printf("Employee Name : %s\n", empname);
printf("Employee Salary: %lf\n",empsalary);
printf("Employee Rank : %d\n",emprank);
}
fclose(fptr);
}
}