超市商品购买与管理系统

熬了 三天做出来的 可能还有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] = '