tinhspt
21-04-2009, 09:13
Em đang gặp một số vấn đề về bài này mà chưa tìm được hướng giải quyết mong các bác trợ giúp
ĐỀ:
Write a C program to store employee detail in a structure array. The data should include employee ID ,name ,salary , and date of joining ( include month ,year ,date ) . The date of joining should be stored in a structure . The program should perform the following :
- Function accept n element ( 0< n < 50) of EMPLOYEE structure (4)
- Function accept detail of EMPLOYEE structure
- Function display detail of EMPLOYEE structure
A Increase the salaries according to the following rules:
If salary <=2000 then increase 15%
If salary >2000 and <=5000 then increase 10%
If salary >5000 then no increase and display “ No …” 2
B Display the detail of employees who complete 10 years with the company 5
Bài làm:
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<stdlib.h>
struct date{
unsigned char day[10];
unsigned char month[10];
unsigned char year[10];
};
struct joining{
int id;
char name[30];
int salary;
struct date dt;
}join;
int capphat(joining*ptr);
void nhapdl(joining*ptr);
void indl(joining*ptr);
void increase(joining*ptr);
void work(joining*ptr);
int n;
void main(){
joining* ptr;
if(capphat(ptr)){
nhapdl(ptr);
indl(ptr);
}
increase(ptr);
work(ptr);
getch();
}
int capphat(joining*ptr){
do{
printf("\n Ban muon nhap bao nhieu nhan vien: ");
scanf("%d",&n);
}while(n<=0||n>=50);
if(ptr==NULL){
return 0;
}else{
ptr=(joining*)malloc(n*sizeof(joining));
return 1;
}
}
void nhapdl(joining*ptr){
int i;
int t1,t2;
printf("\n nhap du lieu");
for(i=0;i<n;i++){
printf("\n Nhap du lieu cho nguoi thu %d",i);
printf("\n Nhap ID nhan vien : ");scanf("%d",&t1);
(ptr+i)->id=t1;
printf("\n Nhap ten nhan vien: ");
fflush(stdin);
gets((ptr+i)->name);
printf(" \nNhap luong nhan vien:");scanf("%d",&t2);
(ptr+i)->salary=t2;
printf(" \nNhap ngay vao cong ty:\n");
fflush(stdin);
gets((ptr+i)->dt.day);
printf(" \nNhap thang vao cong ty:\n");
fflush(stdin);
gets((ptr+i)->dt.month);
printf(" \nNhap nam vao cong ty:\n");
fflush(stdin);
gets((ptr+i)->dt.year);
}
}
void indl(joining*ptr){
int i;
printf("\n In du lieu: ");
for(i=0;i<n;i++){
printf("\n EMPLOYEE %d",i);
printf("\n");
printf("\n ID :%d",(ptr+i)->id);
printf("\n name :%s",(ptr+i)->name);
printf("\n salary:%d",(ptr+i)->salary);
printf("\n day %s month %s year %s",(ptr+i)->dt.day,(ptr+i)->dt.month,(ptr+i)->dt.year);
}
}
void work(joining*ptr){
int i,year1,kt;
printf("\n In ra nhung ngoi lam viec voi cong ty 10 nam");
printf("\n Nhap vao ngay thanh lap cong ty: ");
scanf("%d",&year1);
for(i=0;i<n;i++)
{
kt=year1-(((ptr+i)->dt.year));
if(kt>=10)
indl(ptr);
else
printf("\nNhan vien nay lam viec cho cong ty it hon 10 nam");
}
}
void increase(joining*ptr){
int i;
for(i=0;i<n;i++){
if(((ptr+i)->salary)<=2000)
(((ptr+i)->salary)*15)/100;
if(((ptr+i)->salary)>2000 && ((ptr+i)->salary)<5000)
(((ptr+i)->salary)*10)/100;
if(((ptr+i)->salary)>5000);
}
}
ĐỀ:
Write a C program to store employee detail in a structure array. The data should include employee ID ,name ,salary , and date of joining ( include month ,year ,date ) . The date of joining should be stored in a structure . The program should perform the following :
- Function accept n element ( 0< n < 50) of EMPLOYEE structure (4)
- Function accept detail of EMPLOYEE structure
- Function display detail of EMPLOYEE structure
A Increase the salaries according to the following rules:
If salary <=2000 then increase 15%
If salary >2000 and <=5000 then increase 10%
If salary >5000 then no increase and display “ No …” 2
B Display the detail of employees who complete 10 years with the company 5
Bài làm:
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
#include<stdlib.h>
struct date{
unsigned char day[10];
unsigned char month[10];
unsigned char year[10];
};
struct joining{
int id;
char name[30];
int salary;
struct date dt;
}join;
int capphat(joining*ptr);
void nhapdl(joining*ptr);
void indl(joining*ptr);
void increase(joining*ptr);
void work(joining*ptr);
int n;
void main(){
joining* ptr;
if(capphat(ptr)){
nhapdl(ptr);
indl(ptr);
}
increase(ptr);
work(ptr);
getch();
}
int capphat(joining*ptr){
do{
printf("\n Ban muon nhap bao nhieu nhan vien: ");
scanf("%d",&n);
}while(n<=0||n>=50);
if(ptr==NULL){
return 0;
}else{
ptr=(joining*)malloc(n*sizeof(joining));
return 1;
}
}
void nhapdl(joining*ptr){
int i;
int t1,t2;
printf("\n nhap du lieu");
for(i=0;i<n;i++){
printf("\n Nhap du lieu cho nguoi thu %d",i);
printf("\n Nhap ID nhan vien : ");scanf("%d",&t1);
(ptr+i)->id=t1;
printf("\n Nhap ten nhan vien: ");
fflush(stdin);
gets((ptr+i)->name);
printf(" \nNhap luong nhan vien:");scanf("%d",&t2);
(ptr+i)->salary=t2;
printf(" \nNhap ngay vao cong ty:\n");
fflush(stdin);
gets((ptr+i)->dt.day);
printf(" \nNhap thang vao cong ty:\n");
fflush(stdin);
gets((ptr+i)->dt.month);
printf(" \nNhap nam vao cong ty:\n");
fflush(stdin);
gets((ptr+i)->dt.year);
}
}
void indl(joining*ptr){
int i;
printf("\n In du lieu: ");
for(i=0;i<n;i++){
printf("\n EMPLOYEE %d",i);
printf("\n");
printf("\n ID :%d",(ptr+i)->id);
printf("\n name :%s",(ptr+i)->name);
printf("\n salary:%d",(ptr+i)->salary);
printf("\n day %s month %s year %s",(ptr+i)->dt.day,(ptr+i)->dt.month,(ptr+i)->dt.year);
}
}
void work(joining*ptr){
int i,year1,kt;
printf("\n In ra nhung ngoi lam viec voi cong ty 10 nam");
printf("\n Nhap vao ngay thanh lap cong ty: ");
scanf("%d",&year1);
for(i=0;i<n;i++)
{
kt=year1-(((ptr+i)->dt.year));
if(kt>=10)
indl(ptr);
else
printf("\nNhan vien nay lam viec cho cong ty it hon 10 nam");
}
}
void increase(joining*ptr){
int i;
for(i=0;i<n;i++){
if(((ptr+i)->salary)<=2000)
(((ptr+i)->salary)*15)/100;
if(((ptr+i)->salary)>2000 && ((ptr+i)->salary)<5000)
(((ptr+i)->salary)*10)/100;
if(((ptr+i)->salary)>5000);
}
}