C語言入門 - 學生信息管理系統源碼

學習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;
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章