广东工业大学 C语言课程设计报告


一、 设计任务目的与要求

1、  进一步掌握和利用C语言进行程设计的能力;
2、  进一步理解和运用结构化程设计的思想和方法;
3、  初步掌握开发一个小型实用系统的基本方法;
4、  学会调试一个较长程序的基本方法;
5、  学会利用流程图或N-S图表示算法;
6、  掌握书写程设计开发文档的能力(书写课程设计报告);


二、 设计内容  

1、 总体设计

l 说明包含几大功能模块

l 画出系统功能模块结构图和系统流程图

l 数据结构设计及用法说明

 

2、 详细设计

l 函数名字:

l 函数功能:

l 数据结构设计描述,参数说明

实现过程:写算法或解决思路,贴(NS图或流程图)


学生奖学金管理系统流程图如下

 

使用到的结构体变量

 

struct Student

{

char Sid[10];

char Sclass[20];

char Sname[20];

int Math;

int English;

int Physic;

int Sum;

int rank;

struct Student *next;

};


简介:以上的结构体为学生奖学金管理系统的核心部分,是贯穿整个系统的灵魂。存储和读取都是以结构体的形式进行的,每个结构体包含着丰富的信息。


項目源代码:

# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# define SIZE sizeof(struct Student)

struct Student
{	
	char Sid[10];
	char Sclass[20];
	char Sname[20];
	int Math;
	int English;
	int Physic;
	int Sum;
	int rank;
	struct Student *next;
}; 

void ShowMenu()
{
	printf("\n***********************************************************\n");
	printf("\twelcome to Stugent bonus management system\n\n");
	printf("\t1-------------- Record\n");                    
	printf("\t2-------------- Show all record\n");                  
	printf("\t3-------------- Find\n");
	printf("\t4-------------- Statistics\n");
	printf("\t5-------------- Delete\n");
	printf("\t6-------------- Add\n");
	printf("\t7-------------- Sort\n");
	printf("\t8-------------- Save File\n");
	printf("\t9-------------- Copy File\n");
	printf("\t10------------- Exit\n\n");                   
	printf("***********************************************************\n");
}

//从键盘中输入的数据创建链表
struct Student * in_stuNode()
{
	struct Student * head, * p1, * p2;
	int n = 0;
	p1 = p2 = (struct Student *)malloc(SIZE);

	head = NULL;
	
	scanf("%s",  p1->Sid);
	while(p1->Sid[0] != '@')
	{
		scanf("%s%s%d%d%d", p1->Sclass, p1->Sname, &p1->Math, &p1->English, &p1->Physic);
		p1->Sum = 0; p1->rank = 0;
		n++;
		if(n == 1)
		{
			head = p1;
		}else
		{
			p2->next = p1;
		}
		p2 = p1;

		p1 = (struct Student *)malloc(SIZE);
		scanf("%s",  p1->Sid);
	}
	p2->next = NULL;        
	return head;
}

//从链表中的数据 写入文件
void Record(struct Student *head)
{
	FILE *fp;
	struct Student  *p1;
	p1 = head;

	if((fp = fopen("D:\\Course\\student.txt", "w")) == NULL)
	{
		printf("cannot open this file\n");
		return;
	}

	while(p1 != NULL)
	{
		fprintf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank);
/*		if(fwrite(p1, SIZE, 1, fp) != 1)
			{
				printf("file write error\n");
			}
*/
		p1 = p1->next; 

	}

	if(p1 == NULL){
	printf("Record ok!\n");
	}

	free(p1);
	free(head);
	fclose(fp);

}

//从文件中读取的数据创建链表
struct Student * File_stuNode(){

	FILE *fp;
	int n = 0;
	struct Student *head, *p2, *p1;

	if((fp = fopen("D:\\Course\\student.txt", "r")) == NULL)
	{
		printf("cannot open this file\n");
		return NULL;
	}

	head = NULL;

	p2 = p1 = (struct Student *)malloc(SIZE);
	fscanf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d", p1->Sid, p1->Sclass, p1->Sname, &p1->Math, &p1->English, &p1->Physic, &p1->Sum, &p1->rank);
//	fread(p1, SIZE, 1, fp);
	while(!feof(fp))
	{
		
		n++;
		if(n == 1)
		{
			head = p2;
		}else
		{
			p2->next = p1; 
		}
		p2 = p1;
		p1 = (struct Student *)malloc(SIZE);
	    fscanf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d", p1->Sid, p1->Sclass, p1->Sname, &p1->Math, &p1->English, &p1->Physic, &p1->Sum, &p1->rank);
//		fread(p1, SIZE, 1, fp);
	}

	p2->next = NULL;
	fclose(fp);

	return head;
}

void Show_stuNode()
{
	printf("---------------------------STUDENT------------------------------------\n");
	printf("|no		|class	|name	|sc1	|sc2	|sc3    |sum	|order|\n");
	printf("----------------------------------------------------------------------\n");
	struct Student *p, *head;
	head = File_stuNode();     调用 File_stuNode()

	p = head;
	while(p != NULL)
	{
		printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p->Sid, p->Sclass, p->Sname, p->Math, p->English, p->Physic, p->Sum, p->rank);
		
		p = p->next; 
	}

}

void ShowMenu3()
{
	printf("\t****************************************\n");

	printf("\t1----------按名次查询某学生的个人成绩\n");

	printf("\t2----------按班级查询班级前3名学生的个人成绩\n");

	printf("\t3----------按成绩段查询某学生的个人成绩\n");

	printf("\t4----------exit\n");

	printf("\t****************************************\n");

}

void SortRank()
{
	struct Student *p1, *head, *p2;
	int i;
	head = File_stuNode();

	p1 = head;

	while(p1 != NULL)
	{
		i = 1;
		p2 = head;
		while(p2 != NULL)
		{
			if(p1->Sum < p2->Sum)
			{
				i++;
			}
			p2 = p2->next;
		}
		p1->rank = i;
		p1 = p1->next;

	}

	Record(head);
}

void SearchByRank()
{
	struct Student *p1, *head;
	int number;
	head = File_stuNode();
	p1 = head;

	if(p1->rank == 0)
	{
		printf("你还没有排名呢?请返回主菜单执行操作7\n");
		return;
	}
	printf("请输入要查询的名次:");

	scanf("%d", &number);

	while(p1 != NULL)
	{
		if(p1->rank == number)
		{
			printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank);
		}
		p1 = p1->next;
	}

	free(p1);
	free(head);

}

void SearchByClass()
{

	int i = 1;
	char Class[10] = {0};
	struct Student *p1, *head, *p2;

	printf("请输入要查询的班级:如201501 \n");
	scanf("%s", Class);

	head = File_stuNode();
	p1 = head;

	while(p1 != NULL)
	{
		if(strcmp(Class, p1->Sclass) == 0)
		{
			i = 1;
			p2 = head;
			while(p2 != NULL)
			{
				if(strcmp(Class, p2->Sclass) == 0)
				{
					if(p1->Sum < p2->Sum)
						{
							i++;
						}
				}
				p2 = p2->next;
			}

			if(i <= 3)
			{
				printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank);	
			}
			else if(i > 3)
			{
				break;
			}
		}
		p1 = p1->next;
	}

	free(p1);
	free(head);

}

void SearchByScore()
{
	int scope1, scope2;
	int i = 0;
	struct Student *p1, *head;
	char course[10] = {0};

	printf("请输入要查询的分数段:如 70 - 80 \n");
	scanf("%d-%d", &scope1, &scope2);
	if(scope1 >= scope2)
	{
		printf("scope2 must be bigger than scope1!\n");
		return;
	}

	printf("请输入要查询的科目:(Math、English、Physic) \n");

	scanf("%s", course); 
	if(!(strcmp(course, "Math") == 0 || strcmp(course, "English") == 0 || strcmp(course, "Physic") == 0))
	{
		printf("no found the course\n");
		return;
	}

	head = File_stuNode();

	p1 = head;

	while(p1 != NULL)
	{
		if(strcmp(course, "Math")==0)
		{
			if(p1->Math >= scope1 && p1->Math <= scope2)
			{
				printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank);		
				i++;
			}
		}else if(strcmp(course, "English")==0)
		{
			if(p1->English >= scope1 && p1->English <= scope2)
			{
				printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank);		
				i++;
			}
		}else if(strcmp(course, "Physic")==0)
		{
			if(p1->Physic >= scope1 && p1->Physic <= scope2)
			{
				printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank);		
				i++;
			}
		}
		p1 = p1->next;
	}
		if(i == 0)
		{
			printf("no the student adopt to adition\n");
		}

}

void Search()
{
	int op;
	do
	{
		ShowMenu3();
		printf("\tplease choose the option:: ");
		scanf("%d", &op);

		switch(op)
		{
			case 1: SearchByRank(); break;

			case 2: SearchByClass(); break;

			case 3: SearchByScore(); break;

			case 4: break;

			default : printf("input error!\n");
		} 
	}while(op != 4);

}
void ShowMenu4()
{
	printf("\t****************************************\n");

	printf("\t1-------------- 总计\n");

	printf("\t2-------------- 分班统计\n");

	printf("\t3----------exit\n");

	printf("\t****************************************\n");

}
void StatByStu()
{	
	struct Student *head, *p1;

	head = File_stuNode();

	p1 = head;
	while(p1 != NULL)
	{
		p1->Sum = p1->Math + p1->English + p1->Physic;

		p1 = p1->next;
	}

	Record(head);
	
}

void StatByClass()
{
	char Class[10][10] = {0};
	int ClassSum[10] = {0};
	FILE *fp;
	struct Student *head, *p1;
	int i = 0;  //  记录class总数
	int j;
	int tag = 1;

	head = File_stuNode();
	p1 = head;

	while(p1 != NULL)
	{
		tag = 1;
		for(j = 0; j < i; j++)
		{
			if(strcmp(Class[j] , p1->Sclass) == 0)
			{
				tag = 0; break;
			}
		}
		if(tag == 1)
		{
			strcpy(Class[i++], p1->Sclass);	
		}
		p1 = p1->next;
	}

	p1 = head;
	while(p1 != NULL)
	{
		for(j = 0; j < i; j++)
		{
			if(strcmp(p1->Sclass, Class[j]) == 0)
			{
				ClassSum[j] += p1->Sum;
			}
		}
		p1 = p1->next;
	}



	if((fp = fopen("D:\\Course\\student1.txt", "w+")) == NULL)
	{
		printf("cannot open this file\n");
		return;
	}
	
	for(j = 0; j < i; j++)
	{
		printf("%s %d\n", Class[j], ClassSum[j]);
	}
}
void Statistics()
{
	int op;
	do
	{
		ShowMenu4();
		printf("\tplease choose the option:: ");
		scanf("%d", &op);

		switch(op)
		{
			case 1: StatByStu(); break;

			case 2: StatByClass(); break;

			case 3: break;

			default : printf("input error!\n");
		} 
	}while(op != 3);

}
struct Student * RankSort(struct Student * head)
{
	int i;
	struct Student *p1, *p2;

	p1 = head;
	while(p1 != NULL)
	{
		i = 1;
		p2 = head;
		while(p2 != NULL)
		{
			if(p1->Sum < p2->Sum)
			{
				i++;
			}
			p2 = p2->next;
		}
		p1->rank = i;
		p1 = p1->next;

	}

	return head;
}

/* 
	对链表 按 rank 实现从小到大排序, 并返回链表的头指针。
*/
struct Student * SortByRank(struct Student *head)
{
	struct Student *p1, *p2, *p3;

	struct Student t;

    for(p1 = head; p1 != NULL; p1 = p1->next)
    {
		p3 = p1;
		for(p2 = p1->next; p2 != NULL; p2 = p2->next)
		{
			if(p3->Sum < p2->Sum)
			{
				p3 = p2;   

			}
		}
		if(p3 != p1)
		{

			t.English = p1->English;
			t.Math = p1->Math;
			t.Physic = p1->Physic;
			t.Sum = p1->Sum;
			strcpy(t.Sclass, p1->Sclass);
			strcpy(t.Sid, p1->Sid);
			strcpy(t.Sname, p1->Sname);

			p1->English = p3->English;
			p1->Math = p3->Math;
			p1->Physic = p3->Physic;
			p1->Sum = p3->Sum;
			strcpy(p1->Sclass, p3->Sclass);
			strcpy(p1->Sid, p3->Sid);
			strcpy(p1->Sname, p3->Sname);

			p3->English = t.English;
			p3->Math = t.Math;
			p3->Physic = t.Physic;
			p3->Sum = t.Sum;
			strcpy(p3->Sclass, t.Sclass);
			strcpy(p3->Sid, t.Sid);
			strcpy(p3->Sname, t.Sname);
	
		}
    }
	RankSort(head);   
    return head;
}


/* 
	对链表 按 Sid 实现从小到大排序, 并返回链表的头指针。
*/
struct Student * SortBySid(struct Student *head)
{
	struct Student *p1, *p2, *p3;

	struct Student t;

    for(p1 = head; p1 != NULL; p1 = p1->next)
    {
		p3 = p1;
		for(p2 = p1->next; p2 != NULL; p2 = p2->next)
		{
			if(strcmp(p3->Sid, p2->Sid) > 0)
			{
				p3 = p2;
			}
		}
		if(p3 != p1)
		{
			t.English = p1->English;
			t.Math = p1->Math;
			t.Physic = p1->Physic;
			strcpy(t.Sclass, p1->Sclass);
			strcpy(t.Sid, p1->Sid);
			strcpy(t.Sname, p1->Sname);

			p1->English = p3->English;
			p1->Math = p3->Math;
			p1->Physic = p3->Physic;
			strcpy(p1->Sclass, p3->Sclass);
			strcpy(p1->Sid, p3->Sid);
			strcpy(p1->Sname, p3->Sname);

			p3->English = t.English;
			p3->Math = t.Math;
			p3->Physic = t.Physic;
			strcpy(p3->Sclass, t.Sclass);
			strcpy(p3->Sid, t.Sid);
			strcpy(p3->Sname, t.Sname);
	
		}
    }

	// 统计总分;
	p1 = head;
	while(p1 != NULL)
	{
		p1->Sum = p1->Math + p1->English + p1->Physic;

		p1 = p1->next;
	}
	
	head = RankSort(head);   //  排名;
    return head;
}

void ShowSortBy(int i)
{
	struct Student *head, *p1;
	SortRank(); 
	head = File_stuNode();

	p1 = head;

	if(i == 1)
	{
		p1 = SortByRank(p1);	
	}
	else if(i == 2)
	{
		p1 = SortBySid(p1);
	}
	while(p1 != NULL)
	{

		printf("%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank);		
		p1 = p1->next;
	}
}

void ShowSort()
{
	int op;
	do
	{
		printf("\t****************************************\n");

		printf("\t1----------sort by the rank for all student\n");

		printf("\t2----------sort by the Sid for all student\n");

		printf("\t3----------Exit!\n");

		printf("\t****************************************\n");

		printf("\tplease choose the option:: ");
		scanf("%d", &op);

		switch(op)
		{
			case 1: ShowSortBy(op); break;

			case 2: ShowSortBy(op); break;

			case 3: break;

			default : printf("input error!\n");
		} 
	}while(op != 3);

}
void Delete()
{
	struct Student *p1, *head, *p2;
	char stuid[10] = {0};
	int tag = 0;

	head = File_stuNode();

	printf("please input the deleted stuSid:\n");
	scanf("%s", stuid);

	p1 = head;
	p2 = NULL;
	while(p1 != NULL)
	{
		if(strcmp(p1->Sid, stuid) == 0)
		{
			if(p2 == NULL)
			{
				head = p1->next; // 删除是 head 结点
				tag = 1;
				break;
			}else{

				if(p1->next == NULL)
				{
					p2->next = NULL; // 删除是 尾节点 
				    tag = 1;
					break;
				}
				p2->next = p1->next;
				tag = 1;
				break;
			}
		}
		p2 = p1;
		p1 = p1->next;
	}
	if(tag == 0)
	{
		printf("no found the student!\n");
	}else{
		Record(head);
	}

}

void  Add()
{
	struct Student * head1, *head2, *p1, *head;

	head1 = File_stuNode();
	head2 = in_stuNode();

	p1 = head1;
	if(p1 != NULL)
	{
		while(p1->next != NULL)
		{
			p1 = p1->next;
		}
		head = head1;
		p1->next = head2;
		
	}
	else
	{
		head = head2;	
	}
	if(head == NULL){
		printf("Y");}
	Record(head);

}

void CopyFile(){
	FILE *fp, *fp1;
	char filename[30] = {0};
	char filename1[30] = {0};
	struct  Student *p1, stu;

	printf("please input the fileName\n");
	scanf("%s", filename);

	getchar();
	printf("please input the fileName path\n");
	scanf("%s", filename1);
	getchar();

	if((fp = fopen(filename, "r")) == NULL)
	{
		printf("open file error");
		return;
	}

	if((fp1 = fopen(filename1, "w")) == NULL)
	{
		printf("open file error");
		return;
	}

	p1 = &stu;

	while(!feof(fp))
	{
		fscanf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d", p1->Sid, p1->Sclass, p1->Sname, &p1->Math, &p1->English, &p1->Physic, &p1->Sum, &p1->rank);
		fprintf(fp1, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank);
	}

	fclose(fp);
	fclose(fp1);
}

void SaveFile() 
{
	FILE *fp;
	char filename[30] = {0};
	struct  Student *head, *p1;

	scanf("%s", filename);
	getchar();
	if((fp = fopen(filename, "w")) == NULL)
	{
		printf("open file error");
		return;
	}

	head = File_stuNode();
	
	p1 = head;
	while(p1 != NULL)
	{
		fprintf(fp, "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\n", p1->Sid, p1->Sclass, p1->Sname, p1->Math, p1->English, p1->Physic, p1->Sum, p1->rank);

		p1 = p1->next;
	}

	free(head);
	free(p1);
	fclose(fp);
}

int main()
{
	int option;
	
	do
	{
		ShowMenu();
		printf("\tplease choose the option: ");
		scanf("%d", &option);
		getchar();

		switch(option)
		{
			case 1: Record(in_stuNode()); break;

			case 2: Show_stuNode(); break;

			case 3: Search(); break;

			case 4: Statistics(); break;

			case 5: Delete(); break;

			case 6: Add(); break;

			case 7: ShowSort(); break;

			case 8: SaveFile();break;

			case 9: CopyFile();break;

			case 10: break;

			default : printf("input error!");

		}
	}while(option != 10);

	return 0;
}



  • 6
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
目录 摘 要..............................................................1 1设计内容、任务及具体要求.........................................2 1.1设计内容.....................................................2 1.2设计任务及具体要求...........................................2 2概要设计.........................................................3 2.1该系统的功能简介.............................................3 2.2 总体程序框图.................................................3 2.3各个模块之间的主要关系........................................4 3系统功能模块的具体设计............................................5 3.1各个模块的程序流程图及运行界面................................5 3.2对关键代码加以分析说明.......................................15 4程序调试分析.....................................................23 5程序使用说明.....................................................24 6总结.............................................................25 致谢...........................................................26 参考文献...........................................................27 附:源程序..........................................................28 摘 要 工资管理系统是针对企业的工资管理业务进行计算机处理而开发的应用软件。该系统由系统维护、输入、查询、修改、输出、统计等子模块组成,功能基本涵盖普通企业的工资管理业务范围。企业应用本系统后,可以有效的提高工资管理水平。本文从需求分析、开发平台选择、系统模块建立、数据库设计、功能模块编程实现及软件测试等方面阐述了本应用系统的设计过程。为便于说明,文中绘制了程序结构框图、数据流程图和部分界面图。最后附有主要的源程序代码清单。 关键词:工资管理 系统维护 数据汇总 管理系统 软件开发
C语言程序设计是计算机科学与技术专业中非常重要的一门课程。它作为一门编程语言,具有广泛的应用领域,包括嵌入式系统、操作系统、网络编程等等。在学习这门课程时,我们需要关注一些重点和难点。 首先,理解C语言的语法规则和基本概念是学习这门课程的重点。C语言拥有丰富的语法特点,比如关键字、标识符、变量类型、运算符、控制语句等等。学习者需要通过大量的练习和实例来熟练掌握这些知识点,并能够灵活运用到实际的程序编写中。 其次,算法和逻辑思维是C语言程序设计的难点。在解决实际问题时,我们需要编写高效的算法来实现功能。学习者需要具备良好的逻辑思维能力,能够将问题抽象化,并使用C语言编写出相应的算法。对于初学者来说,这可能是一个挑战,需要不断的练习和实践来提高自己的算法设计能力。 第三,调试和错误处理也是学习C语言程序设计的难点之一。在编写程序时,难免会出现错误和bug。学习者需要具备良好的调试能力,能够找到问题所在并及时修复。同时,还需要学会合理地处理错误,以提高程序的稳定性和鲁棒性。 最后,实际应用是C语言程序设计的重点之一。学习者需要通过实际的项目实践来巩固自己的知识,并将所学的内容应用到实际中去。这样可以更好地理解和掌握C语言的特性和应用场景,提高自己的编程能力。 总结来说,C语言程序设计课程的重点在于理解语法规则和基本概念,算法设计和逻辑思维,调试和错误处理,以及实际应用。只有通过不断的学习和实践,才能够掌握这门重要的编程语言,提高自己的编程水平。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mrchesian

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值