建立关于图书的详细目录。实现录入每本书的相关信息:书名、作者、出版社、出版日期、页数、册数及价格
程序实现:录入大于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);
}
后面该如何做比较,,,指针不会。。 展开
#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);
}
后面该如何做比较,,,指针不会。。 展开
3个回答
展开全部
#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;
}
#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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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;
#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;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询