求助C语言编译个人财务管理系统!(尽快啊)

Python019

求助C语言编译个人财务管理系统!(尽快啊),第1张

/******头文件(.h)***********/

#include "stdio.h" /*I/O函数*/

#include "stdlib.h" /*标准库函数*/

#include "string.h"/*字符串函数*/

#include "ctype.h" /*字符操作函数*/

#define M 200 /*定义常数表示记录数*/

typedef struct /*定义数据结构*/

{

char name[20]/*姓名*/

char units[30]/*单位*/

char tele[10]/*电话*/

char product_company[30]/* 生产厂家 */

char designer[30]/* 设计者 */

char price[10] /* 价格 */

char kucun[10] /* 库存量 */

char year[4]/* 出厂年份 */

char month[2] /* 出厂月份 */

char day[2] /* 出厂 */

}ADDRESS

/******以下是函数原型*******/

int enter(ADDRESS t[])/*输入记录*/

void list(ADDRESS t[],int n)/*显示记录*/

void search(ADDRESS t[],int n)/*按姓名查找显示记录*/

int delete(ADDRESS t[],int n)/*删除记录*/

int add(ADDRESS t[],int n)/*插入记录*/

void save(ADDRESS t[],int n)/*记录保存为文件*/

int load(ADDRESS t[])/*从文件中读记录*/

void display(ADDRESS t[])/*按序号查找显示记录*/

void sort(ADDRESS t[],int n)/*按姓名排序*/

void modify_price(ADDRESS t[],int n)/*快速查找记录*/

void copy()/*文件复制*/

void print(ADDRESS temp)/*显示单条记录*/

int find(ADDRESS t[],int n,char *s) /*查找函数*/

int menu_select()/*主菜单函数*/

/******主函数开始*******/

main()

{

int i

ADDRESS adr[M]/*定义结构体数组*/

int length=0/*保存记录长度*/

clrscr()/*清屏*/

for()/*无限循环*/

{

clrscr()/*清屏*/

switch(menu_select()) /*调用主菜单函数,返回值整数作开关语句的条件*/

{

case 0:length=enter(adr)break/*输入记录*/

case 1:list(adr,length)break/*显示全部记录*/

case 2:search(adr,length)break/*查找记录*/

case 3:length=delete(adr,length)break/*删除记录*/

case 4:length=add(adr,length)break/*插入记录*/

case 5:save(adr,length)break/*保存文件*/

case 6:modify_kucun(adr,length)break/*读文件*/

case 7:display(adr)break/*按序号显示记录*/

case 8:sort(adr,length)break/*按姓名排序*/

case 9:modify_kucun(adr,length)break/*快速查找记录*/

case 10:copy()break/*复制文件*/

case 11:exit(0)/*如返回值为11则程序结束*/

}

}

}

/*菜单函数,函数返回值为整数,代表所选的菜单项*/

menu_select()

{

char s[80]

int c

/*gotoxy(1,25)*//* 将光标定为在第25行,第1列*/

printf("press any key enter menu......\n")/*提示压任意键继续*/

getch()/*读入任意字符*/

clrscr()/*清屏*/

/*gotoxy(1,1)*/

printf("********************MENU*********************\n\n")

printf(" 0. Enter record\n")

printf(" 1. List the file\n")

printf(" 2. Search record on name\n")

printf(" 3. Delete a record\n")

printf(" 4. add record \n")

printf(" 5. Save the file\n")

printf(" 6. Modify kucun\n")

printf(" 7. Display record on order\n")

printf(" 8. Sort to make new file\n")

printf(" 9. Quick seek record\n")

printf(" 10. Copy the file to new file\n")

printf(" 11. Quit\n")

printf("***********************************************\n")

do{

printf("\n Enter you choice(0~11):")/*提示输入选项*/

scanf("%s",s) /*输入选择项*/

c=atoi(s) /*将输入的字符串转化为整型数*/

}while(c<0||c>11)/*选择项不在0~11之间重输*/

clrscr()/*清屏*/

return c/*返回选择项,主程序根据该数调用相应的函数*/

}

/***输入记录,形参为结构体数组,函数值返回类型为整型表示记录长度*/

int enter(ADDRESS t[])

{

int i,n

char *s

clrscr()/*清屏*/

do{

printf("\nHow many numbers do you want to record?\nplease input the numbers you wanted:\n")/*提示信息*/

scanf("%d",&n)/*输入记录数*/

if(n==0)

printf("the num couldn't be '0'!Please enter again!")

}while(n==0)

printf("please input record! \n")/*提示输入记录*/

printf("name|unit|telephone|product_company|designer|price|kucun|year|month|day\n")

printf("------------------------------------------------\n")

for(i=0i<ni++)

{

/*scanf("%s %s %s %s %s %s %s %s %s %s",t[i].name,t[i].units,t[i].tele,t[i].product_company,t[i].designer,t[i].price,t[i].kucun,t[i].year,t[i].month,t[i].day)*//*输入记录*/

printf("name:")/* 打印输出号码 */

scanf("%s",&t[i].name)/* 用数组输入号码 */

printf("unit:")/* 打印输出名字 */

scanf("%s",&t[i].units)/* 用数组输入姓名 */

printf("telephone:")/* 打印输出性别 */

scanf("%s",&t[i].tele)/* 用数组输入性别 */

printf("product_company:")/* 打印输出生日 */

scanf("%s",&t[i].product_company)/* 用数组输入生日 */

printf("designer:")/* 打印输出婚姻状况 */

scanf("%s",&t[i].designer)/* 用数组输入婚姻状况 */

printf("price:")/* 打印输出工作状况 */

scanf("%s",&t[i].price)/* 用数组输入工作状况 */

printf("kucun:")/* 打印输出工作状况 */

scanf("%s",&t[i].kucun)/* 用数组输入工作状况 */

printf("produce year:")/* 打印输出工作状况 */

scanf("%s",&t[i].year)/* 用数组输入工作状况 */

printf("produce month:")/* 打印输出工作状况 */

scanf("%s",&t[i].month)/* 用数组输入工作状况 */

printf("produce day:")/* 打印输出工作状况 */

scanf("%s",&t[i].day)/* 用数组输入工作状况 */

printf("-----------Ok!this record have been recorded!------------\n")

}

printf("the all have been recorded!\n")

getch()

clrscr()

return n/*返回记录条数*/

}

/*显示记录,参数为记录数组和记录条数*/

void list(ADDRESS t[],int n)

{

int i

clrscr()

printf("\n\n*******************ADDRESS******************\n")

printf("name|unit|telephone|product_company|designer|price|kucun|year|month|day\n")

printf("------------------------------------------------------------------------\n")

if(n!=0)

for(i=0i<ni++)

{

printf("%s/%s/%s/%s/%s/%s/%s/%s/%s/%s",t[i].name,t[i].units,t[i].tele,t[i].product_company,t[i].designer,t[i].price,t[i].kucun,t[i].year,t[i].month,t[i].day)

if((i+1)%10==0) /*判断输出是否达到10条记录*/

{

printf("Press any key continue...\n")/*提示信息*/

getch()/*压任意键继续*/

}

}

else printf("there is no record!\n")

printf("************************end*******************\n")

}

/*查找记录*/

void search(ADDRESS t[],int n)

{

char s[20]/*保存待查找姓名字符串*/

int i/*保存查找到结点的序号*/

/*clrscr()*/

printf("please input the search name:\n")

scanf("%s",s)/*输入待查找姓名*/

i=find(t,n,s)/*调用find函数,得到一个整数*/

if(i>n-1) /*如果整数i值大于n-1,说明没找到*/

printf("not found!\n")

else

print(t[i])/*找到,调用显示函数显示记录*/

clrscr()

}

/*显示指定的一条记录*/

void print(ADDRESS temp)

{

/* clrscr() */

printf("\n\n********************************************\n")

printf("name|unit|telephone|product_company|designer|price|kucun|year|month|day\n")

/*printf("------------------------------------------------\n")*/

printf("%s/%s/%s/%s/%s/%s/%s/%s/%s/%s",temp.name,temp.units,temp.tele,temp.product_company,temp.designer,temp.price,temp.kucun,temp.year,temp.month,temp.day)

printf("**********************end***********************\n")

}

/*查找函数,参数为记录数组和记录条数以及姓名s */

int find(ADDRESS t[],int n,char *s)

{

int i

for(i=0i<ni++)/*从第一条记录开始,直到最后一条*/

{

if(strcmp(s,t[i].name)==0) /*记录中的姓名和待比较的姓名是否相等*/

return i/*相等,则返回该记录的下标号,程序提前结结束*/

}

return i/*返回i值*/

}

/*删除函数,参数为记录数组和记录条数*/

int delete(ADDRESS t[],int n)

{

char s[20]/*要删除记录的姓名*/

int ch=0

int i,j

printf("please deleted name\n")/*提示信息*/

scanf("%s",s)/*输入姓名*/

i=find(t,n,s)/*调用find函数*/

if(i>n-1) /*如果i>n-1超过了数组的长度*/

printf("no found not deleted\n")/*显示没找到要删除的记录*/

else

{

print(t[i])/*调用输出函数显示该条记录信息*/

printf("Are you sure delete it(1/0)\n")/*确认是否要删除*/

scanf("%d",&ch)/*输入一个整数0或1*/

if(ch==1) /*如果确认删除整数为1*/

{

for(j=i+1j<nj++) /*删除该记录,实际后续记录前移*/

{

strcpy(t[j-1].name,t[j].name)/*将后一条记录的姓名拷贝到前一条*/

strcpy(t[j-1].units,t[j].units)/*将后一条记录的单位拷贝到前一条*/

strcpy(t[j-1].tele,t[j].tele)/*将后一条记录的电话拷贝到前一条*/

strcpy(t[j-1].product_company,t[j].product_company)

strcpy(t[j-1].designer,t[j].designer)

strcpy(t[j-1].price,t[j].price)

strcpy(t[j-1].kucun,t[j].kucun)

strcpy(t[j-1].year,t[j].year)

strcpy(t[j-1].month,t[j].month)

strcpy(t[j-1].day,t[j].day)

}

n--/*记录数减1*/

}

}

return n/*返回记录数*/

}

/*插入记录函数,参数为结构体数组和记录数*/

int add(ADDRESS t[],int n)/*插入函数,参数为结构体数组和记录数*/

{

ADDRESS temp/*新插入记录信息*/

int i,j

char s[20],p/*确定插入在哪个记录之前*/

printf("please input the new record:\n")

printf("************************************************\n")

printf("name|unit|telephone|product_company|designer|price|kucun|year|month|day\n")

/*printf("--------------------------------------------------\n")

scanf("%s%s%s",temp.name,temp.units,temp.tele)*//* 输入插入信息*/

printf("name:")/* 打印输出号码 */

scanf("%s",&temp.name)/* 用数组输入号码 */

printf("unit:")/* 打印输出名字 */

scanf("%s",&temp.units)/* 用数组输入姓名 */

printf("telephone:")/* 打印输出性别 */

scanf("%s",&temp.tele)/* 用数组输入性别 */

printf("product_company:")/* 打印输出生日 */

scanf("%s",&temp.product_company)/* 用数组输入生日 */

printf("designer:")/* 打印输出婚姻状况 */

scanf("%s",&temp.designer)/* 用数组输入婚姻状况 */

printf("price:")/* 打印输出工作状况 */

scanf("%s",&temp.price)/* 用数组输入工作状况 */

printf("kucun:")/* 打印输出工作状况 */

scanf("%s",&temp.kucun)/* 用数组输入工作状况 */

printf("produce year:")/* 打印输出工作状况 */

scanf("%s",&temp.year)/* 用数组输入工作状况 */

printf("produce month:")/* 打印输出工作状况 */

scanf("%s",&temp.month)/* 用数组输入工作状况 */

printf("produce day:")/* 打印输出工作状况 */

scanf("%s",&temp.day)/* 用数组输入工作状况 */

printf("-----------Ok!this record have been recorded!------------\n")

printf("------------------------------------------------\n")

K:printf("please input the wanted name's position to insert:\n")

scanf("%s",s)/*输入插入位置的姓名*/

i=find(t,n,s)/*调用find,确定插入位置*/

if(i>n-1) /*如果i>n-1超过了数组的长度*/

{

printf("the name isn't exist!\n")/*显示没找到要删除的记录*/

printf("Are you want to continue to insert?Yes--y/No--any other key!\n")

if(getch()=='y') goto K

}

else

{

for(j=n-1j>=ij--) /*从最后一个结点开始向后移动一条*/

{

strcpy(t[j+1].name,t[j].name)/*当前记录的姓名拷贝到后一条*/

strcpy(t[j+1].units,t[j].units)/*当前记录的单位拷贝到后一条*/

strcpy(t[j+1].tele,t[j].tele)/*当前记录的电话拷贝到后一条*/

strcpy(t[j+1].product_company,t[j].product_company)

strcpy(t[j+1].designer,t[j].designer)

strcpy(t[j+1].price,t[j].price)

strcpy(t[j+1].kucun,t[j].kucun)

strcpy(t[j+1].year,t[j].year)

strcpy(t[j+1].month,t[j].month)

strcpy(t[j+1].day,t[j].day)

}

strcpy(t[i].name,temp.name)/*将新插入记录的姓名拷贝到第i个位置*/

strcpy(t[i].units,temp.units)/*将新插入记录的单位拷贝到第i个位置*/

strcpy(t[i].tele,temp.tele)/*将新插入记录的电话拷贝到第i个位置*/

strcpy(t[i].product_company,temp.product_company)

strcpy(t[i].designer,temp.designer)

strcpy(t[i].price,temp.price)

strcpy(t[i].kucun,temp.kucun)

strcpy(t[i].year,temp.year)

strcpy(t[i].month,temp.month)

strcpy(t[i].day,temp.day)

n++/*记录数加1*/

return n/*返回记录数*/

}

}

/*保存函数,参数为结构体数组和记录数*/

void save(ADDRESS t[],int n)

{

int i

FILE *fp/*指向文件的指针*/

if((fp=fopen("record.txt","wb"))==NULL) /*打开文件,并判断打开是否正常*/

{

printf("can not open file\n")/*没打开*/

exit(1)/*退出*/

}

printf("\nSaving file now!\n")/*输出提示信息*/

fprintf(fp,"there is %d records!",n)/*将记录数写入文件*/

fprintf(fp,"\r\n")/*将换行符号写入文件*/

for(i=0i<ni++)

{

fprintf(fp,"%s/%s/%s/%s/%s/%s/%s/%s/%s/%s",t[i].name,t[i].units,t[i].tele,t[i].product_company,t[i].designer,t[i].price,t[i].kucun,t[i].year,t[i].month,t[i].day)/*格式写入记录*/

fprintf(fp,"\r\n")/*将换行符号写入文件*/

}

fclose(fp)/*关闭文件*/

printf("****save success***\n")/*显示保存成功*/

}

/*读入函数,参数为结构体数组*/

/* int load(ADDRESS t[]) */

/* { */

/* int i,n*/

/* FILE *fp*//*指向文件的指针*/

/* if((fp=fopen("record.txt","rb"))==NULL)*//* 打开文件*/

/*{ */

/*printf("can not open file\n")*//*不能打开*/

/*exit(1)*//*退出*/

/*} */

/* fscanf(fp,"%d",&n)*/ /*读入记录数*/

/* for(i=0i<ni++) */

/* fscanf(fp,"%20s%30s%10s",t[i].name,t[i].units,t[i].tele)*/ /*按格式读入记录*/

/* fclose(fp)*/ /*关闭文件*/

/* printf("You have success read data from file!!!\n")*//* 显示保存成功*/

/* return n*/ /*返回记录数*/

/* } */

/*按序号显示记录函数*/

int modify_kucun(ADDRESS t[],int n)

{

char s[20],ch[10]/*保存待查找姓名字符串*/

int i,j/*保存查找到结点的序号*/

/*clrscr()*/

printf("please input the cloth name which you wanted to modify its kucun:\n")

scanf("%s",s)/*输入待查找姓名*/

i=find(t,n,s)/*调用find函数,得到一个整数*/

if(i>n-1) /*如果整数i值大于n-1,说明没找到*/

printf("sorry!the name don't exist!\n")

else

{

print(t[i])/*找到,调用显示函数显示记录*/

/*printf("Are you sure to modify its kucun?Yes--y/")*/

printf("please input the new kucun you want:\n")

scanf("%c",ch)

for(j=0j<10j++)

t[i].kucun[j]=ch[j]

printf("Ok!the kucun has been modified!")

}

clrscr()

}

void display(ADDRESS t[])

{

int id,n

FILE *fp/*指向文件的指针*/

if((fp=fopen("record.txt","rb"))==NULL) /*打开文件*/

{

printf("can not open file\n")/*不能打开文件*/

exit(1)/*退出*/

}

printf("Enter order number:\n")/*显示信息*/

scanf("%d",&id)/*输入序号*/

fscanf(fp,"%d",&n)/*从文件读入记录数*/

if(id>=0&&id<n) /*判断序号是否在记录范围内*/

{

fseek(fp,(id-1)*sizeof(ADDRESS),1)/*移动文件指针到该记录位置*/

print(t[id])/*调用输出函数显示该记录*/

printf("\r\n")

}

else

printf("no %d number record!!!\n ",id)/*如果序号不合理显示信息*/

fclose(fp)/*关闭文件*/

}

/*排序函数,参数为结构体数组和记录数*/

void sort(ADDRESS t[],int n)

{

int i,j,flag

char y

ADDRESS temp/*临时变量做交换数据用*/

R: printf("Please select which kind to sort!0--sort by kucun/1--sort by Chu_Chang_Ri_Qi\n ")/*选择何种方式排序*/

if(getch()=='0')

{

for(i=0i<ni++)

{

flag=0/*设标志判断是否发生过交换*/

for(j=0j<n-1j++)

if((strcmp(t[j].kucun,t[j+1].kucun))>0) /*比较大小*/

{

flag=1

strcpy(temp.name,t[j].name)/*交换记录*/

strcpy(temp.units,t[j].units)

strcpy(temp.tele,t[j].tele)

strcpy(temp.product_company,t[j].product_company)

strcpy(temp.designer,t[j].designer)

strcpy(temp.price,t[j].price)

strcpy(temp.kucun,t[j].kucun)

strcpy(temp.year,t[j].year)

strcpy(temp.month,t[j].month)

strcpy(temp.day,t[j].day)

strcpy(t[j].name,t[j+1].name)

strcpy(t[j].units,t[j+1].units)

strcpy(t[j].tele,t[j+1].tele)

strcpy(t[j].product_company,t[j+1].product_company)

strcpy(t[j].designer,t[j+1].designer)

strcpy(t[j].price,t[j+1].price)

strcpy(t[j].kucun,t[j+1].kucun)

strcpy(t[j].year,t[j+1].year)

strcpy(t[j].month,t[j+1].month)

strcpy(t[j].day,t[j+1].day)

strcpy(t[j+1].name,temp.name)

strcpy(t[j+1].units,temp.units)

strcpy(t[j+1].tele,temp.tele)

strcpy(t[j+1].product_company,temp.product_company)

strcpy(t[j+1].designer,temp.designer)

strcpy(t[j+1].price,temp.price)

strcpy(t[j+1].kucun,temp.kucun)

strcpy(t[j+1].year,temp.year)

strcpy(t[j+1].month,temp.month)

strcpy(t[j+1].day,temp.day)

}

if(flag==0) break/*如果标志为0,说明没有发生过交换循环结束*/

}

printf("sort sucess!!!\n")/*显示排序成功*/

}

else

if(getch()=='1')

{

for(i=0i<ni++)

{

flag=0/*设标志判断是否发生过交换*/

for(j=0j<n-1j++)

/* if((()&&((strcmp(t[j].month,t[j+1].month))>0)))

&&((strcmp(t[j].day,t[j+1].day))>0))||

(((strcmp(t[j].year,t[j+1].year))=0)&&((strcmp(t[j].month,t[j+1].month))>0))||

(((strcmp(t[j].year,t[j+1].year))=0)&&((strcmp(t[j].month,t[j+1].month))=0)&&((strcmp(t[j].day,t[j+1].day))>0))) *//*比较大小*/

if(( ((strcmp(t[j].year,t[j+1].year))>0)&&((strcmp(t[j].month,t[j+1].month))>0)&&((strcmp(t[j].day,t[j+1].day))>0) )||

( ((strcmp(t[j].year,t[j+1].year))==0)&&((strcmp(t[j].month,t[j+1].month))>0) )||

( ((strcmp(t[j].year,t[j+1].year))==0)&&((strcmp(t[j].month,t[j+1].month))==0)&&((strcmp(t[j].day,t[j+1].day))>0) ))

{

flag=1

strcpy(temp.name,t[j].name)/*交换记录*/

#include<stdio.h>

#include<string.h>

#include<graphics.h>

#include<stdlib.h>

#include<conio.h>

#define NULL 0

#define LEN sizeof(struct finance)

#define SETCODE 000000

#define SETUSER ******

/*定义结构体,结构体变量包括序号num,日期date,来源state,生活费receive,消费spend,结余save*/

struct finance

{int num

char date[10]

char state[20]

int receive

int spend

int save

struct finance *next

}

/*函数申明*/

void login()

void win()

void init()

void loginerror()

void direct()

struct finance *creat (void)

void save()

void saveover()

void view()

void viewdraw()

void viewall()

void viewdate()

void viewnum()

void analyse()

int smax()

int smin()

void print(struct finance *p)

int n /*定义一个短整型全局变量记录输入数据条数,而且还可以用于容错处理 */

struct finance **use/*定义结构体型二级指针*/

char ch /*定义字符型全局变量,接收控制字符,以进行窗口切换*/

void main()

{login()

direct()

while(ch!='4')

{switch(ch)

{case'1':*use=creat()break /*direct函数调用后如按下1,调用链表创建函数,记录当前信息*/

case'2':save()break /*direct函数调用后如按下2,调用保存文件函数将链表保存为文件*/

case'3':view()break /*direct函数调用后如按下3,调用查看函数将文件信息输出*/

default:printf("no effect!!!")

}

direct()

}

/*if ch=4,quit*/

}

void direct()

{

init() /*图形函数初始化*/

cleardevice() /*清屏*/

setbkcolor(MAGENTA)/*设置背景颜色为洋红*/

setcolor(BLUE)/*设置当前颜色为蓝色*/

rectangle(20,40,620,400)/*画矩形框*/

rectangle(40,80,600,380)

outtextxy(300,90,"operate")/*图形文本输出,定位输出*/

bar(200,140,240,160)/*条形图,突出显示*/

outtextxy(200,150,"input")

outtextxy(380,150,"press 1!!!")

bar(200,180,240,200)

outtextxy(200,190,"save")

outtextxy(380,190,"press 2!!!")

bar(200,220,240,240)

outtextxy(200,230,"view")

outtextxy(380,230,"press 3!!!")

bar(200,260,240,280)

outtextxy(200,270,"quit")

outtextxy(380,270,"press 4!!!")

ch=getch()/*ch接收字符*/

closegraph()

}

void login()

{char user[10],setuser[]={"SETUSER"},code[10],setcode[]={"SETCODE"}

int flag=0,i

do

{if(flag) loginerror()

init()

cleardevice()

setbkcolor(LIGHTBLUE)

setcolor(RED)

rectangle(180,80,400,200)

outtextxy(220,100,"ID:")

outtextxy(220,120,"username:")

for(i=0i<6i++)

{user[i]=getch()fflush(stdin)}

outtextxy(220,140,user)

outtextxy(220,160,"code:")

for(i=0i<6i++)

{code[i]=getch()

outtextxy(220+5*i,180,"*")

}

flag++

}while(!strcmp(user,setuser)||!strcmp(code,setcode))/*当用户名和密码都正确时循环结束*/

getch()

closegraph()

win()

}

void loginerror() /*当输入的用户名或密码不正确时,调用*/

{

init()

cleardevice()

setbkcolor(DARKGRAY)

setcolor(YELLOW)

rectangle(100,60,540,380)

outtextxy(240,140,"username")

outtextxy(240,220,"or code")

outtextxy(240,300,"not correct!!!")

getch()

closegraph()

}

void win()

{

init()

cleardevice()

setbkcolor(BROWN)

setcolor(GREEN)

rectangle(20,40,620,400)

outtextxy(150,160,"**********************************************")

outtextxy(150,190,"welcome to personal fiance manager system!!!")

outtextxy(150,220,"*********************************************")

getch()

closegraph()

}

void init() /*图形模式初始化*/

{int gdrive,gmode

gdrive=DETECT/*自动检测硬件驱动*/

gmode=CGAC0

initgraph(&gdrive,&gmode,"")

}