|
|
#2
寒风中的细雨2011-04-21 12:41
|
程序代码:#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
struct jiadian
{
int num; //编号
int dj; //单价
int sl; //数量
};
typedef struct node
{
jiadian jd;
struct node *next;
}lnode,linklist;
void menuprint() //菜单1
{
cout<<"\t*************************商场家电库存***********************"<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 1冰箱"<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 2电视机"<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 3洗衣机"<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 4电脑"<<endl;
}
linklist* creatlinklistl() //创建表
{
menuprint();
linklist *h;
lnode *s=(lnode *)malloc(sizeof(lnode));
h=(lnode *)malloc(sizeof(lnode));
h->next=NULL;
printf("请输入家电编号并且以#结束:");
scanf(" %d",&s->jd.num);
while(s->jd.num!='#') //当x等于#时结束
{
s=(lnode *)malloc(sizeof(lnode));
cout<<"请输入家电的单价:"<<endl;
scanf("% d",s->jd.dj);
cout<<"请输入家电的数量:"<<endl;
scanf("% d",s->jd.sl);
s->next=h->next;
h->next=s;
cout<<"请输入家电的编号并以#结束"<<endl;
scanf(" %d",&s->jd.num);
}
return h;
}
void main()
{
creatlinklistl(); //创建表
}
这只是我写的一部分,执行时出错,我不知道怎么改???、 #include<stdlib.h>
#include<stdio.h>
struct jiadian
{
int num; //编号
int dj; //单价
int sl; //数量
};
typedef struct node
{
jiadian jd;
struct node *next;
}lnode,linklist;
void menuprint() //菜单1
{
cout<<"\t*************************商场家电库存***********************"<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 1冰箱"<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 2电视机"<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 3洗衣机"<<endl;
cout<<"\t\t "<<endl;
cout<<"\t\t 4电脑"<<endl;
}
linklist* creatlinklistl() //创建表
{
menuprint();
linklist *h;
lnode *s=(lnode *)malloc(sizeof(lnode));
h=(lnode *)malloc(sizeof(lnode));
h->next=NULL;
printf("请输入家电编号并且以#结束:");
scanf(" %d",&s->jd.num);
while(s->jd.num!='#') //当x等于#时结束
{
s=(lnode *)malloc(sizeof(lnode));
cout<<"请输入家电的单价:"<<endl;
scanf("% d",s->jd.dj);
cout<<"请输入家电的数量:"<<endl;
scanf("% d",s->jd.sl);
s->next=h->next;
h->next=s;
cout<<"请输入家电的编号并以#结束"<<endl;
scanf(" %d",&s->jd.num);
}
return h;
}
void main()
{
creatlinklistl(); //创建表
}