会的帮我哈

作者在 2008-11-18 14:35:27 发布以下内容

#include "stdafx.h"

#include "stdio.h"

#include "iostream.h"

#include "stdlib.h"

#include "string.h"

#include "dos.h"

#include "time.h"

 

struct gouwu

{

       char bianhao[5];

       char pinming[20];

       int number;

       double price;

};

typedef gouwu DataType;

 

#include "SeqList.h"

void main(void)

{

       int zongshu=0;

       char bh[5];

       double zongjia=0,zgjg=0;

 

   

       SeqList   myList(100);

       gouwu a[5]={

              {"001","罐头",2,20.00},

              {"002","猪肉",3,45.00},

              {"003","巧克力",5,60.00},

              {"004","西红柿",2,6.00},

              {"005","苹果",3,9.00}};

       int n=5;

       DataType g;

       for(int i=0;i<n;i++)

          myList.Insert(a[i],i);

       time_t   t   =   time(NULL);

       cout<<"----洋洋百货超市----"<<endl;

    printf("时间为:%s", ctime(&t));

       cout<<endl;

cout<<"-----------------------------"<<endl;

       cout<<"编号      品名     数量  价格"<<endl;

       cout<<"-----------------------------"<<endl;

       for(i=0;i<myList.Size();i++)

       {

              g=myList.GetData(i);

              printf("%-10s%-10s%-5d%.2f\n",g.bianhao,g.pinming,g.number,g.price);

              zongshu=zongshu+g.number;

              zongjia=zongjia+g.price;

              if(zgjg<g.price)

              {

                     zgjg=g.price;

                     strcpy(bh,g.bianhao);

              }

       }

              printf("\n商品总数:%d\n总价格:%.2f\n最高价格商品编号:%s\n",zongshu,zongjia,bh);

}

在中间在加入一个排序算法

按那个number和price排列

 

默认分类 | 阅读 1365 次
文章评论,共0条
游客请输入验证码
文章分类
文章归档
最新评论