void input() { printf("---------教师信息录入功能---------\n\n"); int c; while (1) { printf("第%d个老师的信息\n\n", i + 1); printf("请输入姓名(输入0结束录入):"); scanf("%s", t[i].name); if (t[i].name[0] == '0') break; printf("请输入性别(M为男性,F为女性):"); repeat1:scanf(" %c", &t[i].sex); if (t[i].sex != 'M' && t[i].sex != 'F') //性别判断容错,用字符比较 { printf("输入错误,请重新输入\n"); goto repeat1; } printf("请输入职称:"); scanf("%s", t[i].position); printf("请输入工号:"); scanf("%d", &t[i].employee_number); printf("请输入第一门课程名称:"); scanf("%s", t[i].course_one.course_name); printf("请输入第一门课程开课学期(例:2019-2020学年第二学期):"); scanf("%s", t[i].course_one.term); printf("请输入第一门课程性质(必修或选修):"); repeat2:scanf("%s", t[i].course_one.nature); if (strcmp(t[i].course_one.nature, "必修") != 0 && strcmp(t[i].course_one.nature, "选修") != 0) //课程性质判断容错,用字符串比较 { printf("输入错误,请重新输入\n"); goto repeat2; } printf("请输入第二门课程名称:"); scanf("%s", t[i].course_two.course_name); printf("请输入第二门课程开课学期(例:2019-2020学年第二学期):"); scanf("%s", t[i].course_two.term); printf("请输入第二门课程性质(必修或选修):"); repeat3:scanf("%s", t[i].course_two.nature); if (strcmp(t[i].course_two.nature, "必修") != 0 && strcmp(t[i].course_two.nature, "选修") != 0) { printf("输入错误,请重新输入\n"); goto repeat3; } printf("请输入课程综合评分:"); scanf("%lf",&t[i].score); printf("\n您输入的信息为:"); printf("\n%s %c %s %d %s %s %s %s %s %s %.2f\n\n", t[i].name, t[i].sex, t[i].position, t[i].employee_number, t[i].course_one.course_name, t[i].course_one.term, t[i].course_one.nature, t[i].course_two.course_name, &t[i].course_two.term, t[i].course_two.nature,t[i].score); printf("----------------------------------\n\n"); i++; } printf("\n----------------------------------\n\n"); printf("请选择操作!\n"); printf("\n1.返回主界面\n"); //优化返回 repeat:scanf("%d", &c); if (c == 1) { system("cls"); main(); } else { printf("输入错误,请重新输入!\n"); goto repeat; } }error: expected unqualified-id before ‘{’ token
时间: 2024-03-29 13:39:26 浏览: 52
这是一段 C 语言代码,实现了教师信息录入功能。用户可以输入教师的姓名、性别、职称、工号、两门课程的名称、开课学期、性质以及课程综合评分等信息。代码中还包含了容错处理,例如性别和课程性质输入错误时可以重新输入。最后,用户可以选择返回主界面或重新输入操作。不过,最后一行代码中的错误提示是不完整的,应该是在哪个文件的哪一行出现了错误。
相关问题
人事管理系统 C语言,人事管理系统----C语言设计
人事管理系统是一种基于计算机技术的人力资源管理工具,它可以帮助企业或组织有效地管理员工信息、薪酬福利、招聘培训、绩效考核、职业发展等方面的工作。下面是一个简单的人事管理系统的C语言设计思路:
1.定义员工信息结构体
```
typedef struct Employee{
char name[20]; //员工姓名
int age; //员工年龄
char gender[10]; //员工性别
char department[20]; //员工部门
char position[20]; //员工职位
int salary; //员工薪资
struct Employee *next; //链表指针
}Employee;
```
2.员工信息录入
```
Employee *input(Employee *head){
Employee *p, *q;
char flag;
p = (Employee*)malloc(sizeof(Employee));
printf("请输入员工姓名:");
scanf("%s", p->name);
printf("请输入员工年龄:");
scanf("%d", &p->age);
printf("请输入员工性别:");
scanf("%s", p->gender);
printf("请输入员工部门:");
scanf("%s", p->department);
printf("请输入员工职位:");
scanf("%s", p->position);
printf("请输入员工薪资:");
scanf("%d", &p->salary);
p->next = NULL;
if(head == NULL){
head = p;
}else{
q = head;
while(q->next != NULL){
q = q->next;
}
q->next = p;
}
printf("是否继续录入员工信息?(y/n)");
scanf("%s", &flag);
if(flag == 'y' || flag == 'Y'){
head = input(head);
}
return head;
}
```
3.员工信息查询
```
void find(Employee *head){
Employee *p;
char name[20];
int flag = 0;
printf("请输入要查询的员工姓名:");
scanf("%s", name);
p = head;
while(p != NULL){
if(strcmp(p->name, name) == 0){
printf("姓名:%s\n年龄:%d\n性别:%s\n部门:%s\n职位:%s\n薪资:%d\n", p->name, p->age, p->gender, p->department, p->position, p->salary);
flag = 1;
break;
}
p = p->next;
}
if(flag == 0){
printf("未找到该员工信息!\n");
}
}
```
4.员工信息修改
```
void modify(Employee *head){
Employee *p;
char name[20];
int flag = 0;
printf("请输入要修改的员工姓名:");
scanf("%s", name);
p = head;
while(p != NULL){
if(strcmp(p->name, name) == 0){
printf("请输入员工新的薪资:");
scanf("%d", &p->salary);
printf("员工信息修改成功!\n");
flag = 1;
break;
}
p = p->next;
}
if(flag == 0){
printf("未找到该员工信息!\n");
}
}
```
5.员工信息删除
```
Employee *del(Employee *head){
Employee *p, *q;
char name[20];
int flag = 0;
printf("请输入要删除的员工姓名:");
scanf("%s", name);
p = head;
while(p != NULL){
if(strcmp(p->name, name) == 0){
if(p == head){
head = p->next;
}else{
q->next = p->next;
}
printf("员工信息删除成功!\n");
flag = 1;
break;
}
q = p;
p = p->next;
}
if(flag == 0){
printf("未找到该员工信息!\n");
}
return head;
}
```
以上是一个简单的人事管理系统的C语言设计思路,你可以根据自己的需求进行修改和完善。
用C语言写一个有1---学生信息录入2------学生信息浏览3---学生成绩排4---学生信息查询 5------学生信息修改 6---学生信息统计7---学生投票功能的代码
以下是一个简单的学生信息管理系统的C语言代码,包括1-学生信息录入、2-学生信息浏览、3-学生成绩排名、4-学生信息查询、5-学生信息修改、6-学生信息统计和7-学生投票功能。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT_NUM 100 // 最大学生数量
#define MAX_NAME_LEN 20 // 最大姓名长度
#define MAX_SUBJECT_NUM 5 // 最大科目数量
// 学生结构体
struct student {
char name[MAX_NAME_LEN]; // 姓名
int id; // 学号
int score[MAX_SUBJECT_NUM]; // 科目成绩
int total_score; // 总成绩
float average_score; // 平均成绩
};
struct student students[MAX_STUDENT_NUM]; // 学生数组
int student_num = 0; // 学生数量
// 函数声明
void input_student_info();
void browse_student_info();
void rank_student_score();
void search_student_info();
void modify_student_info();
void statistics_student_info();
void vote_student();
int main() {
int choice;
while (1) {
printf("|*菜单*|\n");
printf("1-录入/插入学生信息\n");
printf("2-浏览学生信息\n");
printf("3-查询学生信息\n");
printf("4-删除学生信息\n");
printf("5-修改学生信息\n");
printf("6-学生信息统计\n");
printf("7-学生投票功能\n");
printf("0-退出系统\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
input_student_info();
break;
case 2:
browse_student_info();
break;
case 3:
search_student_info();
break;
case 4:
// TODO: 删除学生信息
break;
case 5:
modify_student_info();
break;
case 6:
statistics_student_info();
break;
case 7:
vote_student();
break;
case 0:
printf("谢谢使用,再见!\n");
exit(0);
default:
printf("输入有误,请重新输入!\n");
break;
}
}
return 0;
}
// 录入学生信息
void input_student_info() {
if (student_num >= MAX_STUDENT_NUM) {
printf("学生数量已达到上限,无法继续录入!\n");
return;
}
printf("请输入学生姓名:");
scanf("%s", students[student_num].name);
printf("请输入学生学号:");
scanf("%d", &students[student_num].id);
printf("请输入学生各科成绩:\n");
for (int i = 0; i < MAX_SUBJECT_NUM; i++) {
printf("请输入第%d科成绩:", i + 1);
scanf("%d", &students[student_num].score[i]);
students[student_num].total_score += students[student_num].score[i];
}
students[student_num].average_score = (float)students[student_num].total_score / MAX_SUBJECT_NUM;
student_num++;
printf("学生信息录入成功!\n");
}
// 浏览学生信息
void browse_student_info() {
if (student_num == 0) {
printf("暂无学生信息!\n");
return;
}
printf("学生姓名\t学号\t科目1\t科目2\t科目3\t科目4\t科目5\t总成绩\t平均成绩\n");
for (int i = 0; i < student_num; i++) {
printf("%s\t\t%d\t", students[i].name, students[i].id);
for (int j = 0; j < MAX_SUBJECT_NUM; j++) {
printf("%d\t", students[i].score[j]);
}
printf("%d\t%.2f\n", students[i].total_score, students[i].average_score);
}
}
// 学生成绩排名
void rank_student_score() {
// TODO: 学生成绩排名
}
// 学生信息查询
void search_student_info() {
if (student_num == 0) {
printf("暂无学生信息!\n");
return;
}
int choice;
printf("请选择查询方式:\n");
printf("1-按姓名查询\n");
printf("2-按学号查询\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1: {
char name[MAX_NAME_LEN];
printf("请输入要查询的学生姓名:");
scanf("%s", name);
int found = 0;
for (int i = 0; i < student_num; i++) {
if (strcmp(students[i].name, name) == 0) {
printf("学生姓名\t学号\t科目1\t科目2\t科目3\t科目4\t科目5\t总成绩\t平均成绩\n");
printf("%s\t\t%d\t", students[i].name, students[i].id);
for (int j = 0; j < MAX_SUBJECT_NUM; j++) {
printf("%d\t", students[i].score[j]);
}
printf("%d\t%.2f\n", students[i].total_score, students[i].average_score);
found = 1;
break;
}
}
if (!found) {
printf("未找到该学生信息!\n");
}
break;
}
case 2: {
int id;
printf("请输入要查询的学生学号:");
scanf("%d", &id);
int found = 0;
for (int i = 0; i < student_num; i++) {
if (students[i].id == id) {
printf("学生姓名\t学号\t科目1\t科目2\t科目3\t科目4\t科目5\t总成绩\t平均成绩\n");
printf("%s\t\t%d\t", students[i].name, students[i].id);
for (int j = 0; j < MAX_SUBJECT_NUM; j++) {
printf("%d\t", students[i].score[j]);
}
printf("%d\t%.2f\n", students[i].total_score, students[i].average_score);
found = 1;
break;
}
}
if (!found) {
printf("未找到该学生信息!\n");
}
break;
}
default:
printf("输入有误,请重新输入!\n");
break;
}
}
// 学生信息修改
void modify_student_info() {
if (student_num == 0) {
printf("暂无学生信息!\n");
return;
}
int id;
printf("请输入要修改的学生学号:");
scanf("%d", &id);
int found = 0;
for (int i = 0; i < student_num; i++) {
if (students[i].id == id) {
printf("请输入学生姓名:");
scanf("%s", students[i].name);
printf("请输入学生各科成绩:\n");
for (int j = 0; j < MAX_SUBJECT_NUM; j++) {
printf("请输入第%d科成绩:", j + 1);
scanf("%d", &students[i].score[j]);
students[i].total_score += students[i].score[j];
}
students[i].average_score = (float)students[i].total_score / MAX_SUBJECT_NUM;
printf("学生信息修改成功!\n");
found = 1;
break;
}
}
if (!found) {
printf("未找到该学生信息!\n");
}
}
// 学生信息统计
void statistics_student_info() {
if (student_num == 0) {
printf("暂无学生信息!\n");
return;
}
int choice;
printf("请选择统计方式:\n");
printf("1-按总成绩排序\n");
printf("2-按平均成绩排序\n");
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1: {
// 按总成绩排序
for (int i = 0; i < student_num - 1; i++) {
for (int j = 0; j < student_num - i - 1; j++) {
if (students[j].total_score < students[j + 1].total_score) {
struct student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
printf("学生姓名\t学号\t科目1\t科目2\t科目3\t科目4\t科目5\t总成绩\t平均成绩\n");
for (int i = 0; i < student_num; i++) {
printf("%s\t\t%d\t", students[i].name, students[i].id);
for (int j = 0; j < MAX_SUBJECT_NUM; j++) {
printf("%d\t", students[i].score[j]);
}
printf("%d\t%.2f\n", students[i].total_score, students[i].average_score);
}
break;
}
case 2: {
// 按平均成绩排序
for (int i = 0; i < student_num - 1; i++) {
for (int j = 0; j < student_num - i - 1; j++) {
if (students[j].average_score < students[j + 1].average_score) {
struct student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
printf("学生姓名\t学号\t科目1\t科目2\t科目3\t科目4\t科目5\t总成绩\t平均成绩\n");
for (int i = 0; i < student_num; i++) {
printf("%s\t\t%d\t", students[i].name, students[i].id);
for (int j = 0; j < MAX_SUBJECT_NUM; j++) {
printf("%d\t", students[i].score[j]);
}
printf("%d\t%.2f\n", students[i].total_score, students[i].average_score);
}
break;
}
default:
printf("输入有误,请重新输入!\n");
break;
}
}
// 学生投票
void vote_student() {
if (student_num == 0) {
printf("暂无学生信息!\n");
return;
}
int id;
printf("请输入要投票的学生学号:");
scanf("%d", &id);
int found = 0;
for (int i = 0; i < student_num; i++) {
if (students[i].id == id) {
printf("您已成功为%s投票!\n", students[i].name);
found = 1;
break;
}
}
if (!found) {
printf("未找到该学生信息!\n");
}
}
```
阅读全文