• 超市商品购买与管理系统


    熬了 三天做出来的 可能还有bug

    不过我学习到了很多

    其中包括密码不回显

    char *passw()
    {
     char ch, s[20];
     int i = 0;
     while ((ch = getch()) != ' ')
     {
      
      
       if (ch != 8)
       {
        s[i] = ch;
        putchar('*');
        i++;
       }
       else if (i > 0)
       {
        putchar('');
        putchar(' ');
        putchar('');
        i--;
       }
      
     }
     s[i] = '';
     return s;

    }

    返回系统时间等 

    struct tm gwtiame()
    {
     time_t t;
     struct tm*lt;
     t=time(NULL);
     lt = localtime(&t);
     struct tm a = *lt;
     return a;
    }

    这是我人生第一个千行代码 留作纪念 

       1 /*本代码及设计由缪传鹏版权所有 未经允许不得商用 The copyright of the design program belongs to Miaoz, it cannot be used for commerce without permission.*/
       2 #include<stdio.h>
       3 #include<stdlib.h>
       4 #include<string.h>
       5 #include<conio.h>
       6 #include<time.h>
       7 typedef struct cmy {
       8  char cmyID[20];
       9  int money;
      10  int kuchun;
      11  char name[40];
      12  char conment[100][100];
      13  char commentcount;
      14 }cm;
      15 typedef struct shopcar {
      16  int shuliang;
      17  cm cmyi;
      18 }car;
      19 typedef struct gmjl {
      20  car jlsp;
      21  struct tm lt;
      22 }jl;
      23 typedef struct users {
      24  char username[20];
      25  char password[20];
      26  int usermony;
      27  car Shopcar[20];
      28  int shopcount;
      29  char youxiang[30];
      30  jl gmjlu[100];
      31  int jilucount;
      32 }uer;
      33 typedef struct wjpass{
      34  char wjname[20];
      35  char beizhu[200];
      36  char youxiang[30];
      37 }wjp;
      38 typedef struct wenti
      39 {
      40  wjp wangji[100];
      41  int wjcount;
      42 }wt;
      43  
      44  
      45 
      46 cm sp[1000] = { { "1",3,450,"可乐","",0 },{ "2",5,600,"辣条","",0 },{ "3",5,582,"酸奶" ,"",0},{ "4",8,888,"红牛","",0 },{"5",7,481,"夹心饼干","",0 } };
      47 ;//初始化信息
      48 uer kehu[1000];//初始化信息
      49 wt weti = { "0",0 };
      50 
      51 char gb[20] = "缪传鹏最帅";
      52 char adm[20] = "admin";
      53 char admpassword[20] = "admin";
      54 
      55 int count = 0;//用户量
      56 int countsp1 , countsp2 = 5;
      57  
      58 void spxx();//输出商品信息 
      59 void zjiasp();//增加商品
      60 void shanchu();//删除商品
      61 void xiugai();//修改商品
      62 void guangliyuan();//管理员界面
      63 void yonhu(int usi);//用户界面 通过用户下标来标识
      64 void zhuc();//注册界面
      65 void den();//登陆界面
      66 void csjm();//初始界面
      67 void exeit();//播放退出动画然后退出
      68 void shopcar(int usi);//购物车界面
      69 void goshopcar(int usi, int shopi);//其中usi为用户下标shopi为商品下标加入购物车
      70 int nametoid(char name2[20]);//通过名字查找下标
      71 void kehuchakansp(int usi);//客户查看商品
      72 void huangying();//欢迎界面
      73 void exeit();
      74 char *passw();//密码不回显
      75 void zhanghuwenti(int usi);//反馈账户问题
      76 void xiugaipassw(int usi);//修改密码
      77 void kehuwent();//初始界面的反馈账户问题
      78 void gly_zhaohu();//管理员找回用户密码
      79 void gly_shanchuwt();//管理员删除问题
      80 void shezhi();//设置界面
      81 void beijingcolor();//背景颜色  未调用
      82 void ziticolor();//字体颜色  未调用
      83 void comment(int shopi);//对商品进行评论
      84 struct tm gwtiame();//返回当前时间
      85 void gwjl(int shul, int shopi);//记录购物记录
      86 void chakangwjl(int usi);//查看购物记录
      87 void chonzhi(int usi);//充值
      88 int spidtoid(char name3[20]);//商品名称返回商品下标
      89 int spidtoid(char name3[20])
      90 {
      91  int flag4 = 0, t1;
      92  for (int i = 0; i < countsp2; i++)
      93  {
      94   if (!strcmp(name3, sp[i].cmyID))
      95   {
      96    flag4 = 1;
      97    t1 = i;
      98   }
      99  }
     100  if (flag4 == 0)
     101  {
     102   return -1;
     103  }
     104  else
     105   return t1;
     106 }
     107 void chonzhi(int usi)
     108 {
     109  while (1)
     110  {
     111   system("cls");
     112   printf("您的余额是:%d
    1————充值余额
    2————返回上一层
    ", kehu[usi].usermony);
     113   char flag22 = getch();
     114   if (flag22 == '1')
     115   {
     116    char flag23[20];
     117    printf("请输入缪传鹏最帅以进行充值
    ");
     118    gets_s(flag23);
     119    if (!strcmp(flag23, gb))
     120    {
     121     printf("充值中......");
     122     kehu[usi].usermony += 100;
     123     _sleep(1000);
     124     printf("充值成功......");
     125     _sleep(500);
     126    }
     127    else
     128    {
     129     printf("充值中........
    ");
     130     _sleep(2000);
     131     printf("充值失败请重试......");
     132     _sleep(500);
     133    }
     134   }
     135   else if (flag22 == '2')
     136   {
     137    yonhu(usi);
     138   }
     139  }
     140 }
     141 void chakangwjl(int usi)
     142 {
     143  while (1)
     144  {
     145   system("cls");
     146   printf("——————购物记录——————
    ");
     147   for (int i = 0; i < kehu[usi].jilucount; i++)
     148   {
     149    printf("编号:%d	", i + 1);
     150    printf("交易时间:");
     151    printf("%d年%d月%d日%d点%d分%d秒	", kehu[usi].gmjlu[i].lt.tm_year + 1900, kehu[usi].gmjlu[i].lt.tm_mon, kehu[usi].gmjlu[i].lt.tm_mday, kehu[usi].gmjlu[i].lt.tm_hour, kehu[usi].gmjlu[i].lt.tm_min, kehu[usi].gmjlu[i].lt.tm_sec);
     152    printf("商品名称:%s
    ", kehu[usi].gmjlu[i].jlsp.cmyi.name);
     153    printf("数量:%d
    ", kehu[usi].gmjlu[i].jlsp.shuliang);
     154    printf("交易额:%d
    ", kehu[usi].gmjlu[i].jlsp.shuliang*kehu[usi].gmjlu[i].jlsp.cmyi.money);
     155    printf("——————————————————————————————
    ");
     156   }
     157   
     158   //printf("———————输入购物记录编号对该商品进行评论——————
    ");
     159   printf("1————评论
    2————退出
    ");
     160   char fla4 = getch();
     161   if (fla4 == '1')
     162   {
     163    int t2;
     164    printf("请输入要评论商品所对应的购物记录编号
    ");
     165    scanf("%d", &t2);
     166    int i = spidtoid(kehu[usi].gmjlu[t2 - 1].jlsp.cmyi.cmyID);
     167    comment(i);
     168   }
     169   if (fla4 == '2')
     170   {
     171    yonhu(usi);
     172   }
     173  }
     174 }
     175 void gwjl(int shopi,int usi)
     176 {
     177  kehu[usi].gmjlu[kehu[usi].jilucount].jlsp = kehu[usi].Shopcar[shopi];
     178  kehu[usi].gmjlu[kehu[usi].jilucount].lt = gwtiame();
     179  kehu[usi].jilucount++;
     180 }
     181 struct tm gwtiame()
     182 {
     183  time_t t;
     184  struct tm*lt;
     185  t=time(NULL);
     186  lt = localtime(&t);
     187  struct tm a = *lt;
     188  return a;
     189 }
     190 void comment(int shopi)
     191 {
     192  printf("%s%d
    ", sp[shopi].name,shopi);
     193  printf("——————请输入评论——————
    ");
     194  scanf("%s", sp[shopi].conment[sp[shopi].commentcount++]);
     195  printf("评论成功");
     196  printf("按任意键返回");
     197  getch();
     198 }
     199 void ziticolor()
     200 {
     201  while (1)
     202  {
     203   system("cls");
     204   printf("输入想要的字体颜色
    ");
     205   printf("0 ————黑色
    1 ———— 蓝色
    2 ———— 绿色
    3———— 浅绿色
    4 ———— 红色
    5 ———— 紫色
    6 ———— 黄色
    7———— 白色
    ");
     206   printf("8 ————灰色
    9 ———— 淡蓝色
    A ———— 淡绿色
    B ———— 淡浅绿色
    C ———— 淡红色
    D————淡紫色
    E ———— 淡黄色
    F ————亮白色
    G————退出
    ");
     207   char fla2 = getch();
     208   switch (fla2)
     209   {
     210   case '1':system("color 1"); break;
     211   case '2':system("color 2"); break;
     212   case '3':system("color 3"); break;
     213   case '4':system("color 4"); break;
     214   case '5':system("color 5"); break;
     215   case '6':system("color 6"); break;
     216   case '7':system("color 7"); break;
     217   case '8':system("color 8"); break;
     218   case '9':system("color 9"); break;
     219   case 'A':system("color A"); break;
     220   case 'B':system("color B"); break;
     221   case 'C':system("color C"); break;
     222   case 'D':system("color D"); break;
     223   case 'E':system("color E"); break;
     224   case 'F':system("color F"); break;
     225   case '0':system("color 0"); break;
     226   case 'G':shezhi(); break;
     227   default:
     228    break;
     229   }
     230  }
     231 }
     232 void beijingcolor()
     233 {
     234  while (1)
     235  {
     236   system("cls");
     237   printf("——————先输入想要的背景颜色——————
    ");
     238   printf("0 ————黑色
    1 ———— 蓝色
    2 ———— 绿色
    3———— 浅绿色
    4 ———— 红色
    5 ———— 紫色
    6 ———— 黄色
    7———— 白色
    ");
     239   printf("8 ————灰色
    9 ———— 淡蓝色
    A ———— 淡绿色
    B ———— 淡浅绿色
    C ———— 淡红色
    D————淡紫色
    E ———— 淡黄色
    F ————亮白色
    G————退出
    ");
     240   char fla2 = getch();
     241   switch (fla2)
     242   {
     243   case '1':system("color 17"); break;
     244   case '2':system("color 27"); break;
     245   case '3':system("color 37"); break;
     246   case '4':system("color 47"); break;
     247   case '5':system("color 57"); break;
     248   case '6':system("color 67"); break;
     249   case '7':system("color 77"); break;
     250   case '8':system("color 87"); break;
     251   case '9':system("color 97"); break;
     252   case 'A':system("color A7"); break;
     253   case 'B':system("color B7"); break;
     254   case 'C':system("color C7"); break;
     255   case 'D':system("color D7"); break;
     256   case 'E':system("color E7"); break;
     257   case 'F':system("color F7"); break;
     258   case '0':system("color 07"); break;
     259   case 'G':ziticolor(); break;
     260   default:
     261    break;
     262   }
     263  }
     264 }
     265 void shezhi()
     266 {
     267  while (1)
     268  {
     269   system("cls");
     270   printf("1————设置颜色
    2————返回上一层");
     271   char fla1 = getch();
     272   if (fla1 == '1')
     273   {
     274    while (1)
     275    {
     276     system("cls");
     277     printf("1——————黑底白字
    2——————白底绿字
    3——————黑底黄字
    4——————黑底白字
    5——————紫底白字
    6——————返回
    ");
     278     char fla2 = getch();
     279     switch (fla2)
     280     {
     281     case '1':system("color 07"); break;
     282     case '2':system("color 72"); break;
     283     case '3':system("color 06"); break;
     284     case '4':system("color 70"); break;
     285     case '5':system("color 57"); break;
     286     case '6':shezhi(); break;
     287     }
     288    }
     289   }
     290   if (fla1 == '2')
     291   {
     292    csjm();
     293   }
     294  }
     295 }
     296 void gly_shanchuwt()
     297 {
     298  system("cls");
     299  printf("————————客户问题————————
    ");
     300  if (weti.wjcount == 0)printf("当前没有客户问题
    ");
     301  for (int i = 0; i < weti.wjcount; i++)
     302  {
     303   printf("编号:%d
    名字:%s
    邮箱地址:%s
    问题:%s
    
    ", i + 1, weti.wangji[i].wjname, weti.wangji[i].youxiang, weti.wangji[i].beizhu);
     304  }
     305  printf("——————————删除问题——————————
    ");
     306  int tempbh;
     307  printf("请输入要删除所对应的编号
    ");
     308  scanf("%d", &tempbh);
     309  if (tempbh<1 || tempbh>weti.wjcount)
     310  {
     311   while (1)
     312   {
     313    printf("请输入正确的编号
    ");
     314    printf("1————重新输入
    2————退出
    ");
     315    char fla4 = getch();
     316    if (fla4 == '1')
     317    {
     318     gly_shanchuwt();
     319    }
     320    if (fla4 == '2')
     321    {
     322     kehuwent();
     323    }
     324   }
     325   
     326  }
     327  else
     328  {
     329   printf("正在删除...
    ");
     330   _sleep(800);
     331   weti.wangji[tempbh] = weti.wangji[weti.wjcount];
     332   weti.wjcount--;
     333   printf("删除成功.....
    ");
     334   _sleep(800);
     335   printf("按任意键返回
    ");
     336   getch();
     337  }
     338 }
     339 void gly_zhaohu()
     340 {
     341  system("cls");
     342  printf("————————客户问题————————
    ");
     343  if (weti.wjcount == 0)printf("当前没有客户问题
    ");
     344  for (int i = 0; i < weti.wjcount; i++)
     345  {
     346   printf("编号:%d
    名字:%s
    邮箱地址:%s
    问题:%s
    
    ", i + 1, weti.wangji[i].wjname, weti.wangji[i].youxiang, weti.wangji[i].beizhu);
     347  }
     348  printf("——————————为客户找回密码——————————
    ");
     349  int tempbh;
     350  printf("请输入客户姓名所对应的编号
    ");
     351  scanf("%d", &tempbh);
     352  if (tempbh<1 || tempbh>weti.wjcount)
     353  {
     354   while (1)
     355   {
     356    printf("请输入正确的编号
    ");
     357    printf("1————重新输入
    2————退出
    ");
     358    char fla4 = getch();
     359    if (fla4 == '1')
     360    {
     361     gly_zhaohu();
     362    }
     363    if (fla4 == '2')
     364    {
     365     kehuwent();
     366    }
     367   }
     368  }
     369  else
     370  {
     371   int kehui = nametoid(weti.wangji[tempbh-1].wjname);
     372   printf("客户:%s
    密码:%s
    请通过他的邮箱%s告知。
    ", kehu[kehui].username, kehu[kehui].password, kehu[kehui].youxiang);
     373   printf("按任意键返回上一级
    ");
     374   getch();
     375  }
     376 }
     377 void kehuwent()
     378 {
     379  while (1)
     380  {
     381   system("cls");
     382   printf("————————客户问题————————
    ");
     383   if (weti.wjcount == 0)printf("当前没有客户问题
    ");
     384   for (int i = 0; i < weti.wjcount; i++)
     385   {
     386    printf("编号:%d
    名字:%s
    邮箱地址:%s
    问题:%s
    
    ", i + 1, weti.wangji[i].wjname, weti.wangji[i].youxiang, weti.wangji[i].beizhu);
     387   }
     388   printf("——————客户是上帝 请解决这些问题——————
    ");
     389   printf("1————为客户找回密码
    2————删除问题
    3——————解决其他问题
    4————退出
    ");
     390   char flag31 = getch();
     391   if (flag31 == '1')
     392   {
     393    gly_zhaohu();
     394   }
     395   if (flag31 == '3')
     396   {
     397    printf("请手动解决
    ");
     398    _sleep(1000);
     399    kehuwent();
     400   }
     401   if (flag31 == '2')
     402   {
     403    gly_shanchuwt();
     404   }
     405   if (flag31 == '4')
     406   {
     407    guangliyuan();
     408   }
     409  }
     410 }
     411 void zhanghuwenti(int usi)
     412 {
     413  while (1)
     414  {
     415   system("cls");
     416   printf("1————修改密码
    2————返回上一层
    ");
     417   char flag30 = getch();
     418   if (flag30 == '1')
     419   {
     420    xiugaipassw(usi);
     421   }
     422   else if (flag30 == '3')
     423   {
     424    //待增加
     425   }
     426   else if (flag30 == '2')
     427   {
     428    yonhu(usi);
     429   }
     430  }
     431 }
     432 char *passw()
     433 {
     434  char ch, s[20];
     435  int i = 0;
     436  while ((ch = getch()) != '
    ')
     437  {
     438   
     439   
     440    if (ch != 8)
     441    {
     442     s[i] = ch;
     443     putchar('*');
     444     i++;
     445    }
     446    else if (i > 0)
     447    {
     448     putchar('');
     449     putchar(' ');
     450     putchar('');
     451     i--;
     452    }
     453   
     454  }
     455  s[i] = '';
     456  return s;
     457 }
     458 void zhaohuipassw() 
     459 {
     460  system("cls");
     461  char nametemp[20],bztemp[200];
     462  printf("请输入账户名
    ");
     463  scanf("%s", nametemp);
     464  if (nametoid(nametemp) == -1)
     465  {
     466   while (1)
     467   {
     468    printf("帐户名不存在
    ");
     469    printf("1————重新输入
    2————返回上一层
    ");
     470    char fla1 = getch();
     471    if (fla1 == '1')zhaohuipassw();
     472    if (fla1 == '2')den();
     473   }
     474  }
     475  printf("请输入备注
    ");
     476  scanf("%s", bztemp);
     477  char yxtemp[30];
     478  while (1)
     479  {
     480   printf("请输入您的邮箱地址
    ");
     481   scanf("%s", yxtemp);
     482   if (!strcmp(yxtemp, kehu[nametoid(nametemp)].youxiang))
     483   {
     484    strcpy(weti.wangji[weti.wjcount].beizhu, bztemp);
     485    strcpy(weti.wangji[weti.wjcount].wjname, nametemp);
     486    strcpy(weti.wangji[weti.wjcount].youxiang, yxtemp);
     487    weti.wjcount++;
     488    printf("等待管理员处理,处理成功新密码将发送至您的邮箱
    ");
     489    _sleep(1000);
     490    break;
     491   }
     492   else
     493   {
     494    while (1)
     495    {
     496     system("cls");
     497     printf("邮箱地址不正确
    ");
     498     
     499     printf("1————重新输入
    2————返回上一层
    ");
     500     char fla1 = getch();
     501     if (fla1 == '1')
     502     {
     503      system("cls");
     504      break;
     505     }
     506     if (fla1 == '2')den();
     507    }
     508   }
     509  }
     510  
     511 }
     512 void xiugaipassw(int usi)
     513 {
     514  if (usi == -1)
     515  {
     516   char zhaoname[20];
     517   system("cls");
     518   printf("请输入账户名
    ");
     519   scanf("%s", zhaoname);
     520   if (zhaoname == "-1")
     521   {
     522    printf("正在返回....");
     523    _sleep(800);
     524    den();
     525   }
     526   if (nametoid(zhaoname) == -1)
     527   {
     528    printf("此帐户名不存在
    ");
     529    printf("请重新输入,输入-1返回上一层
    ");
     530    xiugaipassw(-1);
     531   }
     532   else
     533   {
     534    while (1)
     535    {
     536     system("cls");
     537     char zhaopass[20];
     538     printf("请输入修改前密码");
     539     scanf("%s", zhaopass);
     540     if (!strcmp(zhaopass, kehu[nametoid(zhaoname)].password))
     541     {
     542      while (1)
     543      {
     544       char newpass1[20], newpass2[20];
     545       printf("请输入新密码
    ");
     546       scanf("%s", newpass1);
     547       printf("请再次输入新密码
    ");
     548       scanf("%s", newpass2);
     549       if (!strcmp(newpass1, newpass2))
     550       {
     551        printf("修改密码成功...
    ");
     552        _sleep(800);
     553        strcpy(kehu[nametoid(zhaoname)].password, newpass1);
     554        printf("正在返回上一层....
    ");
     555        _sleep(600);
     556        den();
     557       }
     558       else
     559       {
     560        printf("两次密码不相同请重新输入
    ");
     561        _sleep(800);
     562       }
     563      }
     564     }
     565     else
     566     {
     567      printf("密码错误
    1——————重新输入
    2——————退出
    ");
     568      _sleep(800);
     569      while (1)
     570      {
     571       char flag28 = getch();
     572       if (flag28 == '1')break;
     573       if (flag28 == '2')den();
     574      }
     575      
     576     }
     577    }
     578    
     579   }
     580  }
     581  else
     582  {
     583   while (1)
     584   {
     585    system("cls");
     586    char zhaopass[20];
     587    printf("请输入修改前密码
    ");
     588    strcpy(zhaopass,passw());
     589    if (!strcmp(zhaopass, kehu[usi].password))
     590    {
     591     while (1)
     592     {
     593      char newpass1[20], newpass2[20];
     594      printf("
    请输入新密码
    ");
     595      strcpy(newpass1, passw());
     596      printf("
    请再次输入新密码
    ");
     597      strcpy(newpass2, passw());
     598      if (!strcmp(newpass1, newpass2))
     599      {
     600       printf("
    修改密码成功...
    ");
     601       _sleep(800);
     602       strcpy(kehu[usi].password, newpass1);
     603       printf("正在返回上一层....
    ");
     604       _sleep(600);
     605       yonhu(usi);
     606      }
     607      else
     608      {
     609       printf("
    两次密码不相同请重新输入
    ");
     610       _sleep(800);
     611       break;
     612      }
     613     }
     614    }
     615    else
     616    {
     617     printf("密码错误
    1——————重新输入
    2——————退出
    ");
     618     _sleep(800);
     619     while (1)
     620     {
     621      char flag28 = getch();
     622      if (flag28 == '1')break;
     623      if (flag28 == '2')yonhu(usi);
     624     }
     625    }
     626   }
     627  }
     628 }
     629 void huangying()
     630 {
     631  printf("——————————_——————————欢迎光临——————————————————————");
     632  _sleep(1000);
     633 }
     634 void shopcar(int usi)
     635 {
     636  while (1)
     637  {
     638   system("cls");
     639   printf("——购物车——
    ");
     640   if (kehu[usi].shopcount==0)
     641   {
     642    printf("当前您的购物车是空的
    ");
     643    _sleep(1000);
     644    printf("按任意键退出");
     645    getchar();
     646    yonhu(usi);
     647   }
     648   for (int i = 0; i < kehu[usi].shopcount; i++)
     649   {
     650    printf("商品编号:%d
    商品名称:%s
    商品数量:%d
    价格:%d
    
    ", i+1,kehu[usi].Shopcar[i].cmyi.name, kehu[usi].Shopcar[i].shuliang, kehu[usi].Shopcar[i].cmyi.money *kehu[usi].Shopcar[i].shuliang);
     651   }
     652   printf("1————结算
    2————删除
    3————退出
    ");
     653   char flag18 = getch();
     654   if (flag18 == '2')
     655   {
     656    while (1)
     657    {
     658     system("cls");
     659     printf("请输入所需删除的商品的编号
    ");
     660     printf("————————————————————————
    ");
     661     for (int i = 0; i < kehu[usi].shopcount; i++)
     662     {
     663      printf("商品编号:%d
    商品名称:%s
    商品数量:%d
    价格:%d
    
    ", i+1, kehu[usi].Shopcar[i].cmyi.name, kehu[usi].Shopcar[i].shuliang, kehu[usi].Shopcar[i].cmyi.money *kehu[usi].Shopcar[i].shuliang);
     664     }
     665     printf("————————————————————————
    ");
     666     int flag19;
     667     getchar();
     668     scanf("%d", &flag19);
     669     system("cls");
     670     if (flag19 == -1)shopcar(usi);
     671     if (flag19 > kehu[usi].shopcount)
     672     {
     673      printf("编号错误请重新输入
    ");
     674      _sleep(1000);
     675     }
     676     else if (flag19 > 0)
     677     {
     678      printf("正在删除......");
     679      _sleep(800);
     680      system("cls");
     681      kehu[usi].Shopcar[flag19] = kehu[usi].Shopcar[kehu[usi].shopcount - 1];
     682      kehu[usi].shopcount--;
     683      printf("删除成功......");
     684      shopcar(usi);
     685     }
     686     else
     687     {
     688      printf("编号错误请重新输入
    ");
     689      _sleep(1000);
     690     }
     691    }
     692   }
     693   else if (flag18 == '1')
     694   {
     695    while (1)
     696    {
     697     system("cls");
     698     printf("请输入所需购买的商品的编号
    ");
     699     printf("————————————————————————
    ");
     700     for (int i = 0; i < kehu[usi].shopcount; i++)
     701     {
     702      printf("商品编号:%d 
    商品名称:%s 
    商品数量:%d 
    价格:%d 
    
    ", i + 1, kehu[usi].Shopcar[i].cmyi.name, kehu[usi].Shopcar[i].shuliang, kehu[usi].Shopcar[i].cmyi.money *kehu[usi].Shopcar[i].shuliang);
     703     }
     704     printf("————————————————————————
    ");
     705     int flag20;
     706     getchar();
     707     scanf("%d", &flag20);
     708     system("cls");
     709     if (flag20 == -1)shopcar(usi);
     710     if (flag20 > kehu[usi].shopcount||flag20<1)
     711     {
     712      printf("编号错误请重新输入
    ");
     713      _sleep(1000);
     714     }
     715     else if (flag20 > 0)
     716     {
     717      printf("商品编号:%d
    商品名称:%s
    商品数量:%d
    价格:%d
    
    ", flag20, kehu[usi].Shopcar[flag20-1].cmyi.name, kehu[usi].Shopcar[flag20-1].shuliang, kehu[usi].Shopcar[flag20-1].cmyi.money *kehu[usi].Shopcar[flag20-1].shuliang);
     718 
     719      if (kehu[usi].Shopcar[flag20-1].cmyi.money *kehu[usi].Shopcar[flag20-1].shuliang>kehu[usi].usermony)
     720      {
     721       while (1)
     722       {
     723        system("cls");
     724        printf("余额不足请前往充值
    ");
     725        _sleep(1000);
     726        printf("1————前往充值
    2————返回上一层
    ");
     727        char fal4 = getch();
     728        if (fal4 == '1')
     729        {
     730         chonzhi(usi);
     731        }
     732        if (fal4 == '2')
     733        {
     734         shopcar(usi);
     735        }
     736       }
     737       //选择
     738      }
     739      else
     740      {
     741       while (1)
     742       {
     743        system("cls");
     744        printf("商品名称:%s商品数量:%d
    总价为:%d
    Y——确定   N——取消
    ", kehu[usi].Shopcar[flag20 - 1].cmyi.name, kehu[usi].Shopcar[flag20 - 1].shuliang, kehu[usi].Shopcar[flag20-1].cmyi.money *kehu[usi].Shopcar[flag20-1].shuliang);
     745        char flag21 = getch();
     746        if (flag21 == 'Y')
     747        {
     748         printf("正在交易......");
     749         _sleep(800);
     750         system("cls");
     751         gwjl(flag20 - 1, usi);
     752         kehu[usi].Shopcar[flag20] = kehu[usi].Shopcar[kehu[usi].shopcount - 1];
     753         kehu[usi].shopcount--;
     754         kehu[usi].usermony -= kehu[usi].Shopcar[flag20].cmyi.money *kehu[usi].Shopcar[flag20].shuliang;
     755         printf("交易成功......");
     756         _sleep(200);
     757         shopcar(usi);
     758        }
     759        if (flag21 == 'N')
     760        {
     761         printf("正在取消......");
     762         _sleep(800);
     763         system("cls");
     764         
     765         printf("已取消......");
     766         _sleep(200);
     767         
     768         shopcar(usi);
     769         //取消交易
     770        }
     771       }
     772      }
     773     }
     774    }
     775   }
     776   else if (flag18 == '3')
     777   {
     778    printf("正在退出购物车.....");
     779    _sleep(600);
     780    yonhu(usi);
     781   }
     782  }
     783 }
     784 void spxx()
     785 {
     786  system("cls");
     787  
     788  for (int i = 0; i < countsp2; i++)
     789  {
     790   printf("商品名称: %s
    商品ID: %s
    商品价格: %d
    商品库存: %d
    ", sp[i].name, sp[i].cmyID, sp[i].money, sp[i].kuchun);
     791   for (int j = 0; j < sp[i].commentcount; j++)
     792    printf("第%d评论:%s",j+1,sp[i].conment[j]);
     793   printf("
    
    ");
     794  }
     795  
     796 }
     797 void goshopcar(int usi,int shopi)
     798 {
     799  while (1)
     800  {
     801   system("cls");
     802   printf("商品名称:%s
    请输入所需数量:  ", sp[shopi].name);
     803   int sl;
     804   scanf("%d", &sl);
     805   if (sl == -1)kehuchakansp(usi);
     806   if (sl > sp[shopi].kuchun)
     807   {
     808    printf("库存不足 请减少数量
    ");
     809    printf("1————重新输入
    2————返回上一层
    ");
     810    char fla1 = getch();
     811    if (fla1 == '1')break;
     812    if (fla1 == '2')kehuchakansp(usi);
     813    _sleep(1000);
     814   }
     815   else
     816   {
     817    while (1)
     818    {
     819     system("cls");
     820     printf("商品名称:%s
    所选数量:%d
    ", sp[shopi].name,sl);
     821     printf("总价为:%d
    Y——确定   N——取消
    ", sp[shopi].money*sl);
     822     char flag17 = getch();
     823     if (flag17 == 'Y')
     824     {
     825      printf("正在加入
    ");
     826      _sleep(800);
     827      kehu[usi].Shopcar[kehu[usi].shopcount].cmyi = sp[shopi];
     828      kehu[usi].Shopcar[kehu[usi].shopcount].shuliang = sl;
     829      kehu[usi].shopcount++;
     830      printf("加入购物车成功");
     831      _sleep(800);
     832      system("cls");
     833      while (1)
     834      {
     835       system("cls");
     836       printf("1————前往购物车结算
    2————返回商品信息");
     837       char flag18 = getch();
     838       if (flag18 == '1')
     839       {
     840        shopcar(usi);
     841       }
     842       if (flag18 == '2')kehuchakansp(usi);
     843      }
     844     }
     845     else if (flag17 == 'N')
     846     {
     847      printf("正在取消.......");
     848      _sleep(800);
     849      kehuchakansp(usi);
     850      printf("已取消");
     851      _sleep(1000);
     852      kehuchakansp(usi);
     853     }
     854    }
     855    
     856   }
     857  }
     858 }
     859 int nametoid(char name2[20])
     860 {
     861  int flag4 = 0, t1;
     862  for (int i = 0; i < count; i++)
     863  {
     864   if (!strcmp(name2, kehu[i].username))
     865   {
     866    flag4 = 1;
     867    t1 = i;
     868   }
     869  }
     870  if (flag4 == 0)
     871  {
     872   return -1;
     873  }
     874  else
     875   return t1;
     876 }
     877 void kehuchakansp(int usi)
     878 {
     879  while (1)
     880  {
     881   system("cls");
     882   spxx();
     883   printf("——————————————————————欢迎来到本超市————————————————————
    
    ");
     884   printf("1————将商品加入购物车
    2————退出超市
    ");
     885   char fla2 = getch();
     886   if (fla2 == '1')
     887   {
     888    while (1)
     889    {
     890     spxx();
     891     printf("——————————————————————欢迎来到本超市————————————————————
    ");
     892     printf("————————————————————输入商品id以加入购物车——————————————————
    ");
     893     char spid5[20];
     894     scanf("%s", spid5);
     895     if (!strcmp(spid5, "-1"))yonhu(usi);
     896     int flag12 = 1, t2;
     897     for (int i = 0; i < countsp2; i++)
     898      if (!strcmp(spid5, sp[i].cmyID))
     899      {
     900       flag12 = 0;
     901       t2 = i;
     902      }
     903     if (flag12)
     904     {
     905      printf("没有此id对应的商品
    ");
     906      _sleep(1000);
     907     }
     908     else
     909     {
     910      while (1)
     911      {
     912       system("cls");
     913       printf("————————————
    已选中商品:%s
    价格:%d
    库存:%d
    
    
    ", sp[t2].name, sp[t2].money, sp[t2].kuchun);
     914       printf("1——————加入购物车
    2——————返回商品信息
    ");
     915       char flag13;
     916       flag13 = getch();
     917       if (flag13 == '1')
     918       {
     919        goshopcar(usi, t2);
     920       }
     921       else if (flag13 == '2')
     922       {
     923        kehuchakansp(usi);
     924       }
     925      }
     926     }
     927    }
     928   }
     929   if (fla2 == '2')
     930   {
     931    yonhu(usi);
     932   }
     933  }
     934  
     935 }
     936 void exeit()
     937 {
     938  system("cls");
     939  printf("——————欢迎下次再来——————");
     940  
     941  FILE*fp;
     942  fp = fopen("chaoshiahuju", "wb");
     943  fwrite(&count, sizeof(int), 1, fp);
     944  fwrite(&countsp2, sizeof(int), 1, fp);
     945  for (int i = 0; i<countsp2; i++)
     946   fwrite(&sp[i], sizeof(cm), 1, fp);
     947  for (int i = 0; i < count; i++)
     948   fwrite(&kehu[i], sizeof(users), 1, fp);
     949  fwrite(&weti, sizeof(wt), 1, fp);
     950  fclose(fp);
     951  _sleep(1000);
     952  exit(0);
     953  
     954 }
     955 void zjiasp()
     956 {
     957  system("cls");
     958  char spid2[20];
     959  getchar();
     960  printf("请输入商品id
    ");
     961  
     962  gets_s(spid2);
     963  
     964  
     965  if (spid2 == "-")guangliyuan();
     966  int flag9 = 0, t2;
     967  for (int i = 0; i<countsp2; i++)
     968   if (!strcmp(spid2, sp[i].cmyID))
     969   {
     970    flag9 = 1;
     971    t2 = i;
     972   }
     973  if (flag9)
     974  {
     975   printf("id已存在请重新输入
    ");
     976   _sleep(1000);
     977   zjiasp();
     978   
     979  }
     980  else
     981  {
     982   char spname[40];
     983   int spmony,spkuchun;
     984   printf("请输入商品名称
    ");
     985   getchar();
     986   scanf("%s", spname);
     987   printf("请输入商品价格
    ");
     988   scanf("%d", &spmony);
     989   printf("请输入商品库存
    ");
     990   scanf("%d", &spkuchun);
     991   strcpy(sp[countsp2].name, spname);
     992   strcpy(sp[countsp2].cmyID, spid2);
     993   sp[countsp2].kuchun = spkuchun;
     994   sp[countsp2].money = spmony;
     995   sp[countsp2].commentcount = 0;
     996   countsp1++;
     997   countsp2++;
     998   printf("增加商品成功");
     999   _sleep(1000);
    1000   guangliyuan();
    1001  }
    1002 }
    1003 void shanchu()
    1004 {
    1005  system("cls");
    1006  spxx();
    1007  printf("1——————删除商品
    2——————返回上一层
    ");
    1008  char ff = getch();
    1009  if (ff == '2')guangliyuan();
    1010  if (ff == '1')
    1011  {
    1012   system("cls");
    1013   spxx();
    1014   char spid2[20];
    1015   printf("————————————请输入要删除的商品的id————————————
    ");
    1016   scanf("%s", spid2);
    1017   if (!strcmp(spid2, "-1"))guangliyuan();
    1018   int flag9 = 1, t2;
    1019   for (int i = 0; i < countsp2; i++)
    1020    if (!strcmp(spid2, sp[i].cmyID))
    1021    {
    1022     flag9 = 0;
    1023     t2 = i;
    1024    }
    1025   if (flag9)
    1026   {
    1027    printf("没有此id对应的商品
    ");
    1028    _sleep(1000);
    1029    shanchu();
    1030   }
    1031   else
    1032   {
    1033    printf("Y——确定   N——取消
    ");
    1034    char flag21 = getch();
    1035    if (flag21 == 'Y')
    1036    {
    1037     cm temp = sp[t2];
    1038     sp[t2] = sp[countsp2 - 1];
    1039     sp[countsp2 - 1] = temp;
    1040     countsp2--;
    1041     printf("正在删除.....
    ");
    1042     _sleep(1000);
    1043     printf("删除成功");
    1044     _sleep(1000);
    1045     guangliyuan();
    1046    }
    1047    if (flag21 == 'N')
    1048    {
    1049     printf("正在取消......");
    1050     _sleep(800);
    1051     system("cls");
    1052     printf("已取消......");
    1053     _sleep(200);
    1054     guangliyuan();
    1055     //取消交易
    1056    }
    1057   }
    1058  }
    1059  if (ff != '2'&&ff != '1')shanchu();
    1060 }
    1061 void xiugai()
    1062 {
    1063  system("cls");
    1064  spxx();
    1065  printf("1——————修改商品
    2——————返回上一层
    ");
    1066  char ff = getch();
    1067  if (ff == '2')guangliyuan();
    1068  if (ff == '1')
    1069  {
    1070   system("cls");
    1071   spxx();
    1072   printf("————————————请输入要修改的商品的id————————————
    ");
    1073   char spid3[20];
    1074   gets_s(spid3);
    1075   if (spid3 == "-")guangliyuan();
    1076   int flag9 = 1, t3;
    1077   for (int i = 0; i < countsp2; i++)
    1078    if (!strcmp(spid3, sp[i].cmyID))
    1079    {
    1080     flag9 = 0;
    1081     t3 = i;
    1082    }
    1083   if (flag9)
    1084   {
    1085    printf("没有此商品请重新输入");
    1086    _sleep(1000);
    1087    xiugai();
    1088   }
    1089   else
    1090   {
    1091    printf("商品修改前名称:%s
    请输入商品新的名称
    ", sp[t3].name);
    1092    scanf("%s", sp[t3].name);
    1093    printf("商品修改前价格:%d
    请输入商品新的价格
    ", sp[t3].money);
    1094    scanf("%d", &sp[t3].money);
    1095    printf("商品修改前库存:%d
    请输入商品新的库存
    ", sp[t3].kuchun);
    1096    scanf("%d", &sp[t3].kuchun);
    1097    printf("修改成功");
    1098    _sleep(1000);
    1099    xiugai();
    1100   }
    1101   if (ff != '1'&&ff != '2')
    1102   {
    1103    xiugai();
    1104   }
    1105  }
    1106 
    1107 }
    1108 void guangliyuan()
    1109 {
    1110  while (1)
    1111  {
    1112   system("cls");
    1113   printf("1————增加商品
    2————删除商品
    3————修改商品信息
    4————查看商品信息
    5————查看客户问题
    6——————返回登录
    ");
    1114   char flag7 = getch();
    1115   if (flag7 == '1')
    1116   {
    1117    zjiasp();
    1118    guangliyuan();
    1119   }
    1120   else if (flag7 == '2')
    1121   {
    1122    shanchu();
    1123   }
    1124   else if (flag7 == '3')
    1125   {
    1126    xiugai();
    1127    guangliyuan();
    1128   }
    1129   else if (flag7 == '4')
    1130   {
    1131    
    1132    spxx();
    1133    printf("————————按任意键返回上一层————————");
    1134    getchar();
    1135    getch();
    1136    
    1137    guangliyuan();
    1138   }
    1139   else if (flag7 == '6')
    1140   {
    1141    den();
    1142   }
    1143   else if (flag7 == '5')
    1144   {
    1145    kehuwent();
    1146   }
    1147  }
    1148 }
    1149 void yonhu(int usi)
    1150 {
    1151  while (1)
    1152  {
    1153   system("cls");
    1154   char flag10;
    1155   printf("1————查看商品
    2————查看购物车
    3————查看余额|充值余额
    4————账户问题
    5————查看购物记录
    6————退出登录
    ");
    1156   flag10=getch();
    1157   if (flag10 == '1')
    1158   {
    1159    kehuchakansp(usi);
    1160   }
    1161   else if (flag10 == '2')
    1162   {
    1163    shopcar(usi);
    1164   }
    1165   else if (flag10 == '3')
    1166   {
    1167    chonzhi(usi);
    1168   }
    1169   else if (flag10 == '6')
    1170   {
    1171    den();
    1172   }
    1173   else if (flag10 == '4')
    1174   {
    1175    zhanghuwenti(usi);
    1176   }
    1177   else if(flag10=='5')
    1178   {
    1179    chakangwjl(usi);
    1180   }
    1181  }
    1182 }
    1183 void zhuc()
    1184 {
    1185  char usname[20];
    1186  char  password[20], passwordag[20];
    1187  system("cls");
    1188  printf("请输入用户名
    ");
    1189  scanf("%s", usname);
    1190  int flag3 = 0;
    1191  for (int i = 0; i < count; i++)
    1192  {
    1193   if (!strcmp(usname, kehu[i].username))flag3 = 1;
    1194  }
    1195  if (flag3)
    1196  {
    1197   printf("用户名已经存在请重新输入");
    1198   _sleep(1000);
    1199   zhuc();
    1200  }
    1201  else
    1202  {
    1203   int flag6 = 0;
    1204   while (1)
    1205   {
    1206    printf("请输入密码
    ");
    1207    strcpy(password, passw());
    1208    system("cls");
    1209    printf("请再次输入密码
    ");
    1210    strcpy(passwordag, passw());
    1211    if (strcmp(password, passwordag))
    1212    {
    1213     printf("两次密码不相同,请重新输入密码
    ");
    1214     _sleep(1000);
    1215    }
    1216    else
    1217    {
    1218     system("cls");
    1219     printf("请输入您的邮箱地址
    ");
    1220     scanf("%s", kehu[count].youxiang);
    1221     system("cls");
    1222     printf("注册成功");
    1223     _sleep(1000);
    1224     strcpy(kehu[count].username, usname);
    1225     strcpy(kehu[count].password, password);
    1226     kehu[count].jilucount = 0;
    1227     kehu[count].usermony = 100;
    1228     kehu[count++].shopcount = 0;
    1229     flag6 = 1;
    1230     break;
    1231    }
    1232   }
    1233   if (flag6)den();
    1234  }
    1235 }
    1236 void den()
    1237 {
    1238  char flag1;
    1239  while (1)
    1240  {
    1241   system("cls");
    1242   printf("1——客户登录
    2——管理员登录
    3——返回上一层
    ");
    1243   flag1 = getch();
    1244   if (flag1 == '1')
    1245   {
    1246    while (1)
    1247    {
    1248     char name1[20];
    1249     char password2[20];
    1250     system("cls");
    1251     printf("请输入账户名
    ");
    1252     scanf("%s", name1);
    1253     if (!strcmp(name1, "-1"))break;
    1254     int flag4 = 0, t1;
    1255     for (int i = 0; i < count; i++)
    1256     {
    1257      if (!strcmp(name1, kehu[i].username))
    1258      {
    1259       flag4 = 1;
    1260       t1 = i;
    1261      }
    1262     }
    1263     if (flag4 == 0)
    1264     {
    1265      while (1)
    1266      {
    1267       printf("用户名不存在
    ");
    1268       printf("1————重新输入
    2————返回上一层
    ");
    1269       char fla1 = getch();
    1270       if (fla1 == '1')break;
    1271       if (fla1 == '2')den();
    1272       _sleep(1000);
    1273      }
    1274     }
    1275     else
    1276     {
    1277      printf("请输入密码
    ");
    1278      strcpy(password2, passw());
    1279      if (!strcmp(password2, "-1"))den();
    1280      if (!strcmp(password2, kehu[t1].password))
    1281      {
    1282       system("cls");
    1283       printf("登入成功");
    1284       _sleep(1000);
    1285       
    1286       yonhu(t1);
    1287       
    1288      }
    1289      else
    1290      {
    1291       printf("密码不正确");
    1292       _sleep(1000);
    1293      }
    1294     }
    1295    }
    1296   }
    1297   if (flag1 == '2')
    1298   {
    1299    char name2[20];
    1300    char password3[20];
    1301    while (1)
    1302    {
    1303     system("cls");
    1304     printf("请输入账户名
    ");
    1305     scanf("%s", name2);
    1306     if (!strcmp(name2, "-1"))break;
    1307     if (strcmp(name2, adm))
    1308     {
    1309      while (1)
    1310      {
    1311       printf("用户名不存在
    ");
    1312       printf("1————重新输入
    2————返回上一层
    ");
    1313       char fla1 = getch();
    1314       if (fla1 == '1')break;
    1315       if (fla1 == '2')den();
    1316       _sleep(1000);
    1317      }
    1318      
    1319     }
    1320     else
    1321     {
    1322      printf("请输入密码
    ");
    1323      strcpy(password3, passw());
    1324      if (strcmp(password3, admpassword))
    1325      {
    1326       printf("密码不正确
    ");
    1327      }
    1328      else
    1329      {
    1330       system("cls");
    1331       printf("登录成功");
    1332       _sleep(1000);
    1333       //后续程序
    1334       guangliyuan();
    1335       
    1336      }
    1337     }
    1338    }
    1339    exeit();
    1340   }
    1341   if (flag1 == '3')
    1342   {
    1343    csjm();
    1344   }
    1345  }
    1346 }
    1347 void csjm() 
    1348 {
    1349  while (1)
    1350  {
    1351   system("cls");
    1352   char flag5 = 0;
    1353   char flag2 = '0';
    1354   while (1)
    1355   {
    1356    system("cls");
    1357    printf("1——登录
    2——注册
    3——账户问题
    4——设置
    5——退出
    ");
    1358    flag2 = getch();
    1359    if (flag2 == '1')
    1360    {
    1361     den();
    1362     break;
    1363    }
    1364    if (flag2 == '2')
    1365    {
    1366     zhuc();
    1367     break;
    1368    }
    1369    if (flag2 == '5')
    1370    {
    1371     system("cls");
    1372     printf("——————欢迎下次再来——————");
    1373     _sleep(1000);
    1374     exeit();
    1375     
    1376    }
    1377    if (flag2 == '3')
    1378    {
    1379     while (1)
    1380     {
    1381      system("cls");
    1382      printf("1————修改密码
    2————找回密码
    3————返回上一级
    ");
    1383      char flag29 = getch();
    1384      if (flag29 == '1')
    1385      {
    1386       xiugaipassw(-1);
    1387      }
    1388      if (flag29 == '2')
    1389      {
    1390       zhaohuipassw();
    1391      }
    1392      if (flag29 == '3')break;
    1393     }
    1394     
    1395    }
    1396    if (flag2 == '4')
    1397    {
    1398     shezhi();
    1399    }
    1400   }
    1401  }
    1402 }
    1403 int main()
    1404 {
    1405  FILE*fp;
    1406  fp = fopen("chaoshiahuju", "rb+");
    1407  fread(&count, sizeof(int), 1, fp);
    1408  fread(&countsp2, sizeof(int), 1, fp);
    1409  for (int i = 0; i<countsp2; i++)
    1410   fread(&sp[i], sizeof(cm), 1, fp);
    1411  for (int i = 0; i < count; i++)
    1412   fread(&kehu[i], sizeof(users), 1, fp);
    1413  fread(&weti, sizeof(wt), 1, fp);
    1414  fclose(fp);
    1415  /*本代码及设计由缪传鹏版权所有 未经允许不得商用 The copyright of the design program belongs to Miaoz, it cannot be used for commerce without permission.*/
    1416  system("color 70");
    1417  csjm();
    1418  return 0;
    1419 }
  • 相关阅读:
    各种redis的介绍:ServiceStack.Redis,StackExchange.Redis,CSRedis
    nginx 配置web服务
    安装Office Online Server
    买房哪些事?
    微服务演变:微服务架构介绍
    VUE 前端调用Base64加密,后端c#调用Base64解密
    程序员35岁前必须做完的事
    Vue 开发流程
    小程序快速认证
    vue页面打印成pdf
  • 原文地址:https://www.cnblogs.com/miaos/p/miaoz-1-3.html
Copyright © 2020-2023  润新知