```
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct COURSE
{
char number[20];//课程编号
char name[20];//课程名
char style[20];//课程类型
int time[2];//授课学时,上机学时
int score;//学分
int n;//开课学期
}course[100];
int N=0;
void Input_Course()
{
system(“cls”);
printf(“请输入输入课程编号\n”);
scanf("%s",&course[N].number);
printf(“请输入输入课程名\n”);
scanf("%s",&course[N].name);
printf(“请输入输入课程类型\n”);
scanf("%s",&course[N].style);
printf(“请输入输入课程授课学时\n”);
scanf("%d",&course[N].time[0]);
printf(“请输入输入课程实验或上机学时\n”);
scanf("%d",&course[N].time[1]);
printf(“请输入输入课程学分\n”);
scanf("%d",&course[N].score);
printf(“请输入输入课程开课学期\n”);
scanf("%d",&course[N].n);
N++;
printf(“新增课程成功!\n”);
system(“pause”);
}
int Menu()
{
int n;
system(“cls”);
printf(“1:课程信息录入\n”);
printf(“2:课程信息浏览\n”);
printf(“3:按课程名排序\n”);
printf(“4:按课程名查询\n”);
printf(“0:退出\n”);
printf(“请选择编号:”);
scanf("%d",&n);
while(n<0||n>4)
{
printf(“输入错误,请重新输入!\n”);
scanf("%d",&n);
}
return n;
}
void Show_Iofo()
{
int i;
system(“cls”);
if(0==N)
{
printf(“无课程信息!\n”);
}
else
{
printf("%-10s%-20s%-10s%-10s%-16s%-10s%-4s\n",“编号”,“课程名”,“类型”,“授课学时”,“上机或实验学时”,“学分”,“学期”);
for(i=0;i<N;i++)
{
printf("%-10s%-20s%-10s%-10d%-16d%-10d%-4d\n",course[i].number,course[i].name,course[i].style,course[i].time[0],course[i].time[1],course[i].score,course[i].n);
}
}
system(“pause”);
}
void Sort_Name()
{
struct COURSE temp;
int i,j;
for(i=0;i<N;i++)
{
for(j=i+1;j<N;j++)
{
if( strcmp(course[i].name,course[j].name)>0 )
{
temp=course[j];
course[j]=course[i];
course[i]=temp;
}
}
}
}
void Serach_Name()
{
int i;
char temp[20];
system(“cls”);
printf(“请输入要查询的课程名:\n”);
scanf("%s",temp);
printf("%-10s%-20s%-10s%-10s%-16s%-10s%-4s\n",“编号”,“课程名”,“类型”,“授课学时”,“上机或实验学时”,“学分”,“学期”);
for(i=0;i<N;i++)
{
if(!strcmp(temp,course[i].name))
{
printf("%-10s%-20s%-10s%-10d%-16d%-10d%-4d\n",course[i].number,course[i].name,course[i].style,course[i].time[0],course[i].time[1],course[i].score,course[i].n);
}
}
system(“pause”);
}
int main()
{
int n;
do
{
n=Menu();
switch(n)
{
case 1:
Input_Course();
break;
case 2:
Show_Iofo();
break;
case 3:
Sort_Name();
Show_Iofo();
break;
case 4:
Serach_Name();
break;
}
}while(n!=0);
return 0;
}