首页 > 代码库 > c语言第12次作业

c语言第12次作业

1.

#include<stdio.h>
struct student
{
    char name[20];
    char num[20];
    char porject[20];
    double grade;
};

void main()
{
    int i;student str[3];
    for(i=0;i<3;i++)
    {
        printf("第%d个学生的信息是:\n",i+1);
        printf("姓名:");scanf("%s",str[i].name);
        printf("学号:");scanf("%s",str[i].num);
        printf("系别:");scanf("%s",str[i].porject);
        printf("成绩:");scanf("%lf",&str[i].grade);
    }
    for(i=0;i<3;i++)
    {
        printf("第%d个学生的信息是:\n",i+1);
        printf("姓名:%s\n",str[i].name);
        printf("学号:%s\n",str[i].num);
        printf("系别:%s\n",str[i].porject);
        printf("成绩:%lf\n",str[i].grade);
    }
}

2.

#include<stdio.h>
struct student
{
    char sno[10];
    char sname[20];
    int age;
}; 
int main()
{
    student class3[31];
    FILE *fp=fopen("d:\\input.txt","r");
    fscanf(fp,"%s%s%d",class3[0].sno,class3[0].sname,&class3[0].age);
    fclose(fp);
    fp=fopen("d:\\output.txt","w");
    printf("%s %s %d",class3[0].sno,class3[0].sname,class3[0].age);
    fclose(fp);    
    return 0;
}

3.

#include<stdio.h>
struct student{
    char sno[10];
    char sname[20];
    int age;    
};
student s1;
void addStudent()
{
    FILE *fp=fopen("d:\\student.txt","a+");
    printf("请输入学号:");
    scanf("%s",s1.sno);
    printf("请输入姓名:");
    scanf("%s",s1.sname);
    printf("请输入年龄:"); 
    scanf("%s",&s1.age);
    fprintf(fp,"\n%s %s %d",s1.sno,s1.sname,s1.age);
    printf("信息添加成功。\n");    
}
void queryStudent()
{
    printf("query");
}
void updateStudent()
{
    printf("update");
}
void deleteStudent()
{
    printf("delete");
}
void mainmenu()
{
    int choice;
    printf("学生管理系统\n");
    printf("1.添加学生信息\n");
    printf("2.查询学生信息\n");
    printf("3.修改学生信息\n");
    printf("4.删除学生信息\n");
    printf("请选择:");
    scanf("%d",&choice);
    switch(choice)
        {
        case 1:
        addStudent();
        break;
        case 2:
        queryStudent();
        break;
        case 3:
        updateStudent();
        break;
        case 4:
        deleteStudent();
        break;
        default:
        printf("输入有误,程序退出!");
        } 
}
int main()
{        
    mainmenu();
}

 

c语言第12次作业