增删小系统(2day4)

fun.h文件

#ifndef __FUN_H__
#define __FUN_H__
#include <myhead.h>
#define SX 30//
#define AZ 30
#define MAX 30
typedef char ch[SX];
typedef struct 
{
	ch name;
	ch classm;
	int age;
	int score;
}stu;
typedef struct
{
	stu student[MAX];
	int len;
}rty,*prty;


prty fun0();//申请空间
void fun1(prty M);
void fun2(prty M);
void fun3(prty M);//按位插入
void fun4(prty M);
void my_free(prty M);
void look(prty M,int a,int b);//查看一定区域内的信息
#endif

fun.c文件

#include "fun.h"
prty fun0()//申请空间
{
	prty M=malloc(sizeof(rty));
		if(M==NULL)
		{
			printf("申请失败\n");
			return NULL;
		}
		else
		{
			M->len=0;//计数器初始化
			memset(M->student,0,sizeof(M->student));
				return M;
		}
}
void fun1(prty M)//输入信息
{
	printf("请输入学生信息:\n按照以下格式书写:\n姓名 班级 年龄 分数\n");
	scanf("%s%s%d%d",M->student[M->len].name,
			M->student[M->len].classm,&M->student[M->len].age,
			&M->student[M->len].score);
	M->len++;
	printf("len= %d\n",M->len);
}
void look(prty M,int a,int b)//查看一定区域内的信息
{
	int i;
	if(a>0||a<=MAX||b>0||b<=MAX)
	{
		if(a<b)
		{
			a^=b;
			b^=a;
			a^=b;
		}
		for(i=a-1;i<b;i++)
		{
			printf("姓名:%s\t班级:%s\t年龄:%d\t成绩:%d\n",
			M->student[i].name,
			M->student[i].classm,
			M->student[i].age,
			M->student[i].score);
		}
	}
}

void fun2(prty M)//全部查看
{
	int i;
for(i=0;i<M->len;i++)
		{
			printf("姓名:%s\t班级:%s\t年龄:%d\t成绩:%d\n",
			M->student[i].name,
			M->student[i].classm,
			M->student[i].age,
			M->student[i].score);
		}

}
void fun3(prty M)//按位插入
{
	printf("请输入要插入的位置:\n");
	int key,i;
	stu key1;
	scanf("%d",&key);
	if(key<0||key>M->len+1||key>MAX)
		{
		printf("你的输入有误\n");
	}
	else
	{
		printf("请输入要插入的内容:\n");
		printf("姓名:\t班级:\t年龄:\t成绩:\n");
		scanf("%s%s%d%d",key1.name,key1.classm,
			&key1.age,&key1.score);
		for(i=M->len;i>=key-1;i--)
		{
			M->student[i+1]=M->student[i];
		}
		M->student[key-1]=key1;
	}
	M->len++;
	
}

void fun4(prty M)
{
	int key ,i;
	printf("请输入要删除的位置:\n");
	scanf("%d",&key);
	if(key<0||key>M->len+1||key>MAX)
		{
		printf("你的输入有误\n");
	}
	else
	{

		for(i=key;i<M->len+1;i++)
		{
			M->student[i]=M->student[i+1];
		}
	}
	M->len--;
}
void my_free(prty M)
{
	free(M);
	M==NULL;
}

main.c文件

#include "fun.h"
int main(int argc, const char *argv[])

{
	int a;
	prty M=fun0();

while(1)
{
	printf("输入业务序号:\n");
	scanf("%d",&a);
	switch (a)
	{
		case 1:fun1(M);
			break;
		case 2:fun2(M);
			break;
		case 3:fun3(M);
			break;
		case 4:fun4(M);
			break;
		case 5:void my_free(M);
			break;
		default :printf("序号有误\n");
			break;
	}
}
	return 0;
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,由于篇幅限制,我无法在这里展示完整的Java代码。但我可以给你提供一个大致的代码框架,供你参考。 1. 用户管理 - 用户实体类 ``` public class User { private Long id; private String username; private String password; private String email; private String phoneNumber; // getter and setter } ``` - 用户登录控制器 ``` @Controller public class LoginController { @Autowired private UserService userService; @GetMapping("/login") public String login() { return "login"; } @PostMapping("/login") public String login(String username, String password, HttpSession session) { User user = userService.login(username, password); if (user != null) { session.setAttribute("user", user); return "redirect:/home"; } else { return "login"; } } } ``` 2. 账本管理 - 账单类型实体类 ``` public class BillType { private Long id; private String name; // getter and setter } ``` - 账单实体类 ``` public class Bill { private Long id; private BigDecimal amount; private Date date; private String remark; private BillType type; private User user; // getter and setter } ``` - 账单管理控制器 ``` @Controller public class BillController { @Autowired private BillService billService; @GetMapping("/bill") public String list(Model model) { List<Bill> bills = billService.getAllBills(); model.addAttribute("bills", bills); return "bill/list"; } @GetMapping("/bill/add") public String add(Model model) { List<BillType> types = billService.getAllBillTypes(); model.addAttribute("types", types); return "bill/add"; } @PostMapping("/bill/add") public String add(Bill bill, HttpSession session) { User user = (User) session.getAttribute("user"); bill.setUser(user); billService.addBill(bill); return "redirect:/bill"; } @GetMapping("/bill/edit/{id}") public String edit(@PathVariable Long id, Model model) { Bill bill = billService.getBillById(id); List<BillType> types = billService.getAllBillTypes(); model.addAttribute("bill", bill); model.addAttribute("types", types); return "bill/edit"; } @PostMapping("/bill/edit") public String edit(Bill bill) { billService.updateBill(bill); return "redirect:/bill"; } @GetMapping("/bill/delete/{id}") public String delete(@PathVariable Long id) { billService.deleteBill(id); return "redirect:/bill"; } } ``` 3. 账单管理 - 账单管理控制器 ``` @Controller public class BillManageController { @Autowired private BillService billService; @GetMapping("/bill/export/day") public void exportDayBill(Date date, HttpServletResponse response) { List<Bill> bills = billService.getDayBills(date); // 导出Excel或CSV文件 } @GetMapping("/bill/export/year") public void exportYearBill(Integer year, HttpServletResponse response) { List<Bill> bills = billService.getYearBills(year); // 导出Excel或CSV文件 } @GetMapping("/bill/statistics/year") public String statisticsYearBill(Integer year, Model model) { BigDecimal income = billService.getYearIncome(year); BigDecimal expense = billService.getYearExpense(year); model.addAttribute("income", income); model.addAttribute("expense", expense); return "bill/statistics"; } } ``` 4. 用户日常管理 - 日程实体类 ``` public class Schedule { private Long id; private String name; private Date date; private String remark; private User user; // getter and setter } ``` - 日程管理控制器 ``` @Controller public class ScheduleController { @Autowired private ScheduleService scheduleService; @GetMapping("/schedule") public String list(Model model) { List<Schedule> schedules = scheduleService.getAllSchedules(); model.addAttribute("schedules", schedules); return "schedule/list"; } @GetMapping("/schedule/add") public String add() { return "schedule/add"; } @PostMapping("/schedule/add") public String add(Schedule schedule, HttpSession session) { User user = (User) session.getAttribute("user"); schedule.setUser(user); scheduleService.addSchedule(schedule); return "redirect:/schedule"; } @GetMapping("/schedule/edit/{id}") public String edit(@PathVariable Long id, Model model) { Schedule schedule = scheduleService.getScheduleById(id); model.addAttribute("schedule", schedule); return "schedule/edit"; } @PostMapping("/schedule/edit") public String edit(Schedule schedule) { scheduleService.updateSchedule(schedule); return "redirect:/schedule"; } @GetMapping("/schedule/delete/{id}") public String delete(@PathVariable Long id) { scheduleService.deleteSchedule(id); return "redirect:/schedule"; } } ``` 5. 用户反馈管理 - 反馈实体类 ``` public class Feedback { private Long id; private String content; private User user; // getter and setter } ``` - 反馈管理控制器 ``` @Controller public class FeedbackController { @Autowired private FeedbackService feedbackService; @GetMapping("/feedback") public String add() { return "feedback/add"; } @PostMapping("/feedback") public String add(Feedback feedback, HttpSession session) { User user = (User) session.getAttribute("user"); feedback.setUser(user); feedbackService.addFeedback(feedback); return "redirect:/feedback"; } } ``` 以上只是一个大致的代码框架,具体实现还需要进一步细化和完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值