求利用C语言完成一个小型管理系统
发布网友
发布时间:2022-04-24 17:37
我来回答
共3个回答
热心网友
时间:2023-10-27 02:04
(1)
学生管理系统
/* main.c */
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "linkedlist.h"
#include "passwd.h"
#include "menu.h"
const char Grade[] = "年级";
const char StuID[] = "学号";
const char Name[] = "姓名";
const char Math[] = "数学";
const char Chinese[] = "语文";
const char English[] = "英语";
const char Total[] = "总成绩";
const char Average[] = "平均成绩";
#define MAIN_JUG(jug, n) (((n = strcmp(jug, "yes")) == 0) || ((n = strcmp(jug, "Yes")) == 0) || ((n = strcmp(jug, "Y")) == 0) || ((n = strcmp(jug, "y")) == 0))
struct node tails;
struct node heads = { NULL, NULL, &tails };
struct node tails = { NULL, &heads, NULL };
static link Head = &heads;
static link Tail = &tails;
void fprint_item(link p, FILE *f)
{
fprintf(f, "%-10s %-5d %-15s %-7.2f %-7.2f %-7.2f %-7.2f %-7.2f\n", p->item->grade, p->item->No, p->item->name, p->item->scores[0], p->item->scores[1], p->item->scores[2], p->item->total, p->item->aver);
return;
}
void print_item(link p)
{
printf("%-10s %-5d %-15s %-7.2f %-7.2f %-7.2f %-7.2f %-7.2f\n", p->item->grade, p->item->No, p->item->name, p->item->scores[0], p->item->scores[1], p->item->scores[2], p->item->total, p->item->aver);
}
void main_sort_menu(void)
{
printf("0.退出排序 \n"
"1.以年级排序 \n"
"2.以学生ID号排序 \n"
"3.以学生姓名排序 \n"
"4.以数学成绩排序 \n"
"5.以语文成绩排序 \n"
"6.以英语成绩排序 \n"
"7.以总成绩排序 \n"
"8.以平均成绩排序 \n"
);
return;
}
link main_pop(void)
{
if (Head->next == Tail)
return NULL;
else {
link p = Head->next;
link temp = Head->next;
temp->next->prev = Head;
Head->next = temp->next;
return p;
}
}
void main_output_file(void)
{
char file[30], jug[5];
int flag = 1;
int n;
FILE *fp = NULL;
link q = NULL;
printf("您想要保存所有学生的记录吗 (Y or N) ?: ");
if (scanf("%s", jug) < 0) {
perror("scanf");
exit(1);
}
if (MAIN_JUG(jug, n)) {
printf("请输入文件名: ");
if (scanf("%s", file) < 0) {
perror("scanf");
exit(1);
}
if ((fp = fopen(file, "w")) == NULL) {
perror("Open file stu_info");
exit(1);
}
fprintf(fp, "%-13s%-8s%-18s%-10s%-10s%-10s%-11s%-8s\n", Grade, StuID, Name, Math, Chinese, English, Total, Average);
while ((q = main_pop())) {
fprint_item(q, fp);
free(q->item);
q->prev = NULL;
q->next = NULL;
free(q);
}
fclose(fp);
while((q = main_pop())) {
free(q->item);
q->prev = NULL;
q->next = NULL;
free(q);
}
flag = 0;
}
else {
while((q = main_pop())) {
free(q->item);
q->prev = NULL;
q->next = NULL;
free(q);
}
}
return;
}
void partial_insert(int const n, link p)
{
if (Head->next == Tail) {
p->next = Head->next;
Head->next->prev = p;
p->prev = Head;
Head->next = p;
return;
}
link q = NULL;
switch (n) {
case 1:
for (q = Head->next; q != Tail; q = q->next) {
if (strcmp(p->item->grade, q->item->grade) < 0) {
p->next = q;
q->prev->next = p;
p->prev = q->prev;
q->prev = p;
return;
}
else {
if (q->next == Tail) {
p->next = q->next;
q->next->prev = p;
p->prev = q;
q->next = p;
return;
}
}
}
case 2:
for (q = Head->next; q != Tail; q = q->next) {
if (p->item->No < q->item->No) {
p->next = q;
q->prev->next = p;
p->prev = q->prev;
q->prev = p;
return;
}
else {
if (q->next == Tail) {
p->next = q->next;
q->next->prev = p;
p->prev = q;
q->next = p;
return;
}
}
}
case 3:
for (q = Head->next; q != Tail; q = q->next) {
if (strcmp(p->item->name, q->item->name) < 0) {
p->next = q;
q->prev->next = p;
p->prev = q->prev;
q->prev = p;
return;
}
else {
if (q->next == Tail) {
p->next = q->next;
q->next->prev = p;
p->prev = q;
q->next = p;
return;
}
}
}
case 4:
for (q = Head->next; q != Tail; q = q->next) {
if (p->item->scores[0] < q->item->scores[0]) {
p->next = q;
q->prev->next = p;
p->prev = q->prev;
q->prev = p;
return;
}
else {
if (q->next == Tail) {
p->next = q->next;
q->next->prev = p;
p->prev = q;
q->next = p;
return;
}
}
}
case 5:
for (q = Head->next; q != Tail; q = q->next) {
if (p->item->scores[1] < q->item->scores[1]) {
p->next = q;
q->prev->next = p;
p->prev = q->prev;
q->prev = p;
return;
}
else {
if (q->next == Tail) {
p->next = q->next;
q->next->prev = p;
p->prev = q;
q->next = p;
return;
}
}
}
case 6:
for (q = Head->next; q != Tail; q = q->next) {
if (p->item->scores[2] < q->item->scores[2]) {
p->next = q;
q->prev->next = p;
p->prev = q->prev;
q->prev = p;
return;
}
else {
if (q->next == Tail) {
p->next = q->next;
q->next->prev = p;
p->prev = q;
q->next = p;
return;
}
}
}
case 7:
for (q = Head->next; q != Tail; q = q->next) {
if (p->item->total < q->item->total) {
p->next = q;
q->prev->next = p;
p->prev = q->prev;
q->prev = p;
return;
}
else {
if (q->next == Tail) {
p->next = q->next;
q->next->prev = p;
p->prev = q;
q->next = p;
return;
}
}
}
case 8:
for (q = Head->next; q != Tail; q = q->next) {
if (p->item->aver < q->item->aver) {
p->next = q;
q->prev->next = p;
p->prev = q->prev;
q->prev = p;
return;
}
else {
if (q->next == Tail) {
p->next = q->next;
q->next->prev = p;
p->prev = q;
q->next = p;
return;
}
}
}
default:
printf("没有相应的功能!\n");
free(p->item);
p->prev = NULL;
p->next = NULL;
free(p);
return;
}
}
void sort_insert(int const n)
{
link p = NULL, q = NULL;
while ((p = fake_pop())) {
partial_insert(n, p);
}
printf("%-13s%-8s%-18s%-10s%-10s%-10s%-11s%-8s\n", Grade, StuID, Name, Math, Chinese, English, Total, Average);
for (q = Head->next; q != Tail; q = q->next)
print_item(q);
return;
}
void main_insert(void)
{
int flags = 1, func;
while (flags) {
main_sort_menu();
printf("请键入相应的功能号 : ");
if (scanf("%d", &func) < 0) {
perror("scanf");
exit(1);
}
switch (func) {
case 0:
main_output_file();
flags = 0;
break;
case 1:
sort_insert(1);
break;
case 2:
sort_insert(2);
break;
case 3:
sort_insert(3);
break;
case 4:
sort_insert(4);
break;
case 5:
sort_insert(5);
break;
case 6:
sort_insert(6);
break;
case 7:
sort_insert(7);
break;
case 8:
sort_insert(8);
break;
default:
fputs("没有此项功能,请重新输入!\n", stderr);
break;
}
}
return;
}
int main(void)
{
int ch, sys, flag = 1;
//while (1) {
if (passwd() < 0) {
fprintf(stderr, "密码错误!退出!.\n");
exit(-1);
}
printf(" "
"欢迎使用"
" 学生管理系统 !\n");
while (flag)
{
menu();
if (scanf("%d", &ch) < 0) {
perror("scanf");
exit(1);
}
switch (ch) {
case 0:
output_file();
flag = 0;
break;
case 1:
if((sys = system("clear")) == -1 || (sys = system("clear")) == 127)
puts("清屏失败");
link pin = make_node();
insert(pin);
break;
case 2:
if((sys = system("clear")) == -1 || (sys = system("clear")) == 127)
puts("清屏失败");
delete();
break;
case 3:
if((sys = system("clear")) == -1 || (sys = system("clear")) == 127)
puts("清屏失败");
printf("请输入相应的功能号来查找你要修改的学生记录 !\n");
char cmo;
int imo = 1, inimo = 1;
while (imo) {
link pmo = search();
if (pmo == NULL) {
printf("没有这个学生 !\n");
puts("你要继续查找修改吗 (y or n) ?:");
while (inimo) {
if (scanf("%c", &cmo) < 0) {
perror("scanf");
exit(1);
}
if (cmo == 'y'|| cmo == 'Y')
imo = 1, inimo = 0;
else if (cmo == 'n' || cmo == 'N')
imo = 0, inimo = 0;
else {
printf("请输入 \'Y\',\'y\',\'N\',\'n\' :");
imo = 1, inimo = 1;
}
}
}
else {
modify(pmo);
imo = 0;
}
}
break;
case 4:
if((sys = system("clear")) == -1 || (sys = system("clear")) == 127)
puts("清屏失败");
link pse = search();
if (pse == NULL) {
printf("没有这个学生!\n");
break;
}
printf("您要查找的学生信息:\n");
printf("%-13s%-8s%-18s%-10s%-10s%-10s%-11s%-8s\n", Grade, StuID, Name, Math, Chinese, English, Total, Average);
print_item(pse);
break;
case 5:
if((sys = system("clear")) == -1 || (sys = system("clear")) == 127)
puts("清屏失败");
main_insert();
break;
case 6:
if((sys = system("clear")) == -1 || (sys = system("clear")) == 127)
puts("清屏失败");
read_file();
printf("%-13s%-8s%-18s%-10s%-10s%-10s%-11s%-8s\n", Grade, StuID, Name, Math, Chinese, English, Total, Average);
traverse(print_item);
break;
case 7:
if((sys = system("clear")) == -1 || (sys = system("clear")) == 127)
puts("清屏失败");
printf("%-13s%-8s%-18s%-10s%-10s%-10s%-11s%-8s\n", Grade, StuID, Name, Math, Chinese, English, Total, Average);
traverse(print_item);
break;
case 8:
if((sys = system("clear")) == -1 || (sys = system("clear")) == 127)
puts("清屏失败");
int a[5][SJT] = { {0} };
pass_rate(a);
display_rate(a);
break;
default:
if((sys = system("clear")) == -1 || (sys = system("clear")) == 127)
puts("清屏失败");
fputs("没有此项功能 !\n", stderr);
break;
}
}
if((sys = system("reset")) == -1 || (sys = system("reset")) == 127)
puts("清屏失败");
return 0;
}
/* linkedlist.h */
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#define GRD 30 //年级最大的字符数(即年级字段最大长度)
#define NAM 40 //姓名的最大长度
#define SJT 3 //学科的数目
struct student
{
char grade[GRD];
int No;
char name[NAM];
float scores[SJT];
float total;
float aver;
};
typedef struct student *stu;
struct node
{
stu item;
struct node *prev;
struct node *next;
};
typedef struct node *link;
extern link make_node(void);
extern void free_node(link p);
extern link search(void);
extern void insert(link p);
extern void delete(void);
extern void modify(link p);
extern void traverse(void (*visit)(link));
extern void destroy(void);
extern link fake_pop(void);
extern link pop(void);
extern void read_file(void);
extern void output_file(void);
extern void pass_rate(int count[][SJT]);
extern void display_rate(int p[][SJT]);
#endif
热心网友
时间:2023-10-27 02:05
怎么用C语言设计一个小型仓库管理系统? 你是要接别人的活儿,还是在做课程设计,如果不是必须用c语言的话,还是建议你用VC加数据库,这样更简单 。如果必须只用c语言来做,那你就得定义一系列的结构体,然后把数据存储在文件里。如何在使用文件函数读写。你的图有点模糊,只能大体说一下思路。
热心网友
时间:2023-10-27 02:05
你是要接别人的活儿,还是在做课程设计,如果不是必须用c语言的话,还是建议你用VC加数据库,这样更简单 。如果必须只用c语言来做,那你就得定义一系列的结构体,然后把数据存储在文件里。
如何在使用文件函数读写。
你的图有点模糊,只能大体说一下思路。