1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
| #include <stdio.h> #include <stdlib.h> #include <string.h>
#define TEADIR "/Users/****/CProjects/****/Data/teacherinfo.txt" #define MANDIR "/Users/****/CProjects/****/Data/maninfo.txt" #define TEAPW "/Users/****/CProjects/****/Password/pw_tea.txt" #define MANPW "/Users/****/CProjects/****/Password/pw_man.txt"
#define FROMTEA "/Users/****/CProjects/****/Message/from_tea.txt" #define TOMAN "/Users/*****/CProjects/****/Message/to_man.txt"
char* transfer(int num);
typedef struct teacher { int teaNo; char* teaName; char* teaSex; char* workUnitName; char* address; char* telNo; double basicWage; double allowance; double tax; } Teacher; char* nameGen() { char LastName[21][8] = {"赵", "钱", "孙", "李", "周", "吴", "郑", "王", "黄", "路", "蔡", "司", "张", "高", "刘", "胡", "侯", "花", "柳", "韩", "常"}; char FirstName[16][8] = {"长", "广", "亮", "乐", "璐", "泉", "雨", "楠", "同", "曈", "火", "淼", "旺", "富", "健", "康"}; int ran_LastName = rand() % 21; int ran_FirstName1 = rand() % 16; int ran_FirstName2 = rand() % 16; char* fullName = (char*)malloc(sizeof(char) * 16);
strcpy(&fullName[0], LastName[ran_LastName]);
int len1 = strlen(fullName); strcpy(&fullName[len1], FirstName[ran_FirstName1]);
int len2 = strlen(fullName); strcpy(&fullName[len2], FirstName[ran_FirstName2]);
int len3 = strlen(fullName); fullName[len3] = '\0'; return fullName; } char* sexGen() { char* sex = (char*)malloc(sizeof(char) * 3); int ran = rand() % 2; if (ran == 1) { strcpy(&sex[0], "男"); } else { strcpy(&sex[0], "女"); } sex[3] = '\0'; return sex; }
char* addrGen() { int rand0 = rand() % 5; int rand1 = rand() % 52; char City[5][40] = {"西安市雁塔区春林四路", "西安市莲湖区西北一路", "西安市碑林区长安北路", "西安市经济技术尚苑路", "西安市高新区高新一路"}; char* addr = (char*)malloc(sizeof(char) * 1024);
char *temp = City[rand0]; int len = strlen(temp); strcpy(&addr[0], temp);
char No[3] = {0}; strcpy(&No[0],transfer(rand1)); strcpy(&addr[len], No);
int len1 = strlen(addr); strcpy(&addr[len1], "号");
int len3 = strlen(addr); addr[len3] = '\0'; return addr; } char* transfer(int num){ int a = num%10; int b = num/10; char *str = (char*)malloc(sizeof(char)*2); str[0] = a+'0'; str[1] = b+'0'; str[2] = '\0'; return str; } char* TelGen() { char num[10][4] = {"135", "136", "137", "139", "151", "158", "155", "159", "173", "177"}; char numbody1[10][4] = {"123", "666", "345", "176", "124", "342", "342", "453", "333", "888"}; char numbody2[10][6] = {"33345", "54555", "34545", "66456", "77777", "11781", "08704", "57855", "37842", "56798"}; int ran1 = rand() % 10; int ran2 = rand() % 10; int ran3 = rand() % 10; char* Tell = (char*)malloc(sizeof(char) * 12); strcpy(&Tell[0], num[ran1]); strcpy(&Tell[3], numbody1[ran2]); strcpy(&Tell[6], numbody2[ran3]); return Tell; } double basicWageGen() { int wage1 = (rand() % 3) * 1000 + 3000; double wage2 = (rand() % 30) * 1.87 + 600; double wageTotal = wage1 + wage2; return wageTotal; } double alloGen() { double allo = (rand() % 20) * 1.87 + 456; return allo; } double taxGen(int totalWage) { double tax = 0; if (totalWage <= 5000) { tax = 0; } else { tax = totalWage * 0.03; } return tax; } int main() { for (int i = 10000; i < 10300; i++) { Teacher teacher;
teacher.teaNo = i; teacher.teaName = nameGen(); teacher.teaSex = sexGen(); teacher.workUnitName = "航天城第四小学"; teacher.address = addrGen(); teacher.telNo = TelGen(); teacher.basicWage = basicWageGen(); teacher.allowance = alloGen(); teacher.tax = taxGen(teacher.basicWage + teacher.allowance); FILE* fp = fopen(TEADIR, "a"); if (fp == NULL) { printf("打开文件失败,请重新确认路径!\n"); } fprintf(fp, "%d %s %s %s %s %s %.2f元 %.2f元 %.2f元\n", teacher.teaNo, teacher.teaName, teacher.teaSex, teacher.workUnitName, teacher.address, teacher.telNo, teacher.basicWage, teacher.allowance, teacher.tax); } return 0; }
|