学习C语言的一些疑问:
win32application与win32 console application区别何在?
一、结构体的使用:
struct student
{
char xuehao[11];
char xingming[21];
char gender[10];
char home[100];
char mingzu[21];
int age;
};
#define N 100
struct student stu [N];//将结构体student名字改为stu,且为结构体数组
结构体应用:stu[i].age
结构体数组实例:
/*****************
结构体数组
计算一个班学生四门课程平均分
************************/
#include <stdio.h>
typedef struct date
{
int year;
int month;
int day;
}DATE;
typedef struct student
{
long studentID;
char studentName[10];
char studentSex;
DATE birthday;
int score[4];
}STUDENT;
int main()
{
int i,j,sum[30];
STUDENT stu[30] = {{1001,"张三",'M',{1994,6,19},{72,32,89,41}},
{1002,"赵六",'F',{1998,6,19},{72,56,78,41}},
{1003,"王五",'M',{2004,6,19},{96,52,89,41}},
{1004,"李四",'F',{1689,6,19},{56,56,65,41}}
};
for(i=0;i<4;i++)
{
sum[i] = 0;
for(j=0;j<4;j++)
{
sum[i] = sum[i] + stu[i].score[j];
}
printf("%10ld %8s %3c %6d/%02d/%02d %4d %4d %4d %4d %6.1f\n",
stu[i].studentID,
stu[i].studentName,
stu[i].studentSex,
stu[i].birthday.year,
stu[i].birthday.month,
stu[i].birthday.day,
stu[i].score[0],
stu[i].score[1],
stu[i].score[2],
stu[i].score[3],
sum[i]/4.0);
}
return 0;
}
二、!strcmp(stu[2].age,age2)//age2与stu[2].age作比较;判断是否相等!
三、switch使用
四、#include<windows.h>
system("cls");//清屏
#include<conio.h>
getch();//从控制台读取一个字符,但不显示在屏幕上!原型:int getch()
学生信息管理源代码:
#include<stdio.h>
#include<windows.h>
#include<math.h>
#include<conio.h>//int getch();//任意键返回
int flag=0; //标记
struct password1
{
char password1[20];
}password1;
struct password2
{
char password2[20];
}password2;
struct password3
{
char password3[20];
}password3;
struct student//
{
char xuehao[11];
char xingming[21];
char gender[10];
char home[100];
char mingzu[21];
int age;
};
struct studentnumber{
int number;//录入学生的人数
}n;
#define N 100
struct student stu[N];
struct studentnumber2{
int number2;//增加录入学生的人数
}n2;
void homepage();//主页函数声明
void studentinformation();
void information();
void lrinformation();//录入信息
void cxinfrmation();//查询信息
void xginformation();//修改信息
void llinformation();//浏览信息
void scinformation();//删除信息
void zjinformation();//增加信息
void studentresult();//学生成绩管理
/***************************************主页****************************************/
void homepage()//主页
{
int k;//
system("cls");//清屏
printf(" !!!========学生信息管理系统=========!!!\n");
printf("********************************************\n");
printf("********************************************\n");
printf("** 1. 学生管理 5. 财务管理 **\n");
printf("** 2. 教务管理 6. 图书管理 **\n");
printf("** 3. 科研管理 7. 设备管理 **\n");
printf("** 4. 人事管理 8. 后勤管理 **\n");
printf("** 9. 办公室管理 10. 教师管理 **\n");
printf("*******0. 退出******************************\n");
printf("********************************************\n");
printf("请您在上述功能中选择序号: ");
scanf("%d",&k);
switch(k)
{
case 1:
studentinformation();
homepage();
break;
case 2:
system("cls");
printf("敬请期待中!\n任意键返回主页面!\n");
getch();//任意键返回,包含在头文件conio.h
//Sleep(2000);
homepage();
break;
case 3:
system("cls");
printf("敬请期待中!\n任意键返回主页面!\n");
getch();//任意键返回
Sleep(2000);
homepage();
break;
case 4:
system("cls");
printf("敬请期待中!\n任意键返回主页面!\n");
getch();//任意键返回
Sleep(2000);
homepage();
break;
case 5:
system("cls");
printf("敬请期待中!\n任意键返回主页面!\n");
//getch();//任意键返回
Sleep(2000);
homepage();
break;
case 6:
system("cls");
printf("敬请期待中!\n任意键返回主页面!\n");
//getch();//任意键返回
Sleep(2000);
homepage();
break;
case 7:
system("cls");
printf("敬请期待中!\n任意键返回主页面!\n");
//getch();//任意键返回
Sleep(2000);
homepage();
break;
case 0:
exit(0);//退出
break;
default :
system("cls");
printf("您的选择错误!任意键返回主页!\n");
getch();
Sleep(2000);
homepage();
break;
}
}
/***************************************学生信息管理****************************************/
void studentinformation()
{
int i;
system("cls");
printf("*********************************************************************\n");
printf(" 1. 学生个人信息管理模块 2. 学生个人成绩管理模块\n");
printf(" 11.返回主页 0.退出系统\n");
printf("*********************************************************************\n");
scanf("%d",&i);
switch(i)
{
case 1:
information();//
break;
case 11:
homepage();
break;
/*case 0:
exit(0);
break;*/
case 2:
studentresult();//
break;
default:
system("cls");
printf("您的选择错误!任意键重新选择!\n");
getch();//
studentinformation();
break;
}
}
/***************************************学生个人信息管理模块****************************************/
void information(){
int o;
system("cls");
printf("*********************************************************************\n");
printf(" 1.录入学生信息 3.查询学生信息\n");
printf(" 2.修改学生信息 4.浏览学生信息\n");
printf(" 5.删除学生信息 6.增加学生信息\n");
printf(" 222.返回上一级\n");
printf(" 111.返回主页 0.退出系统 \n");
printf("*********************************************************************\n");
scanf("%d",&o);
switch (o)
{
case 1:
lrinformation();
information();
break;
case 3:
cxinfrmation();
information();
break;
case 2:
xginformation();
information();
break;
case 4:
llinformation();
information();
break;
case 5:
scinformation();
information();
break;
case 6:
zjinformation();
information();
break;
case 222:
studentinformation();
break;
/*case 0:
exit(0);
break;*/
case 111:
homepage();
break;
default :
system("cls");
printf("您的选择错误!任意键重新选择!\n");
getch();
information();
break;
}
}
/***************************************录入信息****************************************/
void lrinformation()
{
int i;
system("cls");
printf("请输入您要录入的学生人数");
scanf("%d",&n.number );
for(i=0;i<n.number;i++)
{
printf("请输入%d个学生的学号\n",i+1);
scanf("%s",stu[i].xuehao);
printf("请输入%d个学生的姓名\n",i+1);
scanf("%s",stu[i].xingming);
printf("请输入%d个学生的性别\n",i+1);
scanf("%s",stu[i].gender);
printf("请输入%d个学生的家庭住址\n",i+1);
scanf("%s",stu[i].home);
printf("请输入%d个学生的名族\n",i+1);
scanf("%s",stu[i].mingzu);
printf("请输入%d个学生的年龄\n",i+1);
scanf("%d",&stu[i].age);
}
printf("\n录入完毕,任意键继续!\n");
getch();
}
/***************************************查询信息****************************************/
void cxinfrmation()
{
int j;
char no[11];//学号
system("cls");//
printf("请输入学号:");
scanf("%s",no);
for(j=0;j<n.number;j++)//n.number学生人数
{
if(!strcmp(stu[j].xuehao,no))//查询的学号与输入的学号相对比
{
//输出信息
printf("\n--------------------------------------------------------------------\n");
printf("学号:%s\t姓名:%s\t性别:%s\t家庭住址:%s",stu[j].xuehao ,stu[j].xingming ,stu[j].gender,stu[j].home);
printf("\n名族:%s\t年龄:%d\t",stu[j].mingzu ,stu[j].age );
printf("\n--------------------------------------------------------------------\n");
break;
}
}
printf("\n查询完毕,任意键继续!\n");
getch();
}
/***************************************修改信息****************************************/
void xginformation()
{
int j;
char no[11];
system("cls");
printf("请输入您要修改的学号:");
scanf("%s",no);
for(j=0;j<n.number;j++)
{
if(!strcmp(stu[j].xuehao,no))//比较后,重新输入结构体stu[N].xx
{
printf("\n--------------------------------------------------------------------\n");
printf("请输入新的学号:");
scanf("%s",stu[j].xuehao);
printf("请输入新的姓名:");
scanf("%s",stu[j].xingming );
printf("请输入新的性别:");
scanf("%s",stu[j].gender );
printf("请输入新的家庭住址:");
scanf("%s",stu[j].home);
printf("请输入新的名族:");
scanf("%s",stu[j].mingzu);
printf("请输入新的年龄:");
scanf("%d",&stu[j].age);
printf("学号:%s\t姓名:%s\t性别:%s\t家庭住址:%s",stu[j].xuehao ,stu[j].xingming,stu[j].gender,stu[j].home );
printf("名族:%s\t年龄:%d\t",stu[j].mingzu ,stu[j].age );
printf("\n--------------------------------------------------------------------\n");
break;
}
}
printf("\n修改完毕,任意键继续!\n");
getch();
}
/***************************************浏览信息****************************************/
void llinformation()
{
int j;
system("cls");
for(j=0;j<n.number-flag;j++)//flag=0,删除后flag=删除的个数
{
printf("\n--------------------------------------------------------------------\n");
printf("学号:%s\t姓名:%s\t性别:%s\t家庭住址:%s\n",stu[j].xuehao ,stu[j].xingming ,stu[j].gender ,stu[j].home );
printf("名族:%s\t年龄:%d\t",stu[j].mingzu ,stu[j].age );
printf("\n--------------------------------------------------------------------\n");
}
printf("\n浏览完毕,任意键继续!\n");
getch();
}
/***************************************删除信息****************************************/
void scinformation()
{
int i,j;
char no[11];
system("cls");
printf("请输入您要删除的学号:");
scanf("%s",no);
for(j=0;j<n.number;j++)
{
if(!strcmp(stu[j].xuehao,no))
{
for(i=j;i<n.number+1;i++)//stu[i]=stu[j],i=j;地址从0开始的,则n.number+1
stu[i]=stu[i+1];//删除stu[i]
flag++;//flag=0
}
}
printf("\n删除完毕,任意键继续!\n");
getch();
}
/***************************************增加信息****************************************/
void zjinformation()
{
int i;
system("cls");
printf("请输入您要增加的学生人数:\n");
scanf("%d",&n2.number2);
for(i=n.number;i<n.number+n2.number2;i++)//i=n.number之前的人数;
{
//printf("请输入%d个学生的姓名\n",i+1-flag);
printf("请输入学生的学号\n");
scanf("%s",stu[i-flag].xuehao);
printf("请输入学生的姓名\n");
scanf("%s",stu[i-flag].xingming);
printf("请输入学生的性别\n");
scanf("%s",stu[i-flag].gender);
printf("请输入学生的家庭住址\n");
scanf("%s",stu[i-flag].home);
printf("请输入学生的名族\n");
scanf("%s",stu[i-flag].mingzu);
printf("请输入学生的年龄\n");
scanf("%d",&stu[i-flag].age);
}
n.number+=n2.number2;
printf("\n增加录入完毕,任意键继续!\n");
getch();
}
/***************************************学生成绩部分*******
没有什么变化代码如上,只需要做相应的改变即可*********************************/
void studentresult()
{
int x;
system("cls");
printf("*********************************************************************\n");
printf(" 1.录入学生成绩 3.查询学生成绩\n");
printf(" 2.修改学生成绩 4.浏览学生成绩\n");
printf(" 5.删除学生成绩 6.增加学生成绩\n");
printf(" 33.返回上一级\n");
printf(" 44.返回主菜单 0.退出系统\n");
printf("*********************************************************************\n");
scanf("%d",&x);
switch(x)
{
case 1:
//lrchengji();
break;
case 2:
//xgchengji();
break;
case 3:
//cxchengji();
break;
case 4:
//llchengji();
break;
case 5:
//scchengji();
break;
case 6:
//zjchengji();
break;
case 33:
studentinformation();
break;
case 44:
homepage();
case 0:
exit(0);
break;
break;
default :
system("cls");
printf("您的选择错误!任意键重新选择!\n");
getch();
studentresult();
break;
}
}
/***************************************录入成绩****************************************/
struct scorenumber
{
int snumber;//录入学生成绩的人数
}sn;
struct scoreinformation
{
char name[21];
float chinese;
float maths;
float english;
};
struct scoreinformation chengji[N];
void lrchengji()
{
int i;
system("cls");
printf("请输入要录入的学生人数:\n");
scanf("%d",&sn.snumber);
for(i=0;i<sn.snumber;i++)
{
system("cls");
printf("请输入%d个学生的姓名:\n",i+1);
scanf("%s",chengji[i].name);
printf("请输入%d个学生%s的chinese成绩:\n",i+1,chengji[i].name);
scanf("%f",&chengji[i].chinese);
printf("请输入%d个学生%s的maths成绩:\n",i+1,chengji[i].name);
scanf("%f",&chengji[i].maths);
printf("请输入%d个学生%s的english成绩:\n",i+1,chengji[i].name);
scanf("%f",&chengji[i].english);
}
printf("\n录入完毕,任意键继续!\n");
getch();
}
/***************************************主函数****************************************/
main()
{
/**登录密码**/
/*int password;
//printf("\n请输入初始登录密码"1":\n");//1
looop:scanf("%d",&password);//looop
if(password==1)
{
system("cls");
printf("为了您的安全要更改您的密码!\n请输入新密码:\n");//2
loooop: scanf("%s",password1.password1);//loooop
system("cls");
printf("请确定你的密码\n");//3
scanf("%s",password2.password2);
if(!strcmp(password2.password2,password1.password1))// !strcmp如果两个字符串相等
{
system("cls");
printf("请输入密码打开主页\n");
loop: scanf("%s",password3.password3);//loop
if(!strcmp(password1.password1,password3.password3))
{
system("cls");
printf("密码正确!\n");
//getch();
Sleep(2000);
homepage();//
}
else
{
system("cls");
printf("您的的密码不正确!\n");
printf("请重新输入密码打开主页!\n\n");
goto loop;//loop
}
}
else
{
system("cls");
printf("您两次输入密码不相同哦!\n请重新输入您的新密码!\n");
goto loooop;//loooop
}
}
else
{
system("cls");
printf("不好意思,您的输入有误!\n请重新输入初始密码!\n");
goto looop;//looop
}*/
homepage();//主页函数调用
return 0;
}