19 July 2016

Từ khóa #define tiền xử lý, dùng để định nghĩa tên một hằng hoặc kiểu trong C

Ví dụ về #define FOR(i,a,b) for(int i = a; i < b; i++)
Java 2016
#include<conio.h>
#include<stdio.h>
#include<string.h>

#define FOR(i,a,b)  for(int i = a; i < b; i++)

float a[5][5] = //supervisor performance rating
{
 {0.013, 0.015, 0.017, 0.019, 0.021},
 {0.015, 0.017, 0.019, 0.021, 0.023},
 {0.017, 0.019, 0.021, 0.023, 0.027},
 {0.019, 0.021, 0.023, 0.025, 0.030},
 {0.021, 0.023, 0.025, 0.027, 0.040}
};
float PeerSalary[5] = {250,300,350,400,450};
typedef struct Employee
{
 int ID;
 char Name[30];
 int Peer;//peer performance rating
 int Sup;
 //float Salary = PeerSalary[Peer];
 
}Emp;
void OldAndNewSalary(Emp E[], int n){
 int count = 1;
 FOR(i,0,n)
 {
  printf("Employee %d : Old Salary : %.2f\n", count, PeerSalary[E[i].Peer]);
  float newSalary = PeerSalary[E[i].Peer] + PeerSalary[E[i].Peer]*a[E[i].Peer][E[i].Sup];
  printf("Employee %d : New Salary : %.2f\n", count, newSalary);
  count++;
 }
}

void in_it(Emp E[], int n)
{ 
 FOR(i,0,n)
 {
  printf("ID : \n"); scanf("%d", &E[i].ID);
  printf("Name : \n"); scanf("%s", &E[i].Name);
  printf("Peer performance rating (1-5) : \n"); scanf("%d", &E[i].Peer);
  printf("Supervisor performance rating (1-5) : \n"); scanf("%d", &E[i].Sup);
 } 
}

void inforEmp(Emp E[],int n)
{ FOR(i,0,n)
 {
  printf("ID : %d\n", E[i].ID); 
  printf("Name : %s\n", E[i].Name); 
  printf("Peer performance rating : %d\n", E[i].Peer);
  printf("Supervisor performance rating : %d\n", E[i].Sup);
 }
}

int meNu(int n)
{ printf("Chon chuc nang = ");
 scanf("%d", &n);
 if( n >= 1) return 1;
 else return 0;
}
int n;
int main()
{ 
 printf("Enter number Employee in Company : ");
 scanf("%d", &n);
 Emp E[10];
 while(true){
 int chose = meNu(n);
 switch(chose){
 case 1 : printf("Create table employee : \n");
   FOR(i,0,n)
   {
    in_it(E,n);
    inforEmp(E,n);
    OldAndNewSalary(E, n);
   } 
 case 0 : return 0;
 //default: printf("enter again");
  }
 }
 getch();
 return 0;
}
Hình ảnh code trên tool DEV C++

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang