/**********************************************************
????作者: 刘家
????时间:2015年12月24日02:44:48
????编译器:dev
***********************************************************/
?
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
?
# define MAX 50
# define MON 6
?
?
?
int count=0; //用于统计职工的总人数
struct Salary_Info
{
int Card_No; //工资卡号
char name[20]; //姓名
float Init_Salary; //应发工资
float Water_Rate; //水费
float Electric_Rate; //电费
float tax; //税金
float Final_Salary; //实发工资
};
/*下面每个变量分别代表上面对应变量的变化 (用百分比表示)*/
?
struct Slary_Change{
????float Init_Salary;
????float Water_Rate;
????float Electric_Rate;
????float tax;
????float Final_Salary;
?
} ;
?
/* 次结构体数组用于存放结构体变量中每个成员的平均值,因为是基于月份求的平均值,二我在存放
????数据时 ,是把二维结构体数组的列下标作为月份来存的 而所得的平均值只有一个,所以定
????义一个一维结构体数组存放 存放每一个没个信息的平均值就可以了
*/
struct Slary_Average{
????float Init_Salary_Average;
????float Water_Rate_Average;
????float Electric_Rate_Average;
????float tax_Average;
????float Final_Salary_Average;
};
?
struct Slary_Average Average[MAX]; //存放每个员工每个信息的平均值
struct Slary_Change Change[MAX][MON]; //存放每个员工每个信息的变化情况
struct Salary_Info Array[MAX][MON]; //存放每个员工的单一信息
?
?
void Load_Information(); //导入数据
void Keep_Information(); //保存数据
?
void Add_Information(); //添加数据
void Change_Information(); //修改信息
void Deleat_Information(); //删除信息
?
int Find_Information(); //查找员工信息
?
void Output_Infromation(); //关于输出信息的函数
void Output_One_Infromation(); //输出单个信息
void Output_All_Infromation(); //输出全部信息
void Output_Average_Information(int n); //输出信息的平均值平均值
void Output_Change_Information(int n); //输出信息的变化率
?
void Sort_Information(); //对员工的信息进行排序
void Echange_Information(int m ,int n); //将两个员工的所有信息交换
?
void Calculate_Information(); // 计算已经存在的信息
?
?
void Inpu_Main_tValue(); //输出主菜单
?
?
?
//主函数,将会从这里选择功能,进入相应的函数
int main() {
????int i;
????char ch;
????Load_Information();
????do {
?
????????Inpu_Main_tValue();
????????printf("请选择功能:");
????????scanf("%d",&i);
????????switch(i) {
????????????Inpu_Main_tValue();
????????????case 1: Output_Infromation();
????????????????break;
????????????case 2: Add_Information();
????????????????break;
????????????case 3: Change_Information();
????????????????break;
????????????case 4: Deleat_Information();
????????????????break;
????????????case 5: Sort_Information();
????????????????break;
????????????case 6: Calculate_Information();
????????????????break;
????????????case 7: Keep_Information();
????????????????break;
????????????case 8: exit(0);
????????????????break;
????????}
????printf("是否返回主菜单?(Y/N)\n");
????scanf(" %c",&ch);????
????????
????
????} while( ch==‘y‘||ch==‘Y‘);
????
}
?
void Load_Information()
{
????int i,j;
????int n;
????FILE * fp;
????char ch [20];
????
????putchar(‘\n‘);
????printf("------------------------------------------------------------------------\n");
????printf("| 请选择信息导入方式 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 1.自动导入本地文件 2.导入指定本地 |\n");
????printf("------------------------------------------------------------------------\n");
????putchar(‘\n‘);
????printf("请选择功能:");
????scanf("%d",&n);
????
????if( n==1 )
????{
????????fp = fopen( "Information.txt","rb");
????????if( fp==NULL )
????????????printf("没有学生信息!\n");
????????else
????????{
????????????//导入一个总人数
????????????fread(&count,sizeof(int),1,fp );
????????????
????????????//导入员工的基本信息
????????????for ( i=0 ; i<count ; i++ )
????????????{
????????????????for (j=0 ; j<MON ;j++)
????????????????{
????????????????????fread(&Array[i][j],sizeof(struct Salary_Info),1,fp);
????????????????}
????????????}
????????????
????????????//导入一个信息的平均值
????????????for ( i=0 ; i<count ; i++ )
????????????{
????????????????fread(&Average[i],sizeof(struct Slary_Average),1,fp);????
????????????}
????????????
????????????//导入员工信息的变化率
????????????for ( i=0 ; i<count ; i++ )
????????????{
????????????????for (j=0 ; j<MON ;j++)
????????????????{
????????????????????fread(&Change[i][j],sizeof(struct Slary_Change),1,fp);
????????????????}
????????????}
????????????
????????}
????????
????????printf("导入信息成功!\n");
????}
????else if( n==2 )
????{
????????printf("请输入指定文件及其路径:");
????????scanf("%s",&ch);
????????fp = fopen( ch,"rb+");????
????????fread(&count,sizeof(int),1,fp );
????????
????????????//导入一个总人数
????????????fread(&count,sizeof(int),1,fp );
????????????
????????????//导入员工的基本信息
????????????for ( i=0 ; i<count ; i++ )
????????????{
????????????????for (j=0 ; j<MON ;j++)
????????????????{
????????????????????fread(&Array[i][j],sizeof(struct Salary_Info),1,fp);
????????????????}
????????????}
????????????
????????????//导入一个信息的平均值
????????????for ( i=0 ; i<count ; i++ )
????????????{
????????????????fread(&Average[i],sizeof(struct Slary_Average),1,fp);????
????????????}
????????????
????????????//导入员工信息的变化率
????????????for ( i=0 ; i<count ; i++ )
????????????{
????????????????for (j=0 ; j<MON ;j++)
????????????????{
????????????????????fread(&Change[i][j],sizeof(struct Slary_Change),1,fp);
????????????????}
????????????}
????????????
????}
????else
????????printf("输入错误!\n");
????????
????
????fclose(fp);
?
}
void Keep_Information()
{
????int i,j;
????int n;
????char ch_1[20]; // 用于存放路径
????char ch_2; //用于选择循环
????FILE * fp;
????fp = fopen( "Information.txt","wb+");
?
if (fp == NULL)
return;
???? ?
???? ?
?
????putchar(‘\n‘);
????printf("----------------------------------------------------------\n");
????printf("| 请选择信息导入方式 |\n");
????printf("----------------------------------------------------------\n");
????printf("| 1.自动保存至本地文件 2.保持至指定本地 |\n");
????printf("----------------------------------------------------------\n");
????putchar(‘\n‘);
????printf("请选择功能:");
????scanf("%d",&n);
????
????if( n==1 )
????{
????????
????????if( fp==NULL )
????????????printf("保存失败!\n");
????????????
???? ????//保存员工的个数
????????fwrite(&count,sizeof(int),1,fp );
????????
????????//保存员工的基本信息
????????for ( i=0 ; i<count ; i++ )
????????{
????????????for (j=0 ; j<MON ;j++)
????????????{
????????????????fwrite(&Array[i][j],sizeof(struct Salary_Info),1,fp);
????????????}
????????}
????????//保存一个信息的平均值
????????for ( i=0 ; i<count ; i++ )
????????{
????????????fwrite(&Average[i],sizeof(struct Slary_Average),1,fp);????
????????}
????????//保存员工信息的变化率
????????for ( i=0 ; i<count ; i++ )
????????{
????????????for (j=0 ; j<MON ;j++)
????????????{
????????????????fwrite(&Change[i][j],sizeof(struct Slary_Change),1,fp);
????????????}
????????}
????????
????????
????}
????else if( n==2 )
????{
????????printf("请输入指定文件及其路径:");
????????scanf("%s",ch_1);
????????fp = fopen( ch_1,"rb+");
????????????
????????//保存员工的个数
????????fwrite(&count,sizeof(int),1,fp );
?
????????
????????//保存员工的基本信息
????????for ( i=0 ; i<count ; i++ )
????????{
????????????for (j=0 ; j<MON ;j++)
????????????{
????????????????fwrite(&Array[i][j],sizeof(struct Salary_Info),1,fp);
????????????}
????????}
????????
????????//保存一个信息的平均值
????????for ( i=0 ; i<count ; i++ )
????????{
????????????fwrite(&Average[i],sizeof(struct Slary_Average),1,fp);????
????????}
????????
????????//保存员工信息的变化率
????????for ( i=0 ; i<count ; i++ )
????????{
????????????for (j=0 ; j<MON ;j++)
????????????{
????????????????fwrite(&Change[i][j],sizeof(struct Slary_Change),1,fp);
????????????}
????????}
????}
????
????else
????????printf("输入错误!\n");
???? ?
?
????
????fclose(fp);
}
void Add_Information()
{
????
????int n;
????int i,j;
????
????printf("请输入要添加员工的人数:");
????scanf("%d",&n);
????putchar(‘\n‘);
????
????for ( i=count ; i<count+n ; i++ )
????{
????????
????????printf("请输入第%d个员工的信息:\n",i+1);
????????
????????printf("姓名: ");
????????????scanf("%s",Array[i][0].name);
????????
????????printf("工资卡号:");
????????????scanf("%d",&Array[i][0].Card_No);
????????putchar(‘\n‘);
?
????????for ( j=0 ; j<MON ; j++ )
????????{
?
????????????printf("请输入第%d个员工第%d个月的信息。\n",i+1,j+1);????
????????????
????????????
????????????printf("应发工资:");
????????????????scanf("%f",&Array[i][j].Init_Salary);
????????????
????????????printf("水费: ");
????????????????scanf("%f",&Array[i][j].Water_Rate);
????????????
????????????printf("电费: ");
????????????????scanf("%f",&Array[i][j].Electric_Rate);
????????????????
????????????
????????}
???? }
???? count = count + n; //更新总人数
????
???? /*将每个员工后面3个月的姓名与工资卡号复制*/
???? for ( i=0 ; i<count ; i++ )
???? {
???? ????Array[i][2].Card_No = Array[i][1].Card_No = Array[i][0].Card_No;
???? ????//Array[i][2].name = Array[i][1].name = Array[i][0].name;
???? }
????
}
void Inpu_Main_tValue(){
????
????printf("一共有%d个职工信息。\n",count);
????putchar(‘\n‘);
????printf("------------------------------------------------------------------------\n");
????printf("| 主菜单 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 1.浏览信息 2.添加信息 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 3.修改信息 4.删除信息 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 5.排序信息 6.统计信息 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 7.保存信息 8.退出系统(不保存) |\n");
????printf("------------------------------------------------------------------------\n");
????putchar(‘\n‘);
?
}
/*总的选择输出函数,将会由其引导各种输出*/
?
void Output_Infromation()
{
????int i;
????char ch;
????
????printf("注意:使用此功能之前必须要先统计信息。\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 1.浏览所有员工的基本信息 2.浏览单个员工的基本信息 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 3.浏览所有员工信息的平均值 4.浏览单个员工信息的平均值 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 5.浏览所有员工信息的变化率 6.浏览单个员工信息的变化率 |\n");
????printf("------------------------------------------------------------------------\n");
????
????printf("请选择输出方式:");
????scanf("%d",&i);
????
????/*????此处设计的不合理,在输出基本信息的时候我定义个2个函数分别输出 单一和所有信息
???????? 而信息的平均值我就,先调用函数,然后在函数值判断怎么输出
????*/
????
????if( i==2 )
????????Output_One_Infromation();
????else if( i==1 )
????????Output_All_Infromation();
????else if( i==3||i==4)
????{
????????Output_Average_Information(i);
????}
????else if ( i==5 || i==6 )
{
????????Output_Change_Information(i);
}
????????
????else
????????printf("选择错误!");
????return ;
????
????
}
?
?
int Find_Information()
{
????int i;
????int Id_Number; //存放工资卡卡号
????int n;
????char Name[20]; //存放姓名
????
????printf("------------------------------------------------------------------------\n");
????printf("| 1.按工资卡号查找 2.按姓名查找 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("请选择查找方式:");
????scanf("%d",&n);
????
????if ( n==1)
????{
????????printf("请输入工资卡号:");
????????scanf("%d",&Id_Number);
????????
????????for ( i=0 ; i<count ; i++ )
????????{
????????????if( Array[i][0].Card_No==Id_Number)
????????????????return i;????
????????}
????????
????????/*如果未查到,则返回-1,后面函数在接收返回值的时候也会进行检查*/
????????
????????if( i==count )
????????{
????????????printf("未查到该员工!\n");
????????????return -1;
????????}
????????
????}
????else if(n==2)
????{
????????printf("请输入要查找的员工的姓名:");
????????scanf("%s",&Name);
????????
????????for ( i=0 ; i<count ; i++ )
????????{
????????????if( strcmp(Array[i][0].name,Name)==0)
????????????????return i;????
????????}
????????
????????/*如果未查到,则返回-1,后面函数在接收返回值的时候也会进行检查*/
????????
????????if( i==count )
????????{
????????????printf("未查到该员工!\n");
????????????return -1;
????????}
????????
????????
????}
????else
????{
????????printf("输入错误!\n");
????????return -1;
????}
???? ?
???? ?
????
????return i;
}
?
void Output_One_Infromation()
{
????int n;
????int i,j;
???? ?
????
????printf("请先找到该员工。\n");
????n = Find_Information();
????
????if( n == -1 )
????????printf("未找到该员工");????
????
????printf("姓名:%s\n",Array[n][0].name);
????printf("工资卡:%d\n",Array[n][0].Card_No);
????putchar(‘\n‘);
????printf("------------------------------------------------------------------------\n");
????printf("| 月份 应发工资 水费 电费 税金 实发工资 |\n");
????printf("------------------------------------------------------------------------\n");
????????
????for ( i=0 ; i<MON ; i++ )
????{
????????
????????printf(" %4.1d %4.1f %4.1f %4.1f %4.1f %4.1f ",
????????????????i+1,Array[n][i].Init_Salary,Array[n][i].Water_Rate,Array[n][i].Electric_Rate
????????????????,Array[n][i].tax,Array[n][i].Final_Salary);
????}
????putchar(‘\n‘);
????
}
?
//输出所有一个的基本信息
void Output_All_Infromation()
{
????int i,j;
????putchar(‘\n‘);
????printf("------------------------------------------------------------------------\n");
????printf("| 月份 应发工资 水费 电费 税金 实发工资 |\n");
????printf("------------------------------------------------------------------------\n");
????????
????
????for ( i=0 ; i<count ; i++ )
????{
????????
????????printf("第%d个人的信息:",i+1);
????????printf("姓名:%s",Array[i][0].name);
????????printf(" 工资卡号:%d\n",Array[i][0].Card_No);
????????putchar(‘\n‘);
????????
????????
????????for (j=0 ; j<MON ; j++ )
????????{
????????????printf(" %4.1d %4.1f %4.1f %4.1f %4.1f %4.1f ",
????????????????j+1,Array[i][j].Init_Salary,Array[i][j].Water_Rate,Array[i][j].Electric_Rate
????????????????,Array[i][j].tax,Array[i][j].Final_Salary);
????????????putchar(‘\n‘);
????????}
????????putchar(‘\n‘);
????}
????
}
void Output_Average_Information(int i)
{
????int j ;
????printf("------------------------------------------------------------------------\n");
????printf("| 员工信息平均值统计 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 姓名 工资卡号 应发工资 水费 电费 税金 实发工资 |\n");
????printf("------------------------------------------------------------------------\n");
????if( i==3 )
????{
????
????????for ( i=0 ; i<count ; i++)
????????{
????????????printf(" %s %4d %4.1f %4.1f %4.1f %4.1f %4.1f ",Array[i][0].name,
????????????????Array[i][0].Card_No,Average[i].Init_Salary_Average,Average[i].Water_Rate_Average,
????????????????Average[i].Electric_Rate_Average,Average[i].tax_Average,Average[i].Final_Salary_Average);
????????????????
????????????putchar(‘\n‘);????
????????}
????}
????
????if( i==4 )
????{
????????int n;
????????printf("请先找出要浏览员工:");
????????n = Find_Information();
????????if( n==-1)
????????????printf("未找到该员工!\n");
????????else
????????{
????????????printf(" %s %4d %4.1f %4.1f %4.1f %4.1f %4.1f %4.1f",Array[i][0].name,
????????????????Array[i][0].Card_No,Average[i].Init_Salary_Average,Average[i].Water_Rate_Average,
????????????????Average[i].Electric_Rate_Average,Average[i].tax_Average,Average[i].Final_Salary_Average);
????????????????
????????????putchar(‘\n‘);????
????????}????????
????}
????
}
?
?
//输出信息的变化率
void Output_Change_Information(int n)
{
????int i,j;
?
????
????if( n==5)
????{
????????
????????printf("------------------------------------------------------------------------\n");
????????printf("| 月份 应发工资 水费 电费 税金 实发工资 |\n");
????????printf("------------------------------------------------------------------------\n");
????????
????????for ( i=0 ; i<count ; i++ )
????????{
????????????printf("变化率:");
????????????printf("姓名:%s 工资卡号: %d\n",Array[i][0].name,Array[i][0].Card_No);
????????????putchar(‘\n‘);
????????????for ( j=1 ; j<MON ; j++ )
????????????{
????????printf(" %d \t %2.1f% \t %2.1f% \t %2.1f% \t %2.1f% \t %2.1f% ",
????????????????j+1,Change[i][j].Init_Salary,Change[i][j].Water_Rate,Change[i][j].Electric_Rate
????????????????,Change[i][j].tax,Change[i][j].Final_Salary);
????????????????putchar(‘\n‘);
????????????}
????????}
?
????}
???? ?
????
}
void Sort_Information()
{
????int i,j;
????int n;
????printf(" 注意:使用此功能钱,必须先使用 6.统计信息!\n");
????printf("------------------------------------------------------------------------\n");
????printf("| 1.按平均工资排序 2.按平均工资增长率排序 |\n");
????printf("------------------------------------------------------------------------\n");
????printf("请选择排序方式:");
????scanf("%d",&n);
????
????if( n==1 )
????{
????????for ( i=0 ; i<count ; i++ )
????????{
????????????for ( j=i+1 ; j<count ; j++ )
????????????{
????????????????if( Average[i].Final_Salary_Average>Average[j].Final_Salary_Average);
????????????????
????????????????/*????次出设计的不怎么好,因为每次交换来个员工的基本信息之后都会对所有信
????????????????????息进行一次计算,应该再写一个对2个员工的信息进行计算的函数,但是
????????????????????我不想写了。
????????????????*/
????????????????Echange_Information(i,j);
????????????}
????????}
????}
????else if( n==2 )
????{
????????
????}
????else
????{
????????printf("输入错误!\n");
????????return;
????}
????printf("排序成功!\n");
}
?
/* 交换2个员工的说有信息 */
void Echange_Information(int m ,int n)
{
????int i;
????struct Salary_Info temp_1;
????
????/*????此处已经确定2个员工的序号(结构体数组的行下标)
????????只需要交换该员工所对应的每个结构体类型的,每个月的
????????数据即可
????*/
????
????for ( i=0 ; i<MON ; i++ )
????{
????????/*交换每个学生原始信息*/
????????temp_1 = Array[m][i];
????????Array[m][i] =Array[n][i];
????????Array[n][i] = temp_1;
???? /* 为了避免将每个员工每个月的每种信息进行交换
????????????我选择值叫换基本的信息,比如平均值,变化率
????????????什么的,我选择在交换基本信息之后重新计算
????????????
???????? */????
?
????????
????}
????????
}
?
void Change_Information()
{
????int i,j;
????int n;
????int flag;
????printf("请先找出要修改的信息!\n");
????n = Find_Information();
????
????if( n==-1 )
????{
????????printf("未找到该员工!\n");
????????return ;
????}
????else
????{
????????char ch;
???????? ?
????????
????????????printf("姓名:%s\n",Array[n][0].name);
????????????printf("工资卡:%d\n",Array[n][0].Card_No);
????????????putchar(‘\n‘);
????????????printf("------------------------------------------------------------------------\n");
????????????printf("| 月份 应发工资 水费 电费 税金 实发工资 |\n");
????????????printf("------------------------------------------------------------------------\n");
????????????
????????for ( i=0 ; i<MON ; i++ )
????????{
????????????
????????????printf(" %4.1d %4.1f %4.1f %4.1f %4.1f %4.1f ",
????????????????????i+1,Array[i][0].Init_Salary,Array[i][0].Water_Rate,Array[i][0].Electric_Rate
????????????????????,Array[i][0].tax,Array[i][0].Final_Salary);
???? putchar(‘\n‘);
????????}
???????? ?
???? ?
????????
????????printf("是否修改以上信息?(Y/N)\n");
????????scanf(" %c",&ch);
????????
????????/**正式修改信息*/
????????if(ch==‘Y‘||ch==‘y‘)
????????{
????????????????printf("请输入该员工的新信息。\n");
????????????
????????????printf("姓名: ");
????????????????scanf("%s",Array[n][0].name);
????????????
????????????printf("工资卡号:");
????????????????scanf("%d",&Array[n][0].Card_No);
????????????putchar(‘\n‘);
???? ?
????????????for ( j=0 ; j<MON ; j++ )
????????????{
???? ?
????????????????printf("请输入该员工员工第%d个月的信息。\n",j+1);????
????????????????
????????????????
????????????????printf("应发工资:");
????????????????????scanf("%f",&Array[n][j].Init_Salary);
????????????????
????????????????printf("水费: ");
????????????????????scanf("%f",&Array[n][j].Water_Rate);
????????????????
????????????????printf("电费: ");
????????????????????scanf("%f",&Array[n][j].Electric_Rate);
????????????????????
????????????????
????????????}
????????}
????????else
????????{
????????????return;????
????????}????
????????
????????????
????}
}
void Deleat_Information()
{
????int n,i,j;
????char ch;
????
????printf("请先找出你要删除的信息!\n");
????n = Find_Information();
????if( n == -1 )
????{
????????printf("未找到该员工!\n");
????????return ;
????}
????
????putchar(‘\n‘);
????printf("姓名:%s\n",Array[n][0].name);
????printf("工资卡:%d\n",Array[n][0].Card_No);
????????putchar(‘\n‘);
????????printf("------------------------------------------------------------------------\n");
????????printf("| 月份 应发工资 水费 电费 税金 实发工资 |\n");
????????printf("------------------------------------------------------------------------\n");
????????
????for ( i=0 ; i<MON ; i++ )
????{
????????
????????printf(" %4.1d %4.1f %4.1f %4.1f %4.1f %4.1f ",
????????????????i+1,Array[n][i].Init_Salary,Array[n][i].Water_Rate,Array[n][i].Electric_Rate
????????????????,Array[n][i].tax,Array[n][i].Final_Salary);
????????????????putchar(‘\n‘);
????}
????putchar(‘\n‘);
????
????printf("是否删除以上信息?(Y/N)\n");
????scanf(" %c",&ch);
????
????if ( ch==‘Y‘||ch == ‘y‘)
????{
????????
????????for( i=n ; i<count-1 ; i++ )
????????{
????????????for ( j=0 ; j<MON ; j++ )
????????????{
????????????????Array[i][j] = Array[i+1][j];????
????????????}????
????????}
????????count--;
????????printf("删除成功!\n");
????}
????else
????{
????????return ;
????}
???? ?
????
????
}
?
/*计算各个员工的信息的平均值,变换*/
void Calculate_Information()
{
????int i,j;
????
????char ch;
????
????/* 计算每个员工每个月应该缴纳的税金 */
????for ( i=0 ; i<count ; i++ )
????{
????????for( j=0 ; j<MON ; j++ )
????????{
????????????if( Array[i][j].Init_Salary<=800 )
????????????????Array[i][j].tax=0;
????????????
????????????else if( Array[i][j].Init_Salary>800&& Array[i][j].Init_Salary<1400)
????????????????Array[i][j].tax = ( Array[i][j].Init_Salary-800)*float(0.05);
????????????
????????????else if ( Array[i][j].Init_Salary>1400 )
????????????????Array[i][j].tax = ( Array[i][j].Init_Salary-1400)*float(0.1);????????????????
????????}????
????}
????
????
????/*计算每个员工每个月最后得到的工资*/
????
????for ( i=0 ; i<count ; i++ )
????{
????????for ( j=0 ; j<MON ; j++ )
????????{
????????????Array[i][j].Final_Salary = Array[i][j].Init_Salary - Array[i][j].Electric_Rate-
????????????Array[i][j].Water_Rate - Array[i][j].tax;
????????}
????}
???? ?
????
????/*计算每个员工每个信息的平均值*/
????
????/*分别定义出用于存放没个信息总数值的变量*/
????
????float Average_Sum_Init_Salary;
????float Average_Sum_Water_Rate;
????float Average_Sum_Electric_Rate;
????float Average_Sum_tax;
????float Average_Sum_Final_Salary;
????
????for ( i=0 ; i<count ; i++ )
????{
????????for( j=0 ; j<MON ; j++ )
????????{
????????????Average_Sum_Init_Salary += Array[i][j].Init_Salary;
????????????Average_Sum_Water_Rate+= Array[i][j].Water_Rate;
????????????Average_Sum_Electric_Rate += Array[i][j].Electric_Rate;
????????????Average_Sum_tax+= Array[i][j].tax;
????????????Average_Sum_Final_Salary += Array[i][j].Final_Salary;
????????}
????????
????????/*每个员工的每个信息的平均值*/
????????
????????Average[i].Init_Salary_Average = Average_Sum_Init_Salary / MON;
????????Average[i].Water_Rate_Average = Average_Sum_Water_Rate / MON;
????????Average[i].Electric_Rate_Average = Average_Sum_Electric_Rate / MON;
????????Average[i].tax_Average = Average_Sum_tax / MON;
????????Average[i].Final_Salary_Average = Average_Sum_Final_Salary /MON;
????????
????????
????????/*在计算玩平均值后要讲总和这个变量的值初始化为0,不然后面会出错*/
????????
????????????Average_Sum_Init_Salary=0;
????????????Average_Sum_Water_Rate=0;
????????????Average_Sum_Electric_Rate=0;
????????????Average_Sum_tax=0;
????????????Average_Sum_Final_Salary=0;????
????????????????
????}
???? ?
????
????/*计算每个员工每个月于前一个月的变化率*/
????
????for( i=0 ; i<count ; i++ )
????{
????????
????????
????????/*分别计算每个员工种信息每个月的变化率*/
????????for ( j=1 ; j<MON ; j++ )
????????{
????????
????????????Change[i][j].Init_Salary = (Array[i][j].Init_Salary - Array[i][j-1].Init_Salary) / Array[i][j].Init_Salary;
????????????Change[i][j].Electric_Rate = (Array[i][j].Electric_Rate - Array[i][j-1].Electric_Rate) / Array[i][j].Electric_Rate;
????????????Change[i][j].Water_Rate = (Array[i][j].Water_Rate - Array[i][j-1].Water_Rate) / Array[i][j].Water_Rate;
????????????Change[i][j].tax = (Array[i][j].tax - Array[i][j-1].tax) / Array[i][j].tax;
????????????Change[i][j].Final_Salary = (Array[i][j].Final_Salary - Array[i][j-1].Init_Salary) / Array[i][j].Final_Salary;
????????
????????}
????}
????printf("计算结束!\n");
????????????
}
?
?
?
?
?
?
原文:http://www.cnblogs.com/jiavv5/p/5103770.html