📄 复件 wu项.c
字号:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<windows.h>
#include<time.h>
void wenttoxy( int x, int y);
void gotstring(char str[],int maxlen);
void add();
int save(int counts);
void del();
void OrderBySno(int k);
void OrderByTotscore(int k);
void SearchBySno();
void addcaidan();
void PrintInfo(struct student s[],int counts,int page);
void Search_Stu_Info();
void Main_Menu();
/**********************************************************************************************/
/* 定义结构体 */
/**********************************************************************************************/
struct student
{
char sno[4];
char name[21];
short int age;
double score[5];
double totscore;
}stu[100];
/*
stu[100]={{"000","wu",12,{15,89,85,96,45}},
{"001","k",15,{58,96,85,87,46}},
{"002","b",23,{89,56,92,45,19}},
{"003","jko",19,{12,85,75,95,49}},
{"004","k",15,{8,96,49,87,46}},
{"005","k",15,{58,96,49,87,46}},
{"006","k",15,{58,9,49,87,46}},
{"007","jlop",15,{58,96,49,87,4}},
{"008","k",15,{58,96,49,8,46}},
{"009","milo",15,{58,96,49,87,46}},
{"010","k",15,{58,96,4,87,46}},
{"011","lkjh",15,{5,9,4,87,46}},
{"012","fhj",15,{5,95,49,8,46}},
{"013","ghn",15,{58,90,49,82,46}},
{"014","lou",15,{58,93,29,87,46}},
{"015","cvbn",15,{58,99,49,80,46}},
{"016","nmvb",15,{58,96,60,87,46}},
{"017","dfg",15,{58,96,49,88,46}},
{"018","cdvb",15,{58,91,49,87,46}},
{"019","klop",15,{58,93,59,87,46}},
{"020","vbc",15,{58,64,49,80,46}},
{"021","xcv",15,{58,96,9,83,46}},
};
*/
int counts;int page=1;int fsave;
fsave=0;
counts=0;//定义学生纪录counts为全局变量
/******************************时间函数**********************************************************/
void nowtime()
{ struct tm *now;
time_t tval;
tval = time(NULL);
now = localtime(&tval);
wenttoxy(30,24);
printf(" Now Time: %4d--%d --%02d %d:%02d:%02d\n",
now->tm_year+1900,now->tm_mon+1,now->tm_mday,
now->tm_hour,now->tm_min,now->tm_sec);
wenttoxy(15,18);
}
/**********************************************************************************************
光标移动函数
*********************************************************************************************/
void wenttoxy(int x, int y)
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
/***********************************************************************************************
输入字符串函数
参数maxlen表示最大的字符串输入长度
str[]表示字符串
***********************************************************************************************/
void gotstring(char str[],int maxlen)
{
int i;char ch;i=0;
while(1)
{
ch=getch();
if(ch==-32)
getch();
else if(ch==8)
{
if(i>0)
{ printf("\b \b");
i--;
}
}
else if(ch==13)
{
str[i]='\0';break;//回车键时退出
}
else if(ch==27)
ch=getch();
else if( i<=maxlen && !isspace(ch) || ch==32)//限制输入的长度
{
str[i]=ch;
printf("%c",str[i]);
i++;
}
}
}
/*********************************************************************************************
密码输入函数
**********************************************************************************************/
void gotpassward(char str[],int maxlen)
{
int i;char ch;i=0;
while(1)
{
ch=getch();
if(ch==-32)
getch();
else if(ch==8)
{
if(i>0)
{ printf("\b \b");
i--;
}
}
else if(ch==13)
{
str[i]='\0';break;//回车键时退出
}
else if(ch==27)
ch=getch();
else if( i<=maxlen && !isspace(ch) || ch==32)//限制输入的长度
{
str[i]=ch;
printf("*");
i++;
}
}
}
/*********************************************************************************************
学号自动生成
sno是学号
counts是学生记录条数
*********************************************************************************************/
int MakeSno(char *sno,int counts)//添加学号
{
char temp[5];
itoa(counts+1001,temp,10);
strcpy(sno,&temp[1]);
wenttoxy(34,3);
printf("%s",sno);
return counts;
}
/********************************************************************************************
去除名字的左右空格
允许用户输入姓名的同时左右两边有空格,但是可以删除
*********************************************************************************************/
void name_kongge(char name[])//去名字的左右空格
{
int m,i,j,k;k=0;
j=strlen(name);
m=j-1;
do
{
if(name[m]==' ') //去右空格
name[m]='\0';
m--;
}
while(name[m+1]==' ');
i=0;
do
{
if(name[i]==' ') //去左空格
{
{
k++;
}
i++;
}
else break;
}
while(name[i]==' ') ;
strcpy(name,&name[k]);
}
void UserNameVerification(char name[27]) //姓名验证函数
{ int i;int n;int j ;
do
{ j=0;
wenttoxy(29,4);
gotstring(name,27);//输入姓名
name_kongge(name);//去除姓名的左右空格
wenttoxy(29,4);printf(" ");
wenttoxy(29,4); printf("%s",name);
n=strlen(name);
if(n>20) //判断姓名的长度是否超过20
{
wenttoxy(5,18);
wenttoxy(5,18); printf(" ");
wenttoxy(5,18); printf("the name over lenth of 20");
}
else
{
for(i=0;name[i]!=0;i++)
{//验证是否为非法字符
if(!(('a'<=name[i] && name[i]<='z') || ('A'<= name[i] && name[i]<='Z') || name[i]==' '))
{j=1; break;}
}
if(j) {wenttoxy(5,18); printf(" ");
wenttoxy(5,18); printf("the Name illegal");}
else
{
if(j==0)
{
wenttoxy(29,4);//姓名正确时将其输出
printf("%s",name);
wenttoxy(5,18); printf(" ");
break;
}
}
}
}
while(1);
}
void SearchNameVerification(char name[27]) //姓名验证函数
{ int i;int n;int j ;
do
{ j=0;
wenttoxy(39,10);printf(" ");
wenttoxy(39,10); gotstring(name,27);//输入姓名
name_kongge(name);//去除姓名的左右空格
n=strlen(name);
if(n>20) //判断姓名的长度是否超过20
{
wenttoxy(5,18);
wenttoxy(5,18); printf(" ");
wenttoxy(5,18); printf("the name over lenth of 20");
}
else
{
for(i=0;name[i]!=0;i++)
{//验证是否为非法字符
if(!(('a'<=name[i] && name[i]<='z') || ('A'<= name[i] && name[i]<='Z') || name[i]==' '))
{j=1; break;}
}
if(j) {wenttoxy(5,18); printf(" ");
wenttoxy(5,18); printf("the Name illegal");}
else
{
if(j==0)
{
wenttoxy(34,4);printf(" ");
wenttoxy(34,4);//姓名正确时将其输出
printf("%s",name);
wenttoxy(5,18); printf(" ");
break;
}
}
}
}
while(1);
}
void NameVerification(char name[27]) //姓名验证函数
{ int i;int n;int j;int k;k=0;
do
{ j=0;
wenttoxy(34,4);printf(" ");
wenttoxy(34,4); gotstring(name,27);//输入姓名
name_kongge(name);//去除姓名的左右空格
n=strlen(name);
if(n==0) //判断姓名是否为空
{
wenttoxy(5,18);
printf("the name is empty,any key to continue");
getch();
}
else
{
if(n>20) //判断姓名的长度是否超过20
{
wenttoxy(5,18);
wenttoxy(5,18); printf(" ");
wenttoxy(5,18); printf("the name over lenth of 20");
}
else
{
for(i=0;name[i]!=0;i++)
{//验证是否为非法字符
if(!(('a'<=name[i] && name[i]<='z') || ('A'<= name[i] && name[i]<='Z') || name[i]==' '))
{j=1; break;}
}
if(j) {wenttoxy(5,18); printf(" ");
wenttoxy(5,18); printf("the Name illegal");}
else
{
if(j==0)
{
wenttoxy(34,4);printf(" ");
wenttoxy(34,4);//姓名正确时将其输出
printf("%s",name);
wenttoxy(5,18); printf(" ");
break;
}
}
}
}
}
while(1);
}
/**********************************************************************************************
登入函数
输入用户的名字和密码
**********************************************************************************************/
void Enter( )
{
int j;
char passward[6];
char Admin[27];
wenttoxy(15,4);
printf("Enter Admin: " );
wenttoxy(15,6);
printf("Enter Password: ");
for(j=0;j<=2;j++)
{
UserNameVerification(Admin);
wenttoxy(29,6);
gotpassward(passward,6);
if((strcmp("wuqianliang",Admin) == 0) && (strcmp("123456",passward) == 0))
{ printf("\n You have succeeded register \n ");break;}
else
printf("\n The user and/or the password is invalid\n");
}
if(j==3)
{
printf("You only have three opportunities,so sorry now you must exit!! ");getch();exit(0);
}
}
/**********************************************************************************************
去除年龄的左右空格
**********************************************************************************************/
void age_kongge(char a[]) //去除年龄的左右空格
{
int m,i,j,k;k=0;
wenttoxy(34,5);
gotstring(a,7);
wenttoxy(34,5);
printf(" ");
j=strlen(a);
m=j-1;
do
{
if(a[m]==' ') //去除右空格
{ a[m]='\0';}
m--;
}
while(a[m]==' ');
i=0;
do
{
if(a[i]==' ') //去除左空格
{k++;}
i++;
}
while(a[i]==' ');
strcpy(a,&a[k]);
wenttoxy(34,5);printf(" ");
wenttoxy(34,5);printf("%s",a);
}
/***********************************************************************************************
年龄的验证
参数:age用户的年龄是整型变量
a[]为用户年龄的字符型变量用来做输入的,便于验证
***********************************************************************************************/
void AgeVerification(short int *age,char a[]) //年龄验证函数
{ int i;int j;
do
{ j=0;
age_kongge(a);getch();
for(i=0;a[i]!='\0';i++)
{
if('0'>a[i] || a[i]>'9')
{
j=1;//判断非法字符
break;
}
}
if(j)
{
wenttoxy(5,18);
printf("Age is not the correct character\n");
}
else if(strlen(a)>2)//判断年龄长度
{
wenttoxy(5,18);
printf("Age is over the lenth of 2\n");
}
else if((atoi(a)<7 || atoi(a)>50))//判断年龄范围
{
wenttoxy(5,18);
printf("Age is not between 7 and 50 \n");
wenttoxy(5,18);getch();
printf(" ");
}
else
{
if(7<=atoi(a) && atoi(a)<=50)
{ *age=atoi(a); //输出年龄
wenttoxy(34,5);
printf("%d",*age);
printf(" ");
break;
}
}
}
while(1);
}
/***********************************************************************************************
去除分数的左右空格
参数:s[]为字符型分数变量
l为众坐标的改变值,用于光标定位
***********************************************************************************************/
void Score_kongge(char s[],int l)//去除分数的左右空格
{
int m,i,j,k;k=0;
wenttoxy(39,5+l);
printf(" ");
wenttoxy(39,5+l);
gotstring(s,7);
j=strlen(s);
m=j-1;
do
{
if(s[m]==' ')
{ s[m]='\0';}
m--;
}
while(s[m]==' ');
i=0;
do
{
if(s[i]==' ')
{k++;}
i++;
}
while(s[i]==' ');
strcpy(s,&s[k]);
wenttoxy(39,5+l);
printf("%s",s);
}
/***********************************************************************************************
分数的验证函数
参数:*score为学生分数的指针变量
s[]为分数的字符型变量,用于输入便于验证
l为纵坐标的变化量用于光标定位
************************************************************************************************/
void ScoreVerifies(double *score,char s[],int l)//分数的验证
{ int i,j,k,n;i=0;
do
{
Score_kongge(s,l);
n=strlen(s);
k=0;j=0;
if(n>4) //分数字符串的长度判断
{ wenttoxy(5,18);
printf(" ");
wenttoxy(5,18);
printf("The length of score more than four results");getch();
}
else
{
if(n<=4)
for(i=0;s[i]!='\0';i++)
{
if(s[i]=='.') j++; //求小数点的个数
else
{
if(!(s[i]>='0' && s[i]<='9')&& s[i]!='.') k=1;//判断是否为非法字符
}
}
if(k==1) {
wenttoxy(5,18);printf(" ");
wenttoxy(5,18);printf("Score is illegal alphabetic string");
}//小数点是否为1个
{
if(j>=2) //小数点大于1个
{
wenttoxy(5,18);printf(" ");
wenttoxy(5,18); printf("The number of decimal places for more than one, the error");
}
else //小数点为一个时,小数点的位置在首位和末位是错误的
{
if(j==1 && (s[0]=='.'||s[n-1]=='.') )
{ wenttoxy(5,18);printf(" ");
wenttoxy(5,18);printf("The radix point location has been wrong\n");
}
else
{
if(j==1 && s[n-2]=='.'&& (s[n-1]!='0' && s[n-1]!='5'))//小数点正确但是小数部分不对
{
wenttoxy(5,18);printf(" ");
wenttoxy(5,18);printf("The decimal part is not 0 or 5");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -