C语言基础——课程设计之团员管理系统

转眼间一学期要过去了,C语言课程我们也迎来了尾声,我很喜欢这么学科,在学期最后我所在的小组完成了课程设计。

以下是全部代码(详细讲解在下一期):

#include <stdio.h> 
#include <string.h>
#define NAME_LEN 64   /* 姓名字符数 */ 

double time;
int    index;
char name[NAME_LEN];
long studne_id;
typedef struct students {
	long studne_id;       /* 学号 */
	char name[NAME_LEN]; /* 姓名 */
	char sex[3];          /* 性别 */
	int age;              /* 年龄 */
	double time;        /* 入团时间 */
    char telephone[13];  /* 联系电话 */
} Students;
struct	students student[] = {
		{1240701, "陈二", "男", 17, 2016, "17100005963"},
		{1240702, "张三", "男", 18, 2016, "17200005912"},
		{1240703, "李四", "女", 19, 2018, "15100005934"},
		{1240704, "王五", "男", 20, 2020, "12300005463"},
		{1240705, "赵六", "男", 21, 2020, "11100002983"},
	};
void select_studnet_all(Students std[], int count);   // 显示函数
int add_studnet_info(Students std[], int count);      // 添加函数
int find_Students_id(Students std[], long studne_id, int count);  //调用学号函数
void update_studnet_info(Students std[], int count);   //  更新函数
int delete_studnet_info(Students std[], int count);  //  删除函数
void sort_student_info(Students std[], int count);//排序函数
void find_studnet_info(Students std[], int count);   // 统计函数
void search_studnet_info(Students std[], int count);//按姓名查找函数
void seek_studnet_info(Students std[], int count);//按学号查找函数
int main(void) {

	int num;
	int count = 5;
	while (1) {
		puts("----------欢迎进入团员管理系统----------");
		puts("|         1.显示团员信息               |");
		puts("|         2.添加团员信息               |");
		puts("|         3.更新团员信息               |");
		puts("|         4.删除团员信息               |");
        puts("|         5.排序团员信息               |");
		puts("|         6.统计团员信息               |");
		puts("|         7.按姓名搜索团员信息         |");
		puts("|         8.按学号搜索团员信息         |");
		puts("|         9.退出系统                   |");
		puts("----------------------------------------");
		printf("请输入1至9选项:");
		scanf("%d", &num);
		switch (num) {
		case 1:
			select_studnet_all(student, count);
			break;
		case 2:
			count = add_studnet_info(student, count);
			break;
		case 3:
			update_studnet_info(student, count);
			break;
		case 4:
			count = delete_studnet_info(student, count);
			break;
		case 5:
			sort_student_info(student, count);
			break;
		case 6:
			find_studnet_info(student, count);   // 统计函数
			break;
		case 7:
			search_studnet_info(student, count);   //查找姓名函数
			break;
		case 8:
			seek_studnet_info(student, count); //查找姓名函数
			break;
		case 9:
			puts("系统结束运行!!");
			return 0;	
		default:
			puts("输入错误,请重新输入!");
			break;
		}

	}

	return 0;
}

void select_studnet_all(Students std[], int count)
{
	int i;
	puts("  学号      姓名 性别  年龄   入团时间      联系电话");
	for (i = 0; i < count; i++) 
	{
		printf("%ld    %-5s %s    %d      %6.2f       %s\n", std[i].studne_id, std[i].name, std[i].sex, std[i].age, std[i].time, std[i].telephone);
	}
	puts("\n");
}

int add_studnet_info(Students std[], int count)
{
	long studne_id;       /* 学号 */
	char name[NAME_LEN]; /* 姓名 */
	char sex[3];          /* 性别 */
	int age;              /* 年龄 */
	double time;        /* 入团时间 */
    char telephone[13];  /* 联系电话 */
	int index;

	printf("请输入学号:");
	scanf("%ld", &studne_id);
	index = find_Students_id(std, studne_id, count);

	printf("请输入姓名:");
	scanf("%s", name);

	printf("请输入性别:");
	scanf("%s", sex);

	printf("请输入年龄:");
	scanf("%d", &age);

	printf("请输入入团时间:");
	scanf("%lf", &time);

	printf("请输入联系电话:");
	scanf("%s", &telephone);

	if (index == -1) 
	{
		std[count].studne_id = studne_id;
		strcpy(std[count].name, name);
		strcpy(std[count].sex, sex);
		std[count].age = age;
		std[count].time = time;
		strcpy(std[count].telephone, telephone);
		puts("已成功添加新的团员信息:");
		printf("%ld    %-5s %s    %d      %6.2f       %s\n", studne_id, name, sex, age, time, telephone);
		count++;
	}else 
	{
		puts("学号重复添加失败!");
	}
	return count;
}

int find_Students_id(Students std[], long studne_id, int count) 
{
	int i;
	int index;

	for (i = 0; i < count; i++) 
	{

		if (std[i].studne_id == studne_id) 
		{
			index = i;
			break;
		}
		else 
		{
			index = -1;
		}

	}
	return index;
}

void update_studnet_info(Students std[], int count) 
{
	long studne_id;       /* 学号 */
	char name[NAME_LEN]; /* 姓名 */
	char sex[3];          /* 性别 */
	int age;              /* 年龄 */
	double time;        /* 身高 */
	char telephone[50];  /* 联系电话 */


	printf("请输入要修改的团员的学号:");
	scanf("%ld", &studne_id);

	index = find_Students_id(std, studne_id, count);

	if (index != -1) 
	{

		puts("请进行修改操作!");
		printf("请输入学号:");
		scanf("%ld", &studne_id);

		printf("请输入姓名:");
		scanf("%s", name);

		printf("请输入性别:");
		scanf("%s", sex);

		printf("请输入年龄:");
		scanf("%d", &age);

		printf("请输入入团时间:");
		scanf("%lf", &time);

		printf("请输入联系电话:");
		scanf("%s", &telephone);

		puts("已更新的团员信息:");
		printf("%ld    %-5s %s    %d      %6.2f       %s\n",  studne_id, name, sex, age, time, telephone);

		std[index].studne_id = studne_id;
		strcpy(std[index].name, name);
		strcpy(std[index].sex, sex);
		std[index].age = age;
		std[index].time = time;
		strcpy(std[index].telephone ,telephone);
		puts("修改成功!");
	}
	else 
	{
		puts("没有查找到该团员!");
	}

}

int delete_studnet_info(Students std[], int count) 
{
	long studne_id;       /* 学号 */
	int i;

	printf("请输入要删除的团员的学号:");
	scanf("%ld", &studne_id);

	for (i = 0; i < count; i++) 
	{

		if (std[i].studne_id == studne_id) 
		{
			
			while (1) 
			{
				if (i < count) 
				{
					std[i] = std[i + 1];
					i++;
				}
				else 
				{
					break;
				}
			}
			puts("删除成功!");
			count--;
			break;
		}
	}
       if (count == i) 
	   {
		puts("没有查找到该团员!");
	   }
	return count;
}
void sort_student_info(Students std[], int count)
{
	 int i,j;
	 Students t;
     for(i=1;i<count;i++)          //用"冒泡排序法"进行排序
	 {
        for(j=0;j<count-i;j++)
		{
            if(strcmp(student[j].name,student[j+1].name)>0) 
			{ 
			   t=student[j];
			   student[j]=student[j+1];
			   student[j+1]=t;
			}

		}
	 }
     printf("排序后的结果为:\n");
     for(i=0;i<count;i++)           //输出排序后的团员信息 
	{
	  printf("%ld    %-5s %s    %d      %6.2f       %s\n",student[i].studne_id,student[i].name,student[i].sex,student[i].age,student[i].time,student[i].telephone);
	}
}

void find_studnet_info(Students std[], int count)
{
	double time_find;        /*入团时间*/
	int i,j=0;//该年份入团的学生人数 
	printf("请输入入团时间:");
	scanf("%lf", &time_find);
    for(i=0;i<count;i++)
	{
		if(std[i].time==time_find)
		{
	    printf("%ld    %-5s %s    %d      %6.2f       %s\n",student[i].studne_id,student[i].name,student[i].sex,student[i].age,student[i].time,student[i].telephone);
	    j++;
		}
	}

    printf("该年份入团的学生人数为%d\n",j);
}

void search_studnet_info(Students std[], int count) 
{
	char a[8];
	int  i,y=0;
    printf("输入查要找的姓名:\n");
    scanf("%s",a);
	for(i=0;i<count;i++)
	{
	   if(strcmp(std[i].name,a)==0)
	   {
		   y=1;
	   printf("%ld    %-5s %s    %d      %6.2f       %s\n",student[i].studne_id,student[i].name,student[i].sex,student[i].age,student[i].time,student[i].telephone);
	   } 
	}
	if(y==0)
	printf("查不到该学生\n");
}

void seek_studnet_info(Students std[], int count) 
{
	long b;
	int  i,x=0;
    printf("输入查要找的学号:\n"); 
    scanf("%ld",&b);
	for(i=0;i<count;i++)
	{
	   if(std[i].studne_id==b)
	   {	  
		   x=1;
	   printf("%ld    %-5s %s    %d      %6.2f       %s\n",student[i].studne_id,student[i].name,student[i].sex,student[i].age,student[i].time,student[i].telephone);
	   }
	}
	if(x==0)
    printf("查不到该学生\n");
}

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
源代码: #include #include #include #include #define Smax 200 using namespace std; struct student { string num; string name; float eng; float math; float clang;//定义c++ float gete(){return eng;} float getm(){return math;} float getcl(){return clang;} string getn(){return num;} string getna(){return name;} int rank[3]; int row;//排名 int sinto(string,string,float,float,float);//输入数据 void sshow();//输出数据 float sall();// 求和 float save();//求平均 void objrank();//成绩分类 }; void shows()//普通函数 { cout<<setw(6)<<"排名"<<setw(6)<<"学号"<<setw(10)<<"姓名" <<setw(6)<<"英语"<<setw(6)<<"数学"<<setw(6)<<"c++" <<setw(6)<<"总分"<<setw(10)<<"平均分"<<endl; } int student::sinto(string a1,string a2,float b1,float b2,float b3 ) { num=a1;name=a2; eng=b1;math=b2;clang=b3; return 0; } void student::sshow()//输出 { cout<<setw(6)<<row<<setw(6)<<num<<setw(10)<<name<<setw(6) <<eng<<setw(6)<<math<<setw(6)<<clang<<setw(6)<<sall() <<setw(10)<<setiosflags(ios::fixed)<<setprecision(1)<<save()<<endl; cout<<setiosflags(ios::fixed)<<setprecision(0); } float student::sall()//求总分 { return eng+math+clang; } float student::save()//求平均分 {return sall()/3;} void student::objrank() { int n; rank[0]=(int)eng; rank[1]=(int)math; rank[2]=(int)clang; for(int i=0;i<3;i++) { n=rank[i]/10; switch(n) { case 9:n=1;break; case 8:n=2;break; case 7:n=3;break; case 6:n=4;break; default:n=5;} rank[i]=n; } } //类student结束 //类leo开始 class leo {private: student item[Smax]; int size; public: leo(); void lsize(int);//设置数组大小 void linit();//清空 void linsert();//添加 void ldelet(string);//删除 void lsearch(string);//查找 void lchan(string);//修改 void lpcent();//成绩分类 void lrow();//排序 void obave();//求平均 void lview();//显示全部数据 void lcin();//从磁盘输出 void lcout();//储存到磁盘 }; leo::leo() { student item[Smax]; lsize(0); } void leo::lsize(int i) {size=i; } void leo::linit() { lsize(0); cout<<"学生数据清除成功"<<endl;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值