⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 student.cpp

📁 这个小项目用以实现银行的管理系统
💻 CPP
字号:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
static int max = -1;
struct student 
{
	int sno;
	char name[10];
	int age;
}stu[5];

int read()
{
    FILE *f;
	f = fopen("c:\\a.txt","r+");
	if(f == NULL)
	{
		printf("there is no one\n");
		return -1;
	}

	 for(int i=0;!feof(f);i++)
	{
		fscanf(f,"%d %s %d\n",&stu[i].sno,stu[i].name,&stu[i].age);
	}
	 fclose(f);
	 return i-1;
}
write()
{
	FILE *fp;
	fp = fopen("c:\\a.txt","w+");
	if(fp == NULL)
	{
		printf("wrong writting \n");
		exit(0);
	}
    
	for(int i=0;i<=max;i++)
	fprintf(fp,"%d %s %d\n",stu[i].sno,stu[i].name,stu[i].age);
	fclose(fp);
}

open()
{
	max=read();
    if(max==-1) 
	{max++;
	 stu[max].sno=101;
	}
	else
	{
		max++;
		stu[max].sno=stu[max-1].sno+1;
	}
	 fflush(stdin);
	 scanf("%s%d",stu[max].name,&stu[max].age);

    write();

	printf("**********成功*********\n");
	printf("+-学号--姓名-----年龄-+\n");
	printf("| %d --%s---%d |\n",stu[max].sno,stu[max].name,stu[max].age);
	printf("+---------------------+\n");

}

update()
{
	max=read();
	int id;
	printf("please input your sno\n");

go:	scanf("%d",&id);
	for(int i=0;i<=max;i++)
		if(stu[i].sno==id)break;
	if(i>max)
	{printf("the sno doesn't exist\n");
	 goto go; 
	}

    stu[i].age = stu[i].age+1;
	write();
}
view()
{
	max=read();
	for(int i=0;i<=max;i++)
		printf("%d %s %d\n",stu[i].sno,stu[i].name,stu[i].age);
}
welcome()
{
	printf("                      *************welcome*************\n");
	printf("                      *****please input your choice****\n");
	printf("                      *****1. 注册      2. 查询********\n");
	printf("                      *****3. 修改      4. 删除********\n");
	printf("                      ********* 0. 退出 ***************\n");
	int x;
	for(;;)
	{
	printf("your choice is: \n");
	scanf("%d",&x);
	switch(x)
	{
	  case 1: open();break;
	  case 2: view();break;
      case 3: update();break;
	  case 4: break;
      case 0: exit(0);
	  default:printf("please input right number\n");
	}
	}

}


void main()
{
	printf("please input your username and pwd\n");
	char user[10],pwd[10];
	for(int i=0;i<3;i++)
	{
		scanf("%s%s",user,pwd);
        if(strcmp(user,"admin")==0&&strcmp(pwd,"123456")==0)welcome();
		else if(i<2)printf("input again\n");
		     else 
			 {printf("you will leave\n");
			  printf("bye!!!!\n");
			 }
	}

       
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -