⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 个人日常开支管理系统.c

📁 一、目的意义: 1.掌握软件工程原理在实际系统开发中的具体应用
💻 C
字号:
/*头文件*/
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <bios.h>

/*所有函数声明*/
int t();
void design();
void show_mouse();

void entry();
void ventry(char t[],int);

void search();
void search_date();
void search_name();

void display();

void del();
void deletion_name();
void deletion_date();

int delete_file();

void graph();
void graph1();
void graph2();
void bar1(int inscor1);
void bar2(int inscore2);


struct shop
{
	char name[20];
	int quantity;
	float sale;
	char id[10];
	float total;
};

struct shop temp;
struct shop x[20];

FILE *ptr;
char a[10];

/*显示当前时间函数*/
int t(void)
{
   time_t t;   
   time(&t);
   gotoxy(24,21);
   printf("Date: %s\n", ctime(&t));
   return 0;
}

/*显示光标位置函数*/
void show_mouse(void)
{
	union REGS in, out;
	in.x.ax = 0x1;
	int86(0x33, &in, &out);
}

/*程序框架函数*/
void design()
{
    int i;
    clrscr();
	textcolor(14);
	gotoxy(2,2);
	cprintf("\xC9");
	gotoxy(3,2);
       for(i=1;i<=74;i++)
       cprintf("\xCD");
	gotoxy(77,2);
	cprintf("\xBB");
	gotoxy(2,3);
	cprintf("\xBA");gotoxy(2,4);cprintf("\xBA");gotoxy(2,5);cprintf("\xBA");
	gotoxy(2,6);cprintf("\xBA");gotoxy(2,7);cprintf("\xBA");gotoxy(2,8);cprintf("\xBA");
	gotoxy(2,9);cprintf("\xBA");gotoxy(2,10);cprintf("\xBA");gotoxy(2,11);cprintf("\xBA");gotoxy(2,12);cprintf("\xBA");
	gotoxy(2,13);cprintf("\xBA");gotoxy(2,14);cprintf("\xBA");gotoxy(2,15);cprintf("\xBA");gotoxy(2,16);cprintf("\xBA");
	gotoxy(2,17);cprintf("\xBA");gotoxy(2,18);cprintf("\xBA");gotoxy(2,22);cprintf("\xCC");

	gotoxy(2,19);cprintf("\xBA");gotoxy(2,20);cprintf("\xBA");gotoxy(2,21);cprintf("\xBA");gotoxy(2,24);cprintf("\xC8");
	gotoxy(2,23);cprintf("\xBA");
	gotoxy(3,24);
	for(i=1;i<=74;i++)
	cprintf("\xCD");
	gotoxy(77,18);cprintf("\xBA");gotoxy(77,19);cprintf("\xBA");gotoxy(77,20);cprintf("\xBA");gotoxy(77,21);cprintf("\xBA");gotoxy(77,24);cprintf("\xBC");
	gotoxy(77,23);
	cprintf("\xBA");
	gotoxy(3,22);
	for(i=1;i<=74;i++)
	cprintf("\xCD");
	gotoxy(77,22);
	cprintf("\xB9");
	gotoxy(77,3);
	cprintf("\xBA");gotoxy(77,4);cprintf("\xBA");gotoxy(77,5);cprintf("\xBA");
	gotoxy(77,6);cprintf("\xBA");gotoxy(77,7);cprintf("\xBA");gotoxy(77,8);cprintf("\xBA");
	gotoxy(77,9);cprintf("\xBA");gotoxy(77,10);cprintf("\xBA");gotoxy(77,11);cprintf("\xBA");gotoxy(77,12);cprintf("\xBA");
	gotoxy(77,13);cprintf("\xBA");gotoxy(77,14);cprintf("\xBA");gotoxy(77,15);cprintf("\xBA");gotoxy(77,16);cprintf("\xBA");
	gotoxy(77,17);cprintf("\xBA");
    textcolor(4);
}

/*=================把接受的字符串类型转换整型或浮点型=================*/
void ventry(char t[],int code)
{
  int i=0;
  if(code==0)
  {

    while((t[i]=getch())!='\r' && i<30)
     if((t[i]>=97 && t[i]<=122) || (t[i]>=65 && t[i]<=90) || t[i]==32 || t[i]==8)
      {	printf("%c",t[i]);
	i++;
	}
      }
  else if(code==1)
  {
    while((t[i]=getch())!='\r' && i<10)
     if((t[i]>=48 && t[i]<=57) || t[i]==46 || t[i]==8 )
      {	printf("%c",t[i]);
	i++;
	}
      }
  t[i]='\0';
}


/*============1.增加记录函数===================*/
void entry()
{
   char ch;
  clrscr();

	   ptr=fopen("shop.dat","a+b");/*运行程序时就建立shop.dat文件*/
  ch='y';
  while(ch=='y')
 {
  clrscr();
  design();
  textcolor(14);
  t();
  gotoxy(14,3);
  cprintf("\xDB\xDB\xDB\xDB\xDB\xB2  Product Infomation  \xB2\xDB\xDB\xDB\xDB\xDB ");
   {
     gotoxy(7,5);
    cprintf("\xDB\xDB\xB2  Enter Date: ");
     ventry(temp.id,1);
     flushall();
     
     gotoxy(7,8);
     cprintf("\xDB\xDB\xB2 Enter Name: ");
     ventry(temp.name,0);
     flushall();

     gotoxy(7,11);
     cprintf("\xDB\xDB\xB2  Enter Price(RMB): ");
     ventry(a,1);
    temp.sale= atof(a);
     flushall();

     gotoxy(7,14);
     cprintf("\xDB\xDB\xB2  Enter Quantity:  ");
     ventry(a,1);
    temp.quantity= atoi(a);
     flushall();

     gotoxy(7,16);
     cprintf("=====================================");
     temp.total=temp.quantity*temp.sale;

     textcolor(10);
     gotoxy(10,18);
     cprintf("\xB2\xDB\xB2  Total Money = %.2f RMB",temp.total);
   }
  fwrite(&temp,sizeof(temp),1,ptr);
  textcolor(10);
  gotoxy(10,23);
  cprintf("More entries  [Y/N]");
  ch=getche();
 }
fclose(ptr);
}


/*===================2.查找主函数================*/
void search()
{
  int sh;
  clrscr();
	  design();
	  gotoxy(17,6);
	  printf("\xDB\xDB\xB2  Two options available to search \xB2\xDB\xDB");
	  gotoxy(15,9);
	  printf("[ 1 ]  -  Search by Date.");
	  gotoxy(15,11);
	  printf("[ 2 ]  -  Search by Name.");
	  gotoxy(17,15);
	  printf("Enter your choice:");
	  sh=toupper(getch());

  switch(sh)
  {
    case '1':
    search_date();
    break;

    case '2':
    search_name();
    break;

    default:
    gotoxy(18,18);
    printf("\a\xDB\xDB Please try again");
    getch();
   }
  getche();
}


/*=================2_1按日期查找=====================*/
void search_date()
{
  int flag=0;
  char lkf[20];
	   clrscr();
	   ptr=fopen("shop.dat","rb");
	   design();
	   gotoxy(13,4);
	   printf("\xDB\xDB\xB2  Enter date to be searched:");
	   scanf("%s",&lkf);
  while((!flag)&&(fread(&temp,sizeof(temp),1,ptr))==1)
  {
      if(strcmp(temp.id,lkf)==0)
      flag=1;
  }
     if(flag)
  {
	 gotoxy(18,6);
	 printf("Date    :%s",temp.id);
	 gotoxy(18,9);
	 printf("Name    :%s",temp.name);
	 gotoxy(18,12);
	 printf("Price   :%.2f",temp.sale);
	 gotoxy(18,15);
	 printf("Quantity:%d",temp.quantity);
	 gotoxy(16,17);
	 printf("============================");
	 gotoxy(18,19);
	 printf(" Total  :%.2f",temp.total);
  }
  else
       printf("Record not found!");
 fclose(ptr);
}


/*==============2_2按名字查找==================*/
void search_name()
{
  int flag=0;
  char lkf[20];
	   clrscr();
	   ptr=fopen("shop.dat","rb");
	   design();
	   gotoxy(13,4);
	   printf("\xDB\xDB\xB2  Enter name to be searched:");
	   scanf("%s",&lkf);
  while((!flag)&&(fread(&temp,sizeof(temp),1,ptr))==1)
  {
      if(strcmp(temp.name,lkf)==0)
      flag=1;
  }
     if(flag)
  {
	 gotoxy(18,6);
	 printf("Date    :%s",temp.id);
	 gotoxy(18,9);
	 printf("Name    :%s",temp.name);	
	 gotoxy(18,12);
	 printf("Price   :%.2f",temp.sale);
	 gotoxy(18,15);
	 printf("Quantity:%d",temp.quantity);
	 gotoxy(16,17);
	 printf("============================");
	 gotoxy(18,19);
	 printf(" Total  :%.2f",temp.total);
  }
  else
       printf("Record not found!");
 fclose(ptr);
}


/*=================3.显示记录函数======================*/
void display()
{
 char ch;
  clrscr();
  design();
  gotoxy(20,23);
  printf("Press Enter to go to Main Menu");
  textcolor(GREEN);
  gotoxy(25,4);
  cprintf("\xDB\xDB\xDB\xDB\xDB\xB2  Display the Records \xB2\xDB\xDB\xDB\xDB\xDB");
  textcolor(RED);
  gotoxy(4,7);
  cprintf(" Date             Name       Price        Quantity   Total");
  gotoxy(4,9);
  printf("========================================================================");

  ptr=fopen("shop.dat","rb");
  while((fread(&temp,sizeof(temp),1,ptr))==1)
     {
      
      printf("\n \xBA %s",temp.id);
      printf("\t%10s",temp.name);
      printf("\t%.2f",temp.sale);
      printf("\t\t%d",temp.quantity);
      printf("\t%.2f\n",temp.total);
      }
getche();
}


/*====================4.删除主函数====================*/
void del()
{
int sh;
  clrscr();
	  design();
	  gotoxy(17,6);
	  printf("\xDB\xDB\xB2 Two options available to delete \xB2\xDB\xDB");
	  gotoxy(16,9);
	  printf("[ 1 ] -Delete by Date");
	  gotoxy(16,11);
	  printf("[ 2 ] -Delete by Name");
	  gotoxy(18,15);
	  printf("Enter your choice:");
	  sh=toupper(getch());

  switch(sh)
  {
    case '1':
    deletion_date();
    break;

    case '2':
    deletion_name();
    break;

    default:
    gotoxy(18,18);
    printf("\a\xDB\xDB  Wrong entry ");
    gotoxy(17,23);
    printf("Press Enter to go to MAIN MENU .....");
    getch();
   }
  getche();
}


/*===============4_1按日期删除==================*/
void deletion_name()
{
 int j,n,i;
 char tar[30];
 int count=0;

		ptr = fopen("shop.dat","rb");
		clrscr();
		design();
		gotoxy(15,8);
		printf("\xDB\xDB Enter Date be deleted:");
		scanf("%s",&tar);
		j=0;

		while((fread(&temp,sizeof(temp),1,ptr))==1)
		{
		   if((strcmp(temp.id,tar)<0) || (strcmp(temp.id,tar)>0))
		   {
		      x[j] = temp;
		      j++;
		    }
		  else
		  {
		    count++;
		  }
		}
		if (count==0)
		{
		 clrscr();
		 design();
		 gotoxy(30,10);
		 printf("\xDB\xDB Record Not Found");
		 gotoxy(17,23);
		 printf("Press Enter to go to Main Menu");
		 getch();
		 return;
		}

		fclose(ptr);
		n = j;
		clrscr();
		ptr=fopen("shop.dat","wb");
		for(i=0; i<n; i++)
		fwrite(&x[i],sizeof(x[i]),1,ptr);
		fclose(ptr);
		clrscr();
		design();
		gotoxy(15,10);
		printf("Record has been deleted");
		gotoxy(15,12);
		printf("Check it by going to the displayed record");
		gotoxy(17,23);
		printf("Press Enter to go to Main Menu");
		getch();
}


/*=====================4_2按名字删除===================*/
void deletion_date()
{
 int j,n,i;
 char tar[30];
 int count=0;

		ptr = fopen("shop.dat","rb");
		clrscr();
		design();
		gotoxy(17,10);
		printf("\xDB\xDB  Enter Name to be deleted:");
		scanf("%s",&tar);
		j=0;

		while((fread(&temp,sizeof(temp),1,ptr))==1)
		{
		   if((strcmp(temp.name,tar)<0) || (strcmp(temp.name,tar)>0))
		   {
		      x[j] = temp;
		      j++;
		    }
		  else
		  {
		    count++;
		  }
		}
		if (count==0)
		{
		 clrscr();
		 design();
		 gotoxy(30,10);
		 printf("\xDB\xDB Record Not Found");
		 gotoxy(17,23);
		 printf("Press Enter to go to MAIN MENU ");
		 getch();
		 return;
		}

		fclose(ptr);
		n = j;
		clrscr();
		ptr=fopen("shop.dat","wb");
		for(i=0; i<n; i++)
		fwrite(&x[i],sizeof(x[i]),1,ptr);
		fclose(ptr);
		clrscr();
		design();
		gotoxy(20,10);
		printf("Record has been deleted");
		gotoxy(20,12);
		printf("Check it by going to the displayed record");
		gotoxy(17,23);
		printf("Press Enter to go to MAIN MENU");
		getch();
}


/*====================5.删除文件函数==================*/
int delete_file()
{
	char file[80];
	printf("The file to deleted:");
	gets(file);
	if(remove(file)==0)
		printf("Removing.\n",file);
	else
		perror("remove");
	return 0;
}


/*=====================6.统计汇总函数=================*/
void graph()
{
      int sher;
      clrscr();
      textcolor(WHITE);
      gotoxy(24,3);
      printf("\xDB\xDB\xDB\xDB\xB2  Total of the quantity or money   \xB2\xDB\xDB\xDB\xDB");
      gotoxy(10,5);
      printf("\n\n\t   *********  ENTER THE OPTION WHICH SUITS YOU.*******\n");
      printf("\n\t\xDB\xDB\xB2  1.Quantity.\n\n");
      printf("\n\t\xDB\xDB\xB2  2.Money.\n");
      printf("\n\n\n\t\t\xDB\xDB\xB2  Select1-2:");
      sher=toupper(getch());

  switch(sher)
  {
      case '1':
      graph1();
      break;

      case '2':
      graph2();
      break;

      default:
      gotoxy(9,20);
      textcolor(RED);
      cprintf("\a\xDB\xB2 Wrong ENTRY : PRESS ENTER TO GO TO MAIN MENU. ");
      getche();
  }
}


/*绘制数量统计图形*/
void graph1()
{
  int inscor1=1;
  char ch;
  clrscr();
  design();
  gotoxy(20,23);
  printf("Press enter to go to MAIN MENU .....");
  textcolor(10);
  gotoxy(15,4);
  cprintf("************* Graph Of Quantity *************");
  textcolor(14);
  gotoxy(3,5);
  cprintf(" Product Name");
  ptr=fopen("shop.dat","rb");
  while((fread(&temp,sizeof(temp),1,ptr))==1)
     {
        printf("\n \xBA %10s :",temp.name);
        bar1(inscor1);
     }
  fclose(ptr);
getche();
}


/*绘制总支出图形*/
void graph2()
{
  int inscor2=1;
  char ch;
  clrscr();
  design();
  gotoxy(20,23);
  printf("Pres Enter to go to MAIN MENU ...........");
  textcolor(10);
  gotoxy(15,4);
  cprintf("************* Graph Of Money *************");
  textcolor(14);
  gotoxy(4,5);
  cprintf("PRODUCT NAME");
  ptr=fopen("shop.dat","rb");
  while((fread(&temp,sizeof(temp),1,ptr))==1)
     {

     printf("\n \xBA %10s:",temp.name);
     bar2(inscor2);
   }
  fclose(ptr);
  getche();
}
 
 
/*绘制长度条幅*/
void bar1()
{
   int j;
   for(j=1;j<=temp.quantity;j++)
   printf("\xDB");
   printf("  %d",temp.quantity);
   printf("\n");
}

void bar2()
{
   int j;
   for(j=1;j<=temp.total;j+=5)
   printf("\xDB");
   printf("  %.2f RMB",temp.total);
   printf("\n");
}


/*菜单选择函数*/
 menu()
{
 int x;
  do{
       {
	clrscr();
	design();
	t();
	textcolor(WHITE);
	gotoxy(22,3);
	cprintf("\xDB\xDB\xDB\xDB\xB2  Single Financial Manage System \xB2\xDB\xDB\xDB\xDB");
	gotoxy(3,4);
	cprintf("--------------------------------------------------------------------------");
	gotoxy(35,5);
	cprintf("MAIN MENU");
	
	gotoxy(26,7);
	cprintf(" 1  -   Enter  Purchase  Records");
	gotoxy(26,9);
	cprintf(" 2  -   Search For Records      ");
	gotoxy(26,11);
	cprintf(" 3  -   Display the Records     ");
	gotoxy(26,13);
	cprintf(" 4  -   Delete the Records          ");
	gotoxy(26,15);
	cprintf(" 5  -   Delete the File         ");
	gotoxy(26,17);
	cprintf(" 6  -   Total  of Quantity/Money ");
		
	gotoxy(26,19);
	cprintf(" E  -   EXIT");
	
	gotoxy(26,23);
	cprintf("ENTER YOUR CHOICE: ");
	gotoxy(47,23);
	x=toupper(getch());
	switch(x)
	{
	case '1':
	entry();
	break;

	case '2':
	search();
	break;
	
	case '3':
	display();
	break;

	case '4':
	del();
	break;

	case '5':
	delete_file();
	break;
	
	case'6':
	graph();
	break;
	
	case 'e': case 'E':
	exit(0);
	break;

	default:
	clrscr();
	design();
	gotoxy(17,12);
	printf("\a\xDB\xB2  WRONG ENTRY : PRESS ANY KEY AND TRY AGAIN");
	getche();
	}
      }
    }while((x!='e')||(x!='E'));
    return x;
}


/*主函数*/
void main()
{
   textbackground(10);
   show_mouse();
   menu();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -