[C] 家庭财务管理小程序 →→→→→进入此内容的聊天室

来自 , 2020-04-26, 写在 C, 查看 143 次.
URL http://www.code666.cn/view/b6cda17a
  1. /*money management system*/
  2. #include "stdio.h"
  3. #include "dos.h"
  4. main()
  5. {
  6.         FILE *fp;
  7.         struct date d;
  8.         float sum,chm=0.0;
  9.         int len,I,j=0;
  10.         int c;
  11.         char ch[4]="",ch1[16]="",chtime[12]="",chshop[16],chmoney[8];
  12. pp:
  13.         clrscr();
  14.         sum=0.0;
  15.         gotoxy ( 1,1 );
  16.         printf ( "|---------------------------------------------------------------------------|" );
  17.         gotoxy ( 1,2 );
  18.         printf ( "| money management system(C1.0) 2000.03 |" );
  19.         gotoxy ( 1,3 );
  20.         printf ( "|---------------------------------------------------------------------------|" );
  21.         gotoxy ( 1,4 );
  22.         printf ( "| -- money records -- | -- today cost list -- |" );
  23.         gotoxy ( 1,5 );
  24.         printf ( "| ------------------------ |-------------------------------------|" );
  25.         gotoxy ( 1,6 );
  26.         printf ( "| date: -------------- | |" );
  27.         gotoxy ( 1,7 );
  28.         printf ( "| | | | |" );
  29.         gotoxy ( 1,8 );
  30.         printf ( "| -------------- | |" );
  31.         gotoxy ( 1,9 );
  32.         printf ( "| thgs: ------------------ | |" );
  33.         gotoxy ( 1,10 );
  34.         printf ( "| | | | |" );
  35.         gotoxy ( 1,11 );
  36.         printf ( "| ------------------ | |" );
  37.         gotoxy ( 1,12 );
  38.         printf ( "| cost: ---------- | |" );
  39.         gotoxy ( 1,13 );
  40.         printf ( "| | | | |" );
  41.         gotoxy ( 1,14 );
  42.         printf ( "| ---------- | |" );
  43.         gotoxy ( 1,15 );
  44.         printf ( "| | |" );
  45.         gotoxy ( 1,16 );
  46.         printf ( "| | |" );
  47.         gotoxy ( 1,17 );
  48.         printf ( "| | |" );
  49.         gotoxy ( 1,18 );
  50.         printf ( "| | |" );
  51.         gotoxy ( 1,19 );
  52.         printf ( "| | |" );
  53.         gotoxy ( 1,20 );
  54.         printf ( "| | |" );
  55.         gotoxy ( 1,21 );
  56.         printf ( "| | |" );
  57.         gotoxy ( 1,22 );
  58.         printf ( "| | |" );
  59.         gotoxy ( 1,23 );
  60.         printf ( "|---------------------------------------------------------------------------|" );
  61.         i=0;
  62.         getdate ( &d );
  63.         sprintf ( chtime,"%4d.%02d.%02d",d.da_year,d.da_mon,d.da_day );
  64.         for ( ;; )
  65.         {
  66.                 gotoxy ( 3,24 );
  67.                 printf ( " Tab __browse cost list Esc __quit" );
  68.                 gotoxy ( 13,10 );
  69.                 printf ( " " );
  70.                 gotoxy ( 13,13 );
  71.                 printf ( " " );
  72.                 gotoxy ( 13,7 );
  73.                 printf ( "%s",chtime );
  74.                 j=18;
  75.                 ch[0]=getch();
  76.                 if ( ch[0]==27 )
  77.                         break;
  78.                 strcpy ( chshop,"" );
  79.                 strcpy ( chmoney,"" );
  80.                 if ( ch[0]==9 )
  81.                 {
  82. mm:
  83.                         i=0;
  84.                         fp=fopen ( "home.dat","r+" );
  85.                         gotoxy ( 3,24 );
  86.                         printf ( " " );
  87.                         gotoxy ( 6,4 );
  88.                         printf ( " list records " );
  89.                         gotoxy ( 1,5 );
  90.                         printf ( "|-------------------------------------|" );
  91.                         gotoxy ( 41,4 );
  92.                         printf ( " " );
  93.                         gotoxy ( 41,5 );
  94.                         printf ( " |" );
  95.                         while ( fscanf ( fp,"%10s%14s%f\n",chtime,chshop,&chm ) !=EOF )
  96.                         {
  97.                                 if ( i==36 )
  98.                                 {
  99.                                         getch();
  100.                                         i=0;
  101.                                 }
  102.                                 if ( ( i%36 ) <17 )
  103.                                 {
  104.                                         gotoxy ( 4,6+i );
  105.                                         printf ( " " );
  106.                                         gotoxy ( 4,6+i );
  107.                                 }
  108.                                 else if ( ( i%36 ) >16 )
  109.                                 {
  110.                                         gotoxy ( 41,4+i-17 );
  111.                                         printf ( " " );
  112.                                         gotoxy ( 42,4+i-17 );
  113.                                 }
  114.                                 i++;
  115.                                 sum=sum+chm;
  116.                                 printf ( "%10s %-14s %6.1f\n",chtime,chshop,chm );
  117.                         }
  118.                         gotoxy ( 1,23 );
  119.                         printf ( "|---------------------------------------------------------------------------|" );
  120.                         gotoxy ( 1,24 );
  121.                         printf ( "| |" );
  122.                         gotoxy ( 1,25 );
  123.                         printf ( "|---------------------------------------------------------------------------|" );
  124.                         gotoxy ( 10,24 );
  125.                         printf ( "total is %8.1f$",sum );
  126.                         fclose ( fp );
  127.                         gotoxy ( 49,24 );
  128.                         printf ( "press any key to….." );
  129.                         getch();
  130.                         goto pp;
  131.                 }
  132.                 else
  133.                 {
  134.                         while ( ch[0]!='\r' )
  135.                         {
  136.                                 if ( j<10 )
  137.                                 {
  138.                                         strncat ( chtime,ch,1 );
  139.                                         j++;
  140.                                 }
  141.                                 if ( ch[0]==8 )
  142.                                 {
  143.                                         len=strlen ( chtime )-1;
  144.                                         if ( j>15 )
  145.                                                 { len=len+1; j=11;}
  146.                                         strcpy ( ch1,"" );
  147.                                         j=j-2;
  148.                                         strncat ( ch1,chtime,len );
  149.                                         strcpy ( chtime,"" );
  150.                                         strncat ( chtime,ch1,len-1 );
  151.                                         gotoxy ( 13,7 );
  152.                                         printf ( " " );
  153.                                 }
  154.                                 gotoxy ( 13,7 );
  155.                                 printf ( "%s",chtime );
  156.                                 ch[0]=getch();
  157.                                 if ( ch[0]==9 )
  158.                                         goto mm;
  159.                                 if ( ch[0]==27 )
  160.                                         exit ( 1 );
  161.                         }
  162.                         gotoxy ( 3,24 );
  163.                         printf ( " " );
  164.                         gotoxy ( 13,10 );
  165.                         j=0;
  166.                         ch[0]=getch();
  167.                         while ( ch[0]!='\r' )
  168.                         {
  169.                                 if ( j<14 )
  170.                                 {
  171.                                         strncat ( chshop,ch,1 );
  172.                                         j++;
  173.                                 }
  174.                                 if ( ch[0]==8 )
  175.                                 {
  176.                                         len=strlen ( chshop )-1;
  177.                                         strcpy ( ch1,"" );
  178.                                         j=j-2;
  179.                                         strncat ( ch1,chshop,len );
  180.                                         strcpy ( chshop,"" );
  181.                                         strncat ( chshop,ch1,len-1 );
  182.                                         gotoxy ( 13,10 );
  183.                                         printf ( " " );
  184.                                 }
  185.                                 gotoxy ( 13,10 );
  186.                                 printf ( "%s",chshop );
  187.                                 ch[0]=getch();
  188.                         }
  189.                         gotoxy ( 13,13 );
  190.                         j=0;
  191.                         ch[0]=getch();
  192.                         while ( ch[0]!='\r' )
  193.                         {
  194.                                 if ( j<6 )
  195.                                 {
  196.                                         strncat ( chmoney,ch,1 );
  197.                                         j++;
  198.                                 }
  199.                                 if ( ch[0]==8 )
  200.                                 {
  201.                                         len=strlen ( chmoney )-1;
  202.                                         strcpy ( ch1,"" );
  203.                                         j=j-2;
  204.                                         strncat ( ch1,chmoney,len );
  205.                                         strcpy ( chmoney,"" );
  206.                                         strncat ( chmoney,ch1,len-1 );
  207.                                         gotoxy ( 13,13 );
  208.                                         printf ( " " );
  209.                                 }
  210.                                 gotoxy ( 13,13 );
  211.                                 printf ( "%s",chmoney );
  212.                                 ch[0]=getch();
  213.                         }
  214.                         if ( ( strlen ( chshop ) ==0 ) || ( strlen ( chmoney ) ==0 ) )
  215.                                 continue;
  216.                         if ( ( fp=fopen ( "home.dat","a+" ) ) !=NULL );
  217.                         fprintf ( fp,"%10s%14s%6s",chtime,chshop,chmoney );
  218.                         fputc ( '\n',fp );
  219.                         fclose ( fp );
  220.                         i++;
  221.                         gotoxy ( 41,5+i );
  222.                         printf ( "%10s %-14s %-6s",chtime,chshop,chmoney );
  223.                 }
  224.         }
  225. }

回复 "家庭财务管理小程序"

这儿你可以回复上面这条便签

captcha