栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言课程设计

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言课程设计

  • 设计目的

对于一个外卖系统来说,他要管理入驻餐馆的信息,包括餐馆名称,餐馆联系电话,餐馆地址以及餐馆所处位置与用户的距离。外卖公司要灵活运营,因此信息的管理要要考虑到餐馆信息的增添、删除与修改,另外一个完整的外卖管理系统既要包括管理端也应该有用户端,在用户端界面则应有用户对餐馆信息的选择与查询。开发这个简单的系统主要是为了可以为开发一个较为高级外卖系统提供一个可参考的简单程序界面。

通过课程设计,强化实践能力,巩固《高级语言程序设计(C语言)》课程学习的知识和技能,掌握工程软件设计的基本方法;

学会将知识应用于实际的方法,提高分析和解决问题的能力,增强综合开发能力;

 为后续计算机相关课程的学习打下坚实基础;为毕业设计、就业、深造奠定必要基础。 

  • 设计内容

通过本次课程设计,综合应用所学的计算机基础知识和所掌握的程序设计语言(C语言),自行设计并实现一个较为完整的小型管理信息系统或小型应用系统。系统功能包括:
①数据录入:录入外卖店铺信息数据,用链表和结构体数组;
②数据存储:用文件的形式将录入的外卖店铺信息数据存储; 
③数据读写:对文件中的外卖店铺信息数据进行读写操作;
④数据修改:对已存在的旧数据进行修改操作生成新的数据;
⑤数据增添:将新数据插入到链表的后面;
⑥数据删除:对已存在的旧数据进行删除操作;
⑦数据查询:对数据进行查询(简单查询);
⑧界面:设计总体菜单界面。

   本课程设计结合上学期所学的C语言知识,数组、函数、结构体、链表、指针、文件读取操作等等,准备设计开发一个简单的外卖管理系统。设计开发这个系统需要用到链表、文件读取、函数、指针等C语言知识。本课程设计将会实现对菜单的定义、菜单的显示、菜单选项的控制及退出菜单等功能。本着简单、易用的原则,本课程设计在尽量优化界面保证输入输出美观的同时又不是有好的交互界面。

代码如下
#include//编译预处理——文件包含(标准输入/输出函数) 
#include// 编译预处理——文件包含(常用函数) 
#include//编译预处理——字符相关的函数 
#include 
//定义一个包含店铺信息的结构体变量 
typedef struct{
	char name[100];
    char phone[100];
    char add[100];
    char km[100]; 
}Store;
 
typedef struct{
	Store data;
    struct Node *next;
}Node;
//定义一个结构体链表 
typedef struct
{
	int size;
	Node * head;
	Node * rear;
    //next的类型是指向本结构体类型的指针类型 
}LinkList;
//将文件信息创建成一个链表
LinkList * init() //尾插法创建单链表 
{
	LinkList * list =(LinkList *)(malloc(sizeof(LinkList)));//动态分配空间 
	Node * stroe = (Node *)(malloc(sizeof(Node))); 
	stroe->next = NULL;
	list->head = stroe;
	list->rear = stroe;
	
	char ch;
	FILE *fp;
	fp=fopen("C:\Users\Administrator\Desktop\外卖信息.txt","rt+");
	int i = 0,j=0;
	while((ch=getc(fp))!=EOF){
		if(ch == '#'){
			stroe->data.km[j] = '';//判断为最后一行的时候停止读取 
			break;
		}else if(ch == 'n'){//读到换行的时候证明一串数据已经读取完了,从新申请一个链表空间进行下一次的读取 
			stroe->data.km[j] = '';
			i = 0;
			j=0;
			stroe = (Node *)(malloc(sizeof(Node)));
			stroe->next = NULL;
			list->rear->next = stroe;
			list->rear = stroe;
			continue;
		}else if(ch == ' '){//读到空格的时候证明一条信息的一个部分已经读完进入下一个结点进行读取 
			if(i==0){
				stroe->data.name[j] = '';
			}else if(i==1){
				stroe->data.phone[j] = '';
			
			}else if(i==2){
				stroe->data.add[j] = '';
				
			}
			i++;
			j=0;
			continue;
		}
		//将不同类的信息放到对应的链表结点中去 
		if(i == 0){
			stroe->data.name[j++] = ch;
		}else if(i==1){
			stroe->data.phone[j++] = ch;
		}else if(i==2){
			stroe->data.add[j++] = ch;
		}else if(i==3){
			stroe->data.km[j++] = ch;
		}
	}
	fclose(fp);
	return list;
}
//展示文件中的所有信息 
void show(LinkList *list){
	Node * node = list->head;
	printf("序号tt店铺名称tt电话tt地址tt距离n");
	int i = 1;
	
	while(node!=NULL){
		printf("%dtt%stt%stt%stt%sn",i,node->data.name,node->data.phone,node->data.add,node->data.km);
		node = node->next;
		i++;
	}
}
//展示文件中的部分信息 
void show1(LinkList *list){
	Node * node = list->head;
	printf("序号tt店铺名称n");
	int i = 1;
	while(node!=NULL){
		printf("%dtt%sn",i,node->data.name);
		node = node->next;
		i++;
    }
}
//展示文件中指定序号的信息 
void show2(LinkList *list,int x){
	Node * node = list->head;
	printf("序号tt店铺名称tt电话tt地址tt距离n");
	int i=1;
	while(node!=NULL){
		if(i==x)
		{
			printf("nnn%dtt%stt%stt%stt%snnn",i,node->data.name,node->data.phone,node->data.add,node->data.km);
			break;
		}
		else{
			node = node->next;
		    i++;
		}
	}
}
//增添店铺信息 
void Insert(LinkList * list)
{	

	int i;
	printf("请输入添加店铺个数:");
	scanf("%d",&i);
	while(i>0){
		printf("请输入待添加的店铺的信息:n");
		Node * stroe = (Node *)(malloc(sizeof(Node)));//分配结点的内存空间 
		stroe->next = NULL;
		scanf("%s%s%s%s",stroe->data.name,stroe->data.phone,stroe->data.add,stroe->data.km);
		list->rear->next = stroe;
		list->rear = stroe;
		i--;
	}
}

//删除店铺信息 
void delete(LinkList * list)
{	

	show(list);
	printf("请输入要删除的店铺序号:");
	int n;
	scanf("%d",&n);
	Node * head = list->head;
	if(n == 1){
		list->head = head->next;
		free(head);
		return;	
	}
	int t = 2;
	while(head->next!=NULL){
		if(t == n){
			Node * del = head->next;
			head->next = del->next;
			del->next=NULL;
			free(del);
			break;
		}
		head = head->next;
		t++;
	}
	if(t!=n){
		printf("没有找到该店铺信息n");
	}
}
//修改店铺信息 
void alter(LinkList * list)
{	

	show(list);
	printf("请输入要修改的店铺序号:");
	int n;
	scanf("%d",&n); 
	printf("请输入新的名称:");
	char name[100];
	scanf("%s",name);
	Node * head = list->head;
	int t = 1;
	while(head!=NULL){
		if(t == n){
			strcpy(head->data.name,name);
			break;
		}
		head = head->next;
		t++;
	}
	if(t!=n){
		printf("没有找到该店铺信息n");
	}
}
void km()//冒泡排序法 ——对距离进行排序 
{
	int w,q,j;
	char str1[100];
	Store store[100];
	printf("请输9个店铺的信息:n");
	for(j=0;j<9;j++)
	{
		scanf("%s%s%s%s",store[j].name,store[j].phone,store[j].add,store[j].km);
	}
	for(w=0;w<9;w++)
	{
		for(q=0;q<9-w-1;q++)
		{
			if(strcmp(store[q].km,store[q+1].km)==1)
			{
				strcpy(str1,store[q].km);
				strcpy(store[q].km,store[q+1].km);
				strcpy(store[q+1].km,str1);
				strcpy(str1,store[q].name);
				strcpy(store[q].name,store[q+1].name);
				strcpy(store[q+1].name,str1);
				strcpy(str1,store[q].phone);
				strcpy(store[q].phone,store[q+1].phone);
				strcpy(store[q+1].phone,str1);
				strcpy(str1,store[q].add);
				strcpy(store[q].add,store[q+1].add);
				strcpy(store[q+1].add,str1);
			}
		}
	}
	printf("nnn");
	printf("排序后的结果如下:n");
	for(j=0;j<9;j++)
	{
		printf("%d %s %s %s %sn",j+1,store[j].name,store[j].phone,store[j].add,store[j].km);
	}
}
//用户名及登陆密码
ME()
{
	char s1[7]={"admin"},s2[6]={"00000"},s[10],x[10];
	printf("nntt** W E L C O M E **nnt这里是外卖管理系统,请选择接下来的操作n");
	while(1)
	{
		printf("请输入用户名:");
	    scanf("%s",s);
	    if(strcmp(s1,s)==0)
	    {
	        printf("nt请输入密码:");
	        scanf("%s",x);
	        if(strcmp(s2,x)==0)
	        {
		        break;
	        }
	        else{
		        printf("ntSorry,密码错误,请从新输入:");
	        }
        }
        else{
	    printf("ntSorry,该用户不存在,");
        }
	} 
} 
int main()
{
	Store store[2]; 
	system("mode con:cols=110 lines=37");
	system("color a0");
	ME();
	while(1)
	{
	    printf("t请问您是要进入用户端还是管理端?n");
        printf("t用户端请按 1 ,管理端请按 0 ,退出系统按 # n");
        int b;
        scanf("%d",&b);
        //将所有店铺信息存储链表中 
	    LinkList * list=init();
	    printf("********************************************n");
		//录入店铺信息
        int c=9,d,j,k;
        while(1)
		{	if(b==0)//管理端 
	        { 
		    	printf("请选择服务项目:"); 
        	    printf("* 1:增加店铺        2:删除店铺n");
       		    printf("tt* 3:修改店铺信息    4:输入9个店铺的信息并对距离进行排序n");
       		    printf("tt* 0:返回首界面       n"); 
			    scanf("%d",&c);
                if(c==1)//增加店铺信息 
                {
        	        Insert(list); 
        	        printf("n==================================================================================n");
		        }
				else if(c==2)//删除店铺信息 
		  	    { 
		           delete(list);
		           printf("n====================================================================================n");
	      	    } 
	            else if(c==3)//修改店铺信息
		        {
		   	        alter(list); 
		   	        printf("n===================================================================================n");
	           }
	           else if(c==4)
			   {
			   	    km();
			   	    printf("n===================================================================================n");
				} 
	            else if(c==0)
	           {
	       	        break;
				} 
				else{
					printf("Sorry,暂时还没有该服务哦~~~n");
				}
		       show(list); 
		    }
			else if(b==1)//用户端 
         	{	
		        printf("请看如下菜单n");
		        //调用菜单文件
		        show1(list);
		        printf("n请输入您想了解的店铺序号(温馨提示:按0推出查询):n");
		        int n,j;
		        scanf("%d",&n);
		        if(n>=1&&n<=9)
		        { 
		            show2(list,n);
		        }
		        else if(n==0)
	           {
	       	        break;
		       }
		       else
		       {
		           printf("nnnSorry,未找到您想要查找的店铺信息~.~!nnn");
		       }
	        }
	        printf("n************************************************************************************n");
		} 	
		if(b=='#')
	  	{
	    	break;
	    } 
	}
	return 0;
}

	 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/971923.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号