建立关于图书的详细目录。实现录入每本书的相关信息:书名、作者、出版社、出版日期、页数、册数及价格

程序实现:录入大于5条记录(记录信息要有意义);显示界面提示用户可选择按书名排序、作者排序、价格排序;计算图书平均价格#include<stdio.h>#include<... 程序实现:录入大于5条记录(记录信息要有意义);显示界面提示用户可选择按 书名排序、作者排序、价格排序;计算图书平均价格
#include<stdio.h>
#include<string.h>
struct book
{
char name[5];
char writer[5];
char press[5];
int page;
int copy;
float prise;

}book[5];
main()
{
int i,j;
int type;
int a[10]={0};
float len;
float average=0;
for(i=1;i<=5;i++)
{
printf("请输入第%d本书的书名、作者、出版社、页数、册数及价格\n",i);
scanf("%c,%c,%c,%d,%d,%f\n",&book[i].name,&book[i].writer,&book[i].press,&book[i].page,&book[i].copy,&book[i].prise);
}

后面该如何做比较,,,指针不会。。
展开
 我来答
畅夜桖Q7
2011-10-30 · TA获得超过295个赞
知道小有建树答主
回答量:370
采纳率:0%
帮助的人:316万
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct _book
{
char name[50];
char writer[50];
char press[50];
int page;
int copy;
float prise;

}book[5];

void swap(struct _book *a, struct _book *b)
{
struct _book temp;
temp = *a;
*a = *b;
*b = temp;
}

// 升序排列
void sortByName(struct _book *a)
{
int result = 0;
int MAXLENGTH = 5;

for (int i=0; i< MAXLENGTH-1; i++)
{
for(int j=i+1; j< MAXLENGTH; j++)
{
result = strcmp(a[i].name, a[j].name);
if (result > 0) //升序
swap(&a[i], &a[j]);
}
}

}

void getInfo()
{
/*for(i=0;i<5;i++)
{
printf("请输入第%d本书的书名、作者、出版社、页数、册数及价格\n",i);
scanf("%s %s %s %d %d %f",&book[i].name,&book[i].writer,&book[i].press,&book[i].page,&book[i].copy,&book[i].prise);
}*/

strcpy(book[0].name, "数据结构");
strcpy(book[0].writer, "程杰");
strcpy(book[0].press , "清华大学出版社");
book[0].page = 500;
book[0].copy = 4;
book[0].prise = 45.6;

strcpy(book[1].name , "c#本质论");
strcpy(book[1].writer , "程杰");
strcpy(book[1].press, "清华大学出版社");
book[1].page = 500;
book[1].copy = 4;
book[1].prise = 45.6;

strcpy(book[2].name , "数据结构");
strcpy(book[2].writer, "程杰");
strcpy(book[2].press, "清华大学出版社");
book[2].page = 500;
book[2].copy = 4;
book[2].prise = 45.6;

strcpy(book[3].name, "数据结构");
strcpy(book[3].writer, "程杰");
(book[3].press, "清华大学出版社");
book[3].page = 500;
book[3].copy = 4;
book[3].prise = 45.6;

strcpy(book[4].name, "asdf");
strcpy(book[4].writer, "asdf\0");
strcpy(book[4].press, "asdf\0");
book[4].page = 500;
book[4].copy = 4;
book[4].prise = 45.6;
}

void display()
{
int i=0;
puts("打印信息");
for(i=0; i<5; i++)
printf("%s,%s,%s,%d,%d,%f\n",book[i].name,book[i].writer,book[i].press,book[i].page,book[i].copy,book[i].prise);
}

int main()
{
int i,j;
int type;
int a[10]={0};
float len;
float average=0;

getInfo();
display();

sort(book);
display();

return 0;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
呐摩那6905
2012-05-22 · TA获得超过7万个赞
知道大有可为答主
回答量:3.9万
采纳率:0%
帮助的人:5062万
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct _book
{
char name[50];
char writer[50];
char press[50];
int page;
int copy;
float prise;

}book[5];

void swap(struct _book *a, struct _book *b)
{
struct _book temp;
temp = *a;
*a = *b;
*b = temp;
}

// 升序排列
void sortByName(struct _book *a)
{
int result = 0;
int MAXLENGTH = 5;

for (int i=0; i< MAXLENGTH-1; i++)
{
for(int j=i+1; j< MAXLENGTH; j++)
{
result = strcmp(a[i].name, a[j].name);
if (result > 0) //升序
swap(&a[i], &a[j]);
}
}

}

void getInfo()
{
/*for(i=0;i<5;i++)
{
printf("请输入第%d本书的书名、作者、出版社、页数、册数及价格\n",i);
scanf("%s %s %s %d %d %f",&book[i].name,&book[i].writer,&book[i].press,&book[i].page,&book[i].copy,&book[i].prise);
}*/

strcpy(book[0].name, "数据结构");
strcpy(book[0].writer, "程杰");
strcpy(book[0].press , "清华大学出版社");
book[0].page = 500;
book[0].copy = 4;
book[0].prise = 45.6;

strcpy(book[1].name , "c#本质论");
strcpy(book[1].writer , "程杰");
strcpy(book[1].press, "清华大学出版社");
book[1].page = 500;
book[1].copy = 4;
book[1].prise = 45.6;

strcpy(book[2].name , "数据结构");
strcpy(book[2].writer, "程杰");
strcpy(book[2].press, "清华大学出版社");
book[2].page = 500;
book[2].copy = 4;
book[2].prise = 45.6;

strcpy(book[3].name, "数据结构");
strcpy(book[3].writer, "程杰");
(book[3].press, "清华大学出版社");
book[3].page = 500;
book[3].copy = 4;
book[3].prise = 45.6;

strcpy(book[4].name, "asdf");
strcpy(book[4].writer, "asdf\0");
strcpy(book[4].press, "asdf\0");
book[4].page = 500;
book[4].copy = 4;
book[4].prise = 45.6;
}

void display()
{
int i=0;
puts("打印信息");
for(i=0; i<5; i++)
printf("%s,%s,%s,%d,%d,%f\n",book[i].name,book[i].writer,book[i].press,book[i].page,book[i].copy,book[i].prise);
}

int main()
{
int i,j;
int type;
int a[10]={0};
float len;
float average=0;

getInfo();
display();

sort(book);
display();

return 0;
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
纯息县难银
2011-10-31
知道答主
回答量:10
采纳率:0%
帮助的人:4.3万
展开全部
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式