当前位置:编程学习 > C/C++ >>

跪求C语言服装销售系统代码,要能运行的,谢谢!~

要求:

服装销售系统的功能是完成服装信息(服装代码、型号、规格、面料、颜色、单价、数量)先曾、修改和查找功能及服装销售信息(服装代码、数量、日期、售价、小计)登记和查找功能。销售服装时相应的服装信息数量要进行修改(比如原来有100件,销售了50件后只能剩余50件)。

提示:

(1)       用两个文件存放服装信息和销售信息;

(2)       定义结构体表示服装信息和销售信息;

(3)       打印系统操作菜单:N.服装信息登记;M.服装信息修改;D.服装信息删除;S.服装销售登记;Q.退出系统。

答案:闲着无聊,就帮你写个呗。

功能:N.服装信息登记;M.服装信息修改;D.服装信息删除;S.服装销售登记;Q.退出系统。

-------------------------------

#include <stdio.h>
#include <stdlib.h>

void regist(void);
void revise(void);
void delet(void);
void sell(void);

typedef struct clothes
{
 int code;
 char model[10];
 char spec[10];
 char stuff[10];
 char color[10];
 int price;
 int num;
}Cloth;

typedef struct sell
{
 int code;
 int num;
 char date[20];
 int price;
 int cnt;
}Sell;

int main(void)
{
 char item;
 printf("\t服装销售系统\n\n");
 printf("N.服装信息登记\n");
 printf("M.服装信息修改\n");
 printf("D.服装信息删除\n");
 printf("S.服装销售登记\n");
 printf("Q.退出\n\n");
 printf("请选择->\n");
 item = getchar();
 switch(item)
 {
 case 'N':
  regist();
 case 'M':
  revise();
 case 'D':
  delet();
 case 'S':
  sell();
 case 'Q':
  exit(1);
 }
 return 0;
}

//服装信息登记
void regist(void)
{
 Cloth clo;
 FILE *fp;
 printf("请依次录入服装代码、型号、规格、面料、颜色、单价、数量:\n");
 scanf("%d",&clo.code);
 scanf("%s",clo.model);
 scanf("%s",clo.spec);
 scanf("%s",clo.stuff);
 scanf("%s",clo.color);
 scanf("%d",&clo.price);
 scanf("%d",&clo.num);
 fp = fopen("clothse_info.txt","a");
 fprintf(fp,"%d\n",clo.code);
 fprintf(fp,"%s\n",clo.model);
 fprintf(fp,"%s\n",clo.spec);
 fprintf(fp,"%s\n",clo.stuff);
 fprintf(fp,"%s\n",clo.color);
 fprintf(fp,"%d\n",clo.price);
 fprintf(fp,"%d\n",clo.num);
 fclose(fp);
 printf("登记完成\n\n");
}

//服装信息修改
void revise(void)
{
 Cloth clo[50],rev;
 int code;
 int i=0,j;
 int flag=0;
 FILE *fp;
 printf("请输入服装代码:\n");
 scanf("%d",&code);
 if((fp = fopen("clothse_info.txt","r")) == NULL)
 {
  printf("没有服装信息");
  return;
 }
 while(!feof(fp))
 {
  fscanf(fp,"%d",&clo[i].code);
  fscanf(fp,"%s",clo[i].model);
  fscanf(fp,"%s",clo[i].spec);
  fscanf(fp,"%s",clo[i].stuff);
  fscanf(fp,"%s",clo[i].color);
  fscanf(fp,"%d",&clo[i].price);
  fscanf(fp,"%d",&clo[i].num);
  if(clo[i].code == code)
  {
   flag = 1;
  // break;
  }
  i++;
 }
 fclose(fp);
 if(flag)
 {
  printf("请依次录入服装代码、型号、规格、面料、颜色、单价、数量:\n");
  scanf("%d",&rev.code);
  scanf("%s",rev.model);
  scanf("%s",rev.spec);
  scanf("%s",rev.stuff);
  scanf("%s",rev.color);
  scanf("%d",&rev.price);
  scanf("%d",&rev.num);
  fp = fopen("clothse_info.txt","w");
  for(j=0;j<i-1;j++)
  {
   if(clo[j].code != code)
   {
    fprintf(fp,"%d\n",clo[j].code);
    fprintf(fp,"%s\n",clo[j].model);
    fprintf(fp,"%s\n",clo[j].spec);
    fprintf(fp,"%s\n",clo[j].stuff);
    fprintf(fp,"%s\n",clo[j].color);
    fprintf(fp,"%d\n",clo[j].price);
    fprintf(fp,"%d\n",clo[j].num);
   }
   else
   {
    fprintf(fp,"%d\n",rev.code);
    fprintf(fp,"%s\n",rev.model);
    fprintf(fp,"%s\n",rev.spec);
    fprintf(fp,"%s\n",rev.stuff);
    fprintf(fp,"%s\n",rev.color);
    fprintf(fp,"%d\n",rev.price);
    fprintf(fp,"%d\n",rev.num);
   }
  }
  fclose(fp);
 }
 printf("修改完成\n\n");
}

//服装信息删除
void delet(void)
{
 Cloth clo[50];
 int code;
 int i=0,j;
 int flag=0;
 FILE *fp;
 printf("请输入服装代码:\n");
 scanf("%d",&code);
 if((fp = fopen("clothse_info.txt","r")) == NULL)
 {
  printf("没有服装信息");
  return;
 }
 while(!feof(fp))
 {
  fscanf(fp,"%d",&clo[i].code);
  fscanf(fp,"%s",clo[i].model);
  fscanf(fp,"%s",clo[i].spec);
  fscanf(fp,"%s",clo[i].stuff);
  fscanf(fp,"%s",clo[i].color);
  fscanf(fp,"%d",&clo[i].price);
  fscanf(fp,"%d",&clo[i].num);
  if(clo[i].code == code)
  {
   flag = 1;
  }
  i++;
 }
 fclose(fp);
 if(flag)
 {
  fp = fopen("clothse_info.txt","w");
  for(j=0;j<i-1;j++)
  {
   if(clo[j].code != code)
   {
    fprintf(fp,"%d\n",clo[j].code);
    fprintf(fp,"%s\n",clo[j].model);
    fprintf(fp,"%s\n",clo[j].spec);
    fprintf(fp,"%s\n",clo[j].stuff);
    fprintf(fp,"%s\n",clo[j].color);
    fprintf(fp,"%d\n",clo[j].price);
    fprintf(fp,"%d\n",clo[j].num);
   }
  }
  fclose(fp);
 }
 printf("已删除\n\n");
}

//服装销售登记
void sell(void)
{
 Sell sel;
 Cloth clo[50];
 FILE *fp;
 int i=0,j;
 if((fp = fopen("clothse_info.txt","r")) == NULL)
 {
  printf("没有服装信息");
  return;
 }
 while(!feof(fp))
 {
  fscanf(fp,"%d",&clo[i].code);
  fscanf(fp,"%s",clo[i].model);
  fscanf(fp,"%s",clo[i].spec);
  fscanf(fp,"%s",clo[i].stuff);
  fscanf(fp,"%s",clo[i].color);
  fscanf(fp,"%d",&clo[i].price);
  fscanf(fp,"%d",&clo[i].num);
  i++;
 }
 fclose(fp);
 printf("请输入服装代码、数量、日期、售价:\n");
 scanf("%d",&sel.code);
 scanf("%d",&sel.num);
 scanf("%s",sel.date);
 scanf("%d",&sel.price);
 sel.cnt = sel.num*sel.price; /*小记*/
 fp = fopen("clothse_sell.txt","a");
 fprintf(fp,"%d\n",sel.code);
 fprintf(fp,"%d\n",sel.num);
 fprintf(fp,"%s\n",sel.date);
 fprintf(fp,"%d\n",sel.price);
 fprintf(fp,"%d\n",sel.cnt);
 fclose(fp);
 fp = fopen("clothse_info.txt","w");
 for(j=0;j<i-1;j++)
 {
  if(clo[j].code == sel.code)
  {
   fprintf(fp,"%d\n",clo[j].code);
   fprintf(fp,"%s\n",clo[j].model);
   fprintf(fp,"%s\n",clo[j].spec);
   fprintf(fp,"%s\n",clo[j].stuff);
   fprintf(fp,"%s\n",clo[j].color);
   fprintf(fp,"%d\n",clo[j].price);
   fprintf(fp,"%d\n",clo[j].num-sel.num);
  }
  else
  {
   fprintf(fp,"%d\n",clo[j].code);
   fprintf(fp,"%s\n",clo[j].model);
  &nb

上一个:用C语言编写一个图书管理系统(录入、查询、排序,文件操作)…………
下一个:什么是basic语言,c语言

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,