‘(’向后紧跟,‘)’、‘,’、‘;’向前紧跟,紧跟处不留空格

‘(’向后紧跟,‘)’、‘,’、‘;’向前紧跟,紧跟处不留空格。

 

 1 #include <iostream>
 2 #include<stdio.h>
 3 #define size 3
 4 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 5 
 6 
 7 using namespace std;
 8 //定义book结构类型
 9 struct book
10 {
11     char   title[20];
12     char   author[15];
13     int    pages;
14     float  price;
15 };
16 //book结构的输入函数
17 input_book(book& bk,char *name)
18 {
19     cout<<name<<":"<<endl;
20     cout<<"title:";
21     cin>>bk.title;
22     cout<<"author:";
23     cin>>bk.author;
24     cout<<"pages:";
25     cin>>bk.pages;
26     cout<<"price:";
27     cin>>bk.price;
28 }
29 //book结构的输出函数
30 output_book(book& bk,char *name)
31 {
32     cout<<name<<":  ";
33     cout<<bk.title<<" ";
34     cout<<bk.author<<" ";
35     cout<<bk.pages<<" ";
36     cout<<bk.price<<endl;
37 }
38 
39 int main(int argc, char** argv) {
40         //声明变量和结构数组
41     int i;
42     char str[20];
43     book bk[size];
44 
45     //输入结构数组
46     for(i=0;i<size;i++) {
47         sprintf(str,"bk[%d]",i+1);
48         input_book(bk[i],str);
49     }
50 
51     //显示结构数组
52     for(i=0;i<size;i++) {
53         sprintf(str,"bk[%d]",i+1);
54         output_book(bk[i],str);
55     }
56     return 0;
57     
58 }

 

posted @ 2018-08-03 11:33  borter  阅读(488)  评论(0编辑  收藏  举报