C/C++课程设计

这篇博客详细介绍了C/C++课程设计的内容,包括单链表通讯录、简易树洞、职工管理系统、核酸管理系统等多个项目,涵盖了数据管理和简单应用的实现。
摘要由CSDN通过智能技术生成


前言

涵盖单链表通讯录,简易树洞,职工管理系统,核酸管理系统,学生信息管理系统,房屋信息管理系统,复数运算,计算器,旅游景点管理系统,模拟彩票系统,图书管理系统,万年历。

单链表通讯录

#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<windows.h>
//定义通讯录联系人结构体
typedef struct Person 
{
   
	char NAME[15];//姓名
	char GENDER[15];//性别
	char TEL[15];//电话
	char CITY[15];//城市
	char EIP[15];//邮编
}person;
//定义链表结构体
typedef struct node
{
   
	person ps;
	node* next;
}Linklist;
//初始化链表
void Initlist(Linklist*& L)
{
   
	L = (Linklist*)malloc(sizeof(Linklist));
	L->next = NULL;
}
//构建通讯录链表
void Crealist(Linklist*& L, person array[], int n)
{
   
	Linklist* p, * r;
	int i;
	r = L;
	for (i = 0; i < n; i++)
	{
   
		p = (Linklist*)malloc(sizeof(Linklist));
		p->ps = array[i];
		r->next = p;
		r = p;
	}
	r->next = NULL;
}
//添加联系人
bool Increlist(Linklist*& L, person e, int k)
{
   
	int j = 1;
	Linklist* p = L->next;
	while (p != 0 && j < k - 1)
	{
   
		p = p->next;
		j++;
	}
	if (p == 0)
		return 0;
	else
	{
   
		Linklist* s;
		s = (Linklist*)malloc(sizeof(Linklist));
		s->ps = e;
		s->next = p->next;
		p->next = s;
		return 1;
	}
}
//查找联系人
bool Researchlist(Linklist*& L, person e)
{
   
	Linklist* p;
	p = L->next;
	int k = 1;
	while (p && strcmp(e.NAME, p->ps.NAME) != 0)
	{
   
		p = p->next;
		k++;//查找联系人所在位置
	}
	if (!p)
	{
   
		printf("查找失败!!\n");
		return 0;
	}
	else
	{
   
		printf("查找成功!\n");
		printf("查找联系人所在位置是:%d\n", k);
		printf("找到此人\n");
		printf("姓名:%s\n", p->ps.NAME);
		printf("性别:%s\n", p->ps.GENDER);
		printf("电话:%s\n", p->ps.TEL);
		printf("城市:%s\n", p->ps.CITY);
		printf("邮编:%s\n", p->ps.EIP);
		return 1;
	}
}
//删除联系人
bool Deletelist(Linklist*& L, int i, person& e)
{
   
	int j = 1;
	Linklist* p = L->next;
	while (p && j < i - 1)
	{
   
		p = p->next;
		j++;
	}
	if (!p)
		return 0;
	else
	{
   
		Linklist* q = p->next;
		if (!q)
			return 0;
		else
		{
   
			e = p->ps;
			p->next = q->next;
			free(q);
			return 1;
		}
	}
}

//修改联系人
bool Alterlist(Linklist*& L, person e)
{
   
	Linklist* p = L->next;
	if (L != NULL)
	{
   
		
		while (p != NULL)
		{
   
			if (0 == strcmp(p->ps.NAME, e.NAME))
			{
   
				printf("请根据提示修改成员信息:\n");
				printf("请重新输入姓名\n");
				scanf("%s", p->ps.NAME);
				printf("请重新输入性别\n");
				scanf("%s", p->ps.GENDER);
				printf("请重新输入电话\n");
				scanf("%s", p->ps.TEL);
				printf("请重新输入城市\n");
				scanf("%s", p->ps.CITY);
				printf("请重新输入邮编\n");
				scanf("%s", p->ps.EIP);
				printf("修改成功。\n");
				return 1;
			}
			p = p->next;
		}

	}
	
	else
	{
   
		printf("目前通讯录为空。\n");
	}
	if (p == NULL)
	{
   
		printf("查无此人\n");
		return 0;
	}
}
//显示联系人
void Printlist(Linklist* L)
{
   
	Linklist* p = L->next;
	while (p)
	{
   
		printf("姓名:%s\t", p->ps.NAME);
		printf("性别:%s\t", p->ps.GENDER);
		printf("电话:%s\t", p->ps.TEL);
		printf("城市:%s\t", p->ps.CITY);
		printf("邮编:%s\n", p->ps.EIP);
		p = p->next;
	}
}
void Menu()
{
   
	printf("************************************* \n");
	printf("*************通讯录****************** \n");
	printf("********1.初始化通讯录*************** \n");
	printf("********2.构建通讯录***************** \n");
	printf("********3.添加联系人****************  \n");
	printf("********4.查找联系人***************** \n");
	printf("********5.删除联系人***************** \n");
	printf("********6.修改联系人***************** \n");
	printf("********7.输出通讯录***************** \n");
	printf("********0.退出通讯录***************** \n");
	printf("************************************* \n");
}
int main()
{
   
	Linklist* s;
	int m = 2; 
	person stu[2] = {
    {
   "张三","男","110","北京","1"},{
   "李四","男","120","上海","2"} };
	Menu();
	printf("1.通讯录的初始化\n");
	Initlist(s);
	printf("2.构建通讯录 \n");
	Crealist(s, stu, m);
	Printlist(s);
	
	while (true)
	{
   
		int select;
		printf("请选择你要的操作(3-7) \n");
		scanf("%d", &select);
		switch (select)
		{
   
		case 3:
			person w;
			int locate;
			printf("请输入联系人姓名:\n");
			scanf("%s", w.NAME);
			printf("请输入联系人性别:\n");
			scanf("%s", w.GENDER);
			printf("请输入联系人电话号码 \n");
			scanf("%s", w.TEL);
			printf("请输入联系人城市 \n");
			scanf("%s", w.CITY);
			printf("请输入联系人邮编:\n");
			scanf("%s", w.EIP);
			printf("请输入要添加的位置\n");
			scanf("%d", &locate);
			//添加联系人
			Increlist(s, w, locate);
			break;
		case 4:
			person e;
			printf("请输入你要查找的联系人姓名:\n");
			scanf("%s", e.NAME);
			//查找联系人
			Researchlist(s, e);
			break;
		case 5:
			int t;
			printf("请输入你要删除联系人的位置:\n");
			scanf("%d", &t);
			//删除联系人
			Deletelist(s, t, e);
			break;
		case 6:
			person x;
			printf("请输入你要修改的联系人姓名:\n");
			scanf("%s", x.NAME);
			//修改联系人
			Alterlist(s, x);
			break;
		case 7:
			//显示联系人
			Printlist(s);
			break;
		case 0://退出通讯录
			printf("退出通讯录!!!!\n");
			break;
		default:
			printf("输入错误!!!!\n");
			return 0;
		}
	}

	return 0;

}


简易树洞

#include<stdio.h>
#include<string.h>
#include<windows.h>
#define Max 2000
//设计便利贴结构体
struct Note
{
   
	//日期
	char Data[30];
	//内容
	char Information[30];
};

//设计便利贴系统结构体
struct NoteSystem
{
   
	//便利贴系统保存的便利贴数组
	struct Note noteArray[Max];
	//便利贴系统中当前记录便利贴个数
	int Size;
};

//显示菜单
void showMenu()
{
   
	printf( "******************************\n" );
	printf( "*****  1.写下你的便利贴  *****\n" );
	printf( "*****  2.显示你的便利贴  *****\n" );
	printf( "*****  3.查找你的便利贴  *****\n" );
	printf( "*****  4.修改你的便利贴  *****\n" );
	printf( "*****  5.删除你的便利贴  *****\n" );
	printf( "*****  0.退出管理系统    *****\n" );
	printf( "******************************\n" );
}
//1.写下你的便利贴
void addNote(struct NoteSystem* ns)
{
   
	//判断系统是否已满,如果满了就不在添加
	if (ns->Size == Max)
	{
   
		printf("便利贴已满 无法添加!\n");
	}
	else
	{
   
		//添加具体的便利贴
		printf("  *                  *  \n");
		printf(" *   写下你的便利贴   * \n");
		printf("*                      *\n");

		
		//日期
		char data[20];
		printf("请输入日期:\n");
		scanf("%s",data);
		strcpy(ns->noteArray[ns->Size].Data,data);


		//内容
		char information[20];
		printf("请输入便利贴信息:\n");
		scanf("%s",information);
		strcpy(ns->noteArray[ns->Size].Information,information);

		//更新职工系统人数
		ns->Size++;
		printf("添加成功\n");
		system("pause");
		system("cls");
	}
}


//2.显示所有便利贴信息
void showNote(struct NoteSystem* ns)
{
   


	//判断系统中信息是否为0,如果为0,提示记录为空
	if (ns->Size == 0)
	{
   
		printf("当前便利贴内容为空!\n");
	}
	else
	{
   
		printf("▄------------------------------- ▄\n");
		printf("▄        显示便利贴信息          ▄\n");
		printf("▄------------------------------- ▄\n");
		
		int i;
		for ( i = 0; i < ns->Size; i++)
		{
   
			printf("日期为:%s\n",ns->noteArray[i].Data);
			printf("便利贴的信息是:%s\n",ns->noteArray[i].Information);
		
		}
	}
	system("pause");
	system("cls");
}

int isFind(struct NoteSystem* ns, char *data)
{
   
	for (int i = 0; i < ns->Size; i++)
	{
   
		if (strcmp(ns->noteArray[i].Data,data)==0)//找到了
		{
   
			return i;
		}
	}
	return -1;//没找到
}

//3.查询职工信息
void findNote(struct NoteSystem* ns)
{
   
	printf("*-------------------------------*\n");
	printf("*--------查找便利贴信息---------*\n");
	printf("*-------------------------------*\n");



	printf("请输入待查找便利贴日期\n");

	char data[20];

	scanf("%s",data);
	int ret=isFind(ns,data);
	if (ret == -1)
	{
   
		printf("没有找到该便利贴\n");
	}
	else
	{
   
		printf("找到此便利贴\n");
		printf("日期为:%s\n",ns->noteArray[ret].Data);
		printf("便利贴的信息是:%s\n",ns->noteArray[ret].Information);

	}
	
	
	system("pause");
	system("cls");	
}
		
//4.修改便利贴信息
void modifyNote(struct NoteSystem* ns)
{
   
	printf("▄------------------------------- ▄\n");
    printf("▄        修改便利贴信息          ▄\n");
    printf("▄------------------------------- ▄\n");
		
	printf("请输入你要修改的便利贴日期\n");
	char data[20];

	scanf("%s",data);
	int ret=isFind(ns,data);
	if (ret == -1)
	{
   
		printf("没有找到该便利贴\n");
	}
	else
	{
   
		//日期
		char data[20];
		printf("请重新输入日期:\n");
		scanf("%s",data);
		strcpy(ns->noteArray[ret].Data,data);


		//内容
		char information[20];
		printf("请重新输入便利贴信息:\n");
		scanf("%s",information);
		strcpy(ns->noteArray[ret].Information,information);
		
	
		printf("修改成功\n");
	}
	system("pause");
	system("cls");
}
//5.删除职工信息
void deleteNote(struct NoteSystem* ns)
{
   
	printf("▄------------------------------- ▄\n");
	printf("▄        删除便利贴信息          ▄\n");
	printf("▄------------------------------- ▄\n");
	printf("请输入你要删除的日期\n");
	char data[20];

	scanf("%s",data);
	int ret=isFind(ns,data);
	if (ret != -1)
	{
   
		//找到此便利贴,进行删除
		for (int i = ret; i < ns->Size; i++)
		{
   
			//数据前移
			ns->noteArray[i] = ns->noteArray[i + 1];
		}
		ns->Size--;
		printf("删除成功\n");
	}
	else
	{
   
		printf("没有找到该便利贴\n");
	}
	system("pause");
	system("cls");
}
//登录系统
void loginSystem()
{
   
	char account[10] = "admin";
	char password[10] = "12345";

	char user_acc[10], user_ped[10];
	printf("*------------------------------*\n");
	printf("*-------欢迎使用人生树洞-------*\n");
	printf("*------------------------------*\n");
	int i;
	for (i = 0; i < 3; i++)
	{
   
		printf("请输入账号:");
		gets(user_acc);
		printf("请输入密码:");
		gets(user_ped);
		if ((strcmp(account, user_acc) == 0) && (strcmp(password, user_ped) == 0))
		{
   
			printf("验证成功!\n");
			printf("欢迎使用!\n");
			break;
		}
		else
			printf("账号或密码错误!\n");
	}
	if (i == 3)
	{
   

		printf("三次密码均错误 退出\n" );
		return;
	}
	system("pause");
	system("cls");
	
}
int main()
{
   
	loginSystem();

	//创建便利贴系统结构体变量
	struct NoteSystem ns;
	ns.Size = 0;
	int select = 0;//创建用户选择输入的变量
	while (true)
	{
   
		showMenu();
		scanf("%d",&select);
		switch (select)
		{
   
		case 1:// 1.写下你的便利贴
			addNote(&ns);
			break;
		case 2://2.显示你的便利贴
			showNote(&ns);
			break;
		case 3: //3.查找你的便利贴
			findNote(&ns);
			break;
		case 4://4.修改你的便利贴
			modifyNote(&ns);
			break;
		case 5://5.删除你的便利贴
			deleteNote(&ns);
			break;
		case 0://0.退出
			char heart[5][150]={
   
								"\t\t  _____   _                        _             ",
								"\t\t |_   _| | |_     __ _    _ _     | |__    ___     o O O   ",
								"\t\t   | |   | ' \\   / _` |  | ' \\    | / /   (_-<    o        ",
								"\t\t  _|_|_  |_||_|  \\__,_|  |_||_|   |_\\_\\   /__/_   o",
								"\t\t_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"|_|\"\"\"\"\"| {======| ",		
								};
			
					
				int i;
				printf("\n\n");
				for(i=0;i<5;i++)   //逐行打印
					printf("%s\n",heart[i]);
			
				printf("欢迎下次使用\n");
				return 0;
				break;
	
		}
	}
	return 0;
}

职工管理系统

#include<stdio.h>
#include<string.h>
#include<windows.h>
#define Max 2000
//设计职工结构体
struct Worker
{
   
	//职工号
	int Id;
	//姓名
	char Name[50];
	//性别(1 男 2 女 )
	int Sex;
	//出生年月
	long Data; 
	//学历
	char Education[50];
	//职务
	char Post[50];
	//工资
	int Money;
	//住址
	char Address[50];
	//电话
	char Phone[50];
};

//设计职工系统结构体
struct WorkerSystem
{
   
	//职工系统中保存的职工数组
	struct Worker workerArray[Max];
	//职工系统中当前记录职工个数
	int Size;
};

//显示菜单
void showMenu()
{
   
	printf( "****************************\n" );
	printf( "*****  1.录入职工信息  *****\n" );
	printf( "*****  2.显示职工信息  *****\n" );
	printf( "*****  3.查询职工信息  *****\n" );
	printf( "*****  4.修改职工信息  *****\n" );
	printf( "*****  5.删除职工信息  *****\n" );
	printf( "*****  0.退出管理系统  *****\n" );
	printf( "****************************\n" );
}
//1.录入职工信息
void addWorker(struct WorkerSystem* ws)
{
   
	//判断职工系统是否已满,如果满了就不在添加
	if (ws->Size == Max)
	{
   
		printf("职工系统已满 无法添加!\n");
	}
	else
	{
   
		//添加具体的职工

		//职工号
		int id;
		printf("请输入职工号:\n");
		scanf("%d",&id);
		ws->workerArray[ws->Size].Id = id;
		//姓名
		char name[20];
		printf("请输入职工姓名:\n");
		scanf("%s",name);
		strcpy(ws->workerArray[ws->Size].Name,name);

		//性别
		int sex = 0;
		printf("请输入职工性别:\n");
		printf("1 --- 男\n");
		printf("2 --- 女\n");
		while (true)
		{
   
			scanf("%d",&sex);
			if (sex == 1 || sex == 2)
			{
   
				ws->workerArray[ws->Size].Sex = sex;
				break;
			}
			else
			{
   
				printf("输入有误,请重新输入!\n");
			}
		}
		//出生年月
		long data; 
		printf("请输入职工出生年月:\n");
		scanf("%d",&data);
		ws->workerArray[ws->Size].Data = data;

		//学历
		char education[20];
		printf("请输入职工学历:\n");
		scanf("%s",education);
		strcpy(ws->workerArray[ws->Size].Education,education);
		//职务
		char post[20];
		printf("请输入职工职务:\n");
		scanf("%s",post);
		strcpy(ws->workerArray[ws->Size].Post,post);


		//工资
		int money;
		printf("请输入职工工资:\n");
		scanf("%d",&money);
		ws->workerArray[ws->Size].Money = money;


		//住址
		char address[20];
		printf("请输入职工住址:\n");
		scanf("%s",address);
		strcpy(ws->workerArray[ws->Size].Address,address);


		//电话
		char phone[20];
		printf("请输入职工电话:\n");
		scanf("%s",phone);
		strcpy(ws->workerArray[ws->Size].Phone,phone);

		//更新职工系统人数
		ws->Size++;
		printf("添加成功\n");
		system("pause");
		system("cls");
	}
}
//显示所有人
void show(struct WorkerSystem* ws)
{
   
	for (int i = 0; i < ws->Size; i++)
	{
   
		printf("职工号:%d\t",ws->workerArray[i].Id);
		printf("姓名:%s\t",ws->workerArray[i].Name);
		printf("性别:%s\t",(ws->workerArray[i].Sex == 1 ? "男" : "女"));
		printf("出生年月:%d\t",ws->workerArray[i].Data);
		printf("学历:%s\t",ws->workerArray[i].Education);
		printf("职务:%s\t",ws->workerArray[i].Post);
		printf("工资:%d\t",ws->workerArray[i].Money);
		printf("住址:%s\n",ws->workerArray[i].Address);
		printf("电话:%s\t",ws->workerArray[i].Phone );
	}
}
//显示特定的人
void showRet(struct WorkerSystem* ws,int ret)
{
   
	printf("找到此人\n");
	printf("职工号:%d\t",ws->workerArray[ret].Id);
	printf("姓名:%s\t",ws->workerArray[ret].Name);
	printf("性别:%s\t",(ws->workerArray[ret].Sex == 1 ? "男" : "女"));
	printf("出生年月:%d\t",ws->workerArray[ret].Data);
	printf("学历:%s\t",ws->workerArray[ret].Education);
	printf("职务:%s\t",ws->workerArray[ret].Post);
	printf("工资:%d\t",ws->workerArray[ret].Money);
	printf("住址:%s\t",ws->workerArray[ret].Address);
	printf("电话:%s\n",ws->workerArray[ret].Phone );
}
//2.显示所有职工信息
void showWorker(struct WorkerSystem* ws)
{
   
	//判断职工系统中人数是否为0,如果为0,提示记录为空
	if (ws->Size == 0)
	{
   
		printf("当前职工系统中人数为空!\n");
	}
	else
	{
   
		show(ws);
	}
	system("pause");
	system("cls");
}
//按id查找
int isFindID(struct WorkerSystem* ws, int id)
{
   
	for (int i = 0; i < ws->Size; i++)
	{
   
		if (ws->workerArray[i].Id == id)//找到了
		{
   
			return i;
		}
	}
	return -1;//没找到
}
//按姓名查找
int isFindNAME(struct WorkerSystem* ws, char *name)
{
   
	for (int i = 0; i < ws->Size; i++)
	{
   
		if (strcmp(ws->workerArray[i].Name , name)==0)//找到了
		{
   
			return i;
		}
	}
	return -1;//没找到
}

//3.查询职工信息
void findWorker(struct WorkerSystem* ws)
{
   
	printf("输入1按职工号查询\n");
	printf("输入2按姓名查询\n");
	int flag=0;
	scanf("%d",&flag);
	if(flag==1)
	{
   
		printf("请输入查找待查找职工号\n");
		int id;
		scanf("%d",&id);
		int ret=isFindID(ws,id);
		if (ret == -1)
		{
   
			printf("查无此人\n");
		}
		else
		{
   
			showRet(ws,ret);
		}
	}
	else if(flag==2)
	{
   
		printf("请输入查找待查找职工姓名\n");
		char name[20];
		scanf("%s",name);
		int ret=isFindNAME(ws,name);
		if (ret == -1)
		{
   
			printf("查无此人\n");
		}
		else
		{
   
			showRet(ws,ret);
		}
	}
	system("pause");
	system("cls");	
}
		
//4.修改职工信息
void modifyWorker(struct WorkerSystem* ws)
{
   
	printf("请输入你要修改的职工姓名\n");
	char name[20];
	scanf("%s",name);
	int ret = isFindNAME(ws, name);
	if (ret == -1)
	{
   
		printf("查无此人\n");
	}
	else
	{
   

		//职工号
		int id;
		printf("请重新输入职工号:\n");
		scanf("%d",&id);
		ws->workerArray[ret].Id = id;
		//姓名
		char name[20];
		printf("请重新输入职工姓名:\n");
		scanf("%s",name);
		strcpy(ws->workerArray[ret].Name,name);

		//性别
		int sex = 0;
		printf("请重新输入职工性别:\n");
		printf("1 --- 男\n");
		printf("2 --- 女\n");
		while (true)
		{
   
			scanf("%d",&sex);
			if (sex == 1 || sex == 2)
			{
   
				ws->workerArray[ret].Sex = sex;
				break;
			}
			else
			{
   
				printf("输入有误,请重新输入!\n");
			}
		}
		//出生年月
		long data; 
		printf("请重新输入职工出生年月:\n");
		scanf("%d",&data);
		ws->workerArray[ret].Data = data;

		//学历
		char education[20];
		printf("请重新输入职工学历:\n");
		scanf("%s",education);
		strcpy(ws->workerArray[ret].Education,education);
		//职务
		char post[20];
		printf("请重新输入职工职务:\n");
		scanf("%s",post);
		strcpy(ws->workerArray[ret].Post,post);


		//工资
		int money;
		printf("请重新输入职工工资:\n");
		scanf("%d",&money);
		ws->workerArray[ret].Money = money;


		//住址
		char address[20];
		printf("请重新输入职工住址:\n");
		scanf("%s",address);
		strcpy(ws->workerArray[ret].Address,address);


		//电话
		char phone[20];
		printf("请重新输入职工电话:\n");
		scanf("%s",phone);
		strcpy(ws->workerArray[ret].Phone,phone);
	
		printf("修改成功\n");
	}
	system("pause");
	system("cls");
}
//5.删除职工信息
void deleteWorker(struct WorkerSystem* ws)
{
   
	printf("请输入你要删除的职工姓名\n");
	char name[20];
	scanf("%s",name);
	int ret = isFindNAME(ws, name);//先查找此人是否存在
	if (ret != -1)
	{
   
		//找到此人,进行删除
		for (int i = ret; i < ws->Size; i++)
		{
   
			//数据前移
			ws->workerArray[i] = ws->workerArray[i + 1];
		}
		ws->Size--;
		printf("删除成功\n");
	}
	else
	{
   
		printf("查无此人\n");
	}
	system("pause");
	system("cls");
}
int main()
{
   
	//创建职工系统结构体变量
	struct WorkerSystem ws;
	ws.Size = 0;
	int select = 0;//创建用户选择输入的变量
	while (true)
	{
   
		showMenu();
		scanf("%d",&select);
		switch (select)
		{
   
		case 1:// 1.录入职工信息
			addWorker(&ws);
			break;
		case 2://2.显示职工信息
			showWorker(&ws);
			break;
		case 3: //3.查询职工信息
			findWorker(&ws);
			break;
		
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值