结构体初用法1

#include <iostream>
#include <cstring>


using namespace std;


struct Date
{
int year;
int month;
int day;
};


struct Book
{
string name;
double price;
string press;
Date date;
};


void display(Book b)
{
    cout<<"  书  名: "<<b.name<<endl;
    cout<<"  价  格: "<<b.price<<endl;
    cout<<"  出版社: "<<b.press<<endl;
    cout<<"出版日期: "<<b.date.year<<"年"<<b.date.month<<"月"<<b.date.day<<"日"<<endl;
}


int main()
{
    Book cbook={"c++程序设计(第二版)",48.00,"清华大学出版社",{2011,8,1}};
    display(cbook);
   
return 0;
}

猜你喜欢

转载自blog.csdn.net/wrc_nb/article/details/80034677
今日推荐