📄 cyj.cpp
字号:
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#include<math.h>
#define LEN sizeof(struct student)
struct student
{
long num;
char name[20];
float Chinese;
float Math;
float English;
struct student *next;
};
int n;
struct student *creat(void)
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
printf("请输入学号:");
scanf("%ld",&p1->num);
while(p1->num<=0)
{
printf("输入的学号应大于0,请重输:\n");
getchar();
scanf("%ld",&p1->num);
}
printf("请输入姓名:");
scanf("%s",p1->name);
printf("请输入语文成绩:");
scanf("%f",&p1->Chinese);
while(p1->Chinese>100||p1->Chinese<0)
{
printf("请输入0~100的数字\n");
printf("重输语文成绩:");
scanf("%f",&p1->Chinese);
}
printf("请输入数学成绩:");
scanf("%f",&p1->Math);
while(p1->Math>100||p1->Math<0)
{
printf("请输入0~100的数字\n");
printf("重输数学成绩:");
scanf("%f\n",&p1->Math);
}
printf("请输入英语成绩:");
scanf("%f",&p1->English);
while(p1->English>100||p1->English<0)
{
printf("请输入0~100的数字\n");
printf("重输英语成绩:");
scanf("%f",&p1->English);
}
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
printf("请输入学生学号:");
printf("请输入-1退出成绩输入");
scanf("%ld",&p1->num);
if(p1->num==-1)break;
while(p1->num<=0)
{
printf("输入的学号应大于0,请重输:\n");
getchar();
scanf("%ld",&p1->num);
}
printf("请输入姓名:");
scanf("%s",p1->name);
scanf("%f",&p1->Chinese);
while(p1->Chinese>100||p1->Chinese<0)
{
printf("请输入0~100的数字\n");
getchar();
printf("重输语文成绩:");
scanf("%f",&p1->Chinese);
}
printf("请输入数学成绩:");
scanf("%f",&p1->Math);
while(p1->Math>100||p1->Math<0)
{
printf("请输入0~100的数字\n");
getchar();
printf("重输数学成绩:");
scanf("%f",&p1->Math);
}
printf("请输入英语成绩:");
scanf("%f",&p1->English);
while(p1->English>100||p1->English<0)
{
printf("请输入0~100的数字\n");
getchar();
printf("重输英语成绩:");
scanf("%f",&p1->English);
}
}
p2->next=NULL;
return(head);
}
/*查询成绩*/
void xin(struct student *head,char name[20])
{struct student *p1;
p1=head;
if(head!=NULL)
while(p1!=NULL)
{if(strcmp(p1->name,name)!=0)
{p1=p1->next;
}
else
{printf("\t_______________________________________\n");
printf("\t| 学号 |姓名 |语文 |数学 |英语 |\n");
printf("\t_______________________________________\n");
printf("\t| %-ld |%-6.2s|%-7.1f|%-7.1f|%-7.1f|\n",p1->num,p1->name,p1->Chinese,p1->Math,p1->English);break;}}
printf("\t_______________________________________\n");
if(p1==NULL) printf("\t%s 不存在",name);
}
/*输出*/
void print(struct student *head)
{
struct student *p;
printf("\n\tNOW These %d records are:\n",n);
printf("\t_______________________________________\n");
printf("\t| 学号 |姓名 |语文 |数学 |英语 |\n");
printf("\t_______________________________________\n");
p=head;
if(head!=NULL)
do
{
printf("\t| %-ld |%-6.2s|%-7.1f|%-7.1f|%-7.1f|\n",p->num,p->name,p->Chinese,p->Math,p->English);
printf("\t_______________________________________\n");
p=p->next;
}while(p!=NULL);
return;
}
/*按学号排序*/
struct student *xuehao(struct student *head)
{
struct student *p2,*p1;
char n[20];
long k;
float m;
float yingyu;
float y;
p1=head;
while(p1!=NULL)
{
p2=p1->next;
while(p2!=NULL)
{
if(p1->num>p2->num)
{
k=p1->num;p1->num=p2->num;p2->num=k;m=p1->Math;p1->Math=p2->Math;p2->Math=m;
strcpy(n,p1->name);strcpy(p1->name,p2->name);strcpy(p2->name,n);
y=p1->Chinese;p1->Chinese=p2->Chinese;p2->Chinese=y;
yingyu=p1->English;p1->English=p2->English;p2->English=yingyu;
}
p2=p2->next;
}
p1=p1->next;
}
return(head);
}
/*按英语排序*/
struct student *yingyu(struct student *head)
{
struct student *p2,*p1;
char n[20];
float k;
float y;
long s;
float m;
p1=head;
while(p1!=NULL)
{
p2=p1->next;
while(p2!=NULL)
{
if(p1->English>p2->English)
{
k=p1->English;p1->English=p2->English;p2->English=k;
m=p1->Math;p1->Math=p2->Math;p2->Math=m;
strcpy(n,p1->name);strcpy(p1->name,p2->name);strcpy(p2->name,n);
y=p1->Chinese;p1->Chinese=p2->Chinese;p2->Chinese=y;
s=p1->num;p1->num=p2->num;p2->num=s;
}
p2=p2->next;
}
p1=p1->next;
}
return(head);
}
/*按数学排序*/
struct student *Math(struct student *head)
{
struct student *p2,*p1;
char n[20];
float y;
long s;
float m;
float k;
p1=head;
while(p1!=NULL)
{
p2=p1->next;
while(p2!=NULL)
{
if(p1->Math>p2->Math)
{k=p1->Math;p1->Math=p2->Math;p2->Math=k;
m=p1->English;p1->English=p2->English;p2->English=m;
strcpy(n,p1->name);strcpy(p1->name,p2->name);strcpy(p2->name,n);
y=p1->Chinese;p1->Chinese=p2->Chinese;p2->Chinese=y;
s=p1->num;p1->num=p2->num;p2->num=s;}
p2=p2->next;
}
p1=p1->next;
}
return(head);
}
/*按语文排序*/
struct student *Chinese(struct student *head)
{
struct student *p2,*p1;
char n[20];
float y;
long s;
float m;
float k;
p1=head;
while(p1!=NULL)
{
p2=p1->next;
while(p2!=NULL)
{
if(p1->Chinese>p2->Chinese)
{k=p1->Chinese;p1->Chinese=p2->Chinese;p2->Chinese=k;
m=p1->English;p1->English=p2->English;p2->English=m;
strcpy(n,p1->name);strcpy(p1->name,p2->name);strcpy(p2->name,n);
y=p1->Math;p1->Math=p2->Math;p2->Math=y;
s=p1->num;p1->num=p2->num;p2->num=s;}
p2=p2->next;
}
p1=p1->next;
}
return(head);
}
/*彩票*/
void caipiao()
{int m,i,j,n,a[1000][7];
int rand(void);
printf("请输入你想购买的彩票组数:");
scanf("%d",&n);
printf("您的%d组彩票号码如下:\n",n);
{for(i=0;i<n;i++)
for(j=0;j<7;j++)
{m=rand()%50;
if(m>0&&m<=49)
a[i][j]=m;
else j--;}
}
for (i=0;i<n;i++)
{for(j=0;j<7;j++)
if(j!=6)
printf("%5d",a[i][j]);
else printf("\t+%d",a[i][6]);
printf("\n");
}
}
/*计算器*/
void jisuanqi()
{int result,s;
int chengfa();
int jiafa();
int kaifang();
printf("欢迎使用计算器 1.加法\t2.乘法\t3.开方\n");
printf("\t请选择你要的操作:");
scanf("%d",&s);
while(s>3||s<0)
{printf("\t请输入1~~3的数字:");
scanf("%d",&s);}
switch(s)
{case 1:
result=jiafa();printf("%d",result);break;
case 2:
result=chengfa();printf("%d",result);break;
case 3:
result=kaifang();printf("%d",result);break;
}}
/*作加法*/
int jiafa()
{int a[20];
int i,n;
int s=0;
printf("请输入n个要运用加法的数字\n");
scanf("%d",&n);
printf("输入数字:每个数字间用空格!\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
s=s+a[i];
return(s);
}
/*作乘法*/
int chengfa()
{int a[20];
int i,n;
int s=1;
printf("请输入n个要运用乘法的数字个数:");
scanf("%d",&n);
printf("输入数字:每个数字间用空格!\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
s=s*a[i];
return(s);
}
/*作开方*/
int kaifang()
{int s;
int n;
printf("输入一个数字:\n");
scanf("%d",&n);
s=sqrt(n);
return(s);
}
/*主函数*/
void main()
{
struct student *head;
int i,j,m,p;
char name[20];
j=1;
while(j)
{printf("\n");
for(i=0;i<40;i++)
printf("★");
printf("\t\t\t 欢迎使用学生成绩管理系统系统\n");
printf("\t\t\t 开发者:项和平 学号2\n");
printf("\n\n");
printf("\t\t 1.成绩输入 2.计算器 3.六合彩 \n");
printf("\t\t 4.成绩列表 5.成绩排序 6.成绩查询 \n");
printf("\t\t 7.退出系统 \n");
printf("\n");
for(i=0;i<40;i++)
printf("★");
printf("\n");
printf("\t\t请选择你要的操作(1~7):");
scanf("%d",&m);
while(m>7||m<0)
{printf("\t请输入1~7的数字:");
scanf("%d",&m);}
switch(m)
{case 1:
head=creat();break;
case 2:jisuanqi();break;
case 3:caipiao();break;
case 4:
printf("\t成绩列表:");
print(head);break;
case 5:
printf("\t1.学号 \t2.数学 \t3.英语 \t4.语文 \n");
printf("\t请输入排序方式(输入1~4数字):");
scanf("%d",&p);
if(p<1||p>4)
{printf("\t请输入1~4的数字:");
scanf("%d",&p);}
switch(p)
{case 1:xuehao(head);
print(head);break;
case 2:Math(head);
print(head);break;
case 3:yingyu(head);
print(head);break;
case 4:Chinese(head);
print(head);break;
}break;
case 6:
printf("\t请输入要查询的学生的名字:");
scanf("%s",name);
xin(head,name);break;
case 7:
printf("\t谢谢使用本人的管理系统!");
printf("本系统由计算机023-项和平编写.");
getchar();
exit(0);
break;}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -