?? xuesheng.txt
字號:
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct student
{
int num;
char name[20];
float score[3];
float ave;
};
int i=0;//全局變量 統計個數
void wo(struct student a[] ); //錄入函數
void shi(struct student a[]); //排序函數
void shui(struct student a[]); //插入函數
void del(struct student a[]); //刪除函數
void display(struct student a[]);//顯示函數
void main()
{
struct student stu[50];
int number;
do
{
printf("\n\t\t\t學員成績管理\n\n");
printf("\n☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
printf("\n\n請選擇功能\n0.退出\n1.錄入\n2.顯示\n3.排序\n4>插入\n5.刪除\n\n------------------\n");
scanf("%d",&number);
printf("\n------------------\n\n");
switch (number)
{
case 0:break;
case 1:wo(stu);break;
case 2:display(stu);break;
case 3:shi(stu);break;
case 4:shui(stu);break;
case 5:del(stu);break;
}
}while(number!=0);
printf("謝謝你已查尋完畢!下次再見!");
printf("\n");
}
void wo(struct student a[]) //錄入函數
{
int j;
char b;
float sum=0;
printf("請輸入學員信息\n");
do
{
printf("學號:");
scanf("%d",&a[i].num);
printf("姓名:");
scanf("%s",a[i].name);
printf("三門成績\n");
for(j=0;j<3;j++)
{
printf("成績%d:",j+1);
scanf("%f",&a[i].score[j]);
}
a[i].ave=(a[i].score[0]+a[i].score[1]+a[i].score[2])/3;
i++;
printf("是否繼續\n(Y/N)");
fflush(stdin);
scanf("%c",&b);
}while(b=='Y'||b=='y');
display(a);
}
void display(struct student a[]) //顯示函數
{
int k;
printf("學號\t姓名\t平均值\n");
for(k=0;k<i;k++)
{
printf("%d\t%s\t%.2f\n",a[k].num,a[k].name,a[k].ave);
}
}
void shi(struct student a[]) //排序函數
{
int j,k;
struct student temp;
for(k=0;k<i;k++)
{
for(j=0;j<i-k;j++)
{
if(a[j].ave<a[j+1].ave)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("排序后的學員信息如下\n");
display(a);
}
void shui(struct student a[]) //插入函數
{
int j,k;
struct student temp;
printf("學號:");
scanf("%d",&temp.num);
printf("姓名:");
scanf("%s",temp.name);
printf("三門成績\n");
for(j=0;j<3;j++)
{
printf("成績%d:",j+1);
scanf("%f",&temp.score[j]);
}
temp.ave=(temp.score[0]+temp.score[1]+temp.score[2])/3;
for(j=0;j<i;j++)
{
if(temp.ave>a[j].ave)
{
break;
}
}
for(k=i;k>j;k--)
{
a[k]=a[k-1];
}
i++;
a[j]=temp;
display(a);
}
void del(struct student a[]) //刪除函數
{
int k,j;
printf("請輸入要刪除的學號:");
scanf("%d",&k);
for(j=0;j<i;j++)
{
if(k==a[j].num)
{
break;
}
}
if(j<i)
{
for(k=j;k<i-1;k++)
{
a[j]=a[j+1];
}
i--;
printf("刪除后的學員信息\n");
display(a);
}
else
{
printf("沒有您要刪除的學員\n");
display(a);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -