⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p1-51.cpp

📁 C++应用编程200例--------专为广大学习和使用C++语言的读者设计的
💻 CPP
字号:
#include<iostream.h>
main()
{
    //定义结构类型
    struct    books
    {
    char   title[20];
    char   author[15];
    int    pages;
    float  price;
    } ;
    
    //声明结构变量
    struct books Zbk={"VC++ ","Zhang",295,35.5}; 
    books Wbk;  

    //对结构变量的输出
    cout<<"Zbk:"<<endl;
    cout<<Zbk.title <<endl;
    cout<<Zbk.author<<endl;
    cout<<Zbk.pages<<endl;
    cout<<Zbk.price<<endl;
    cout<<"--------------------"<<endl;

    //对结构成员的运算
    Zbk.pages+=10;
    Zbk.price+=0.5;
    cout<<"Zbk.pages="<<Zbk.pages<<endl;
    cout<<"Zbk.price="<<Zbk.price<<endl;
    cout<<"--------------------"<<endl;

    //对结构变量的输入输出
    cout<<"Wbk.title =";
    cin>>Wbk.title;
    cout<<"Wbk.author=";
    cin>>Wbk.author;
    cout<<"Wbk.pages=";
    cin>>Wbk.pages;
    cout<<"Wbk.price=";
    cin>>Wbk.price;
    cout<<"Wbk:"<<endl;
    cout<<Wbk.title <<endl;
    cout<<Wbk.author<<endl;
    cout<<Wbk.pages<<endl;
    cout<<Wbk.price<<endl;
    cout<<"--------------------"<<endl;

    //结构变量之间的相互赋值
    books temp;
    temp=Wbk;
    cout<<"temp:"<<endl;
    cout<<temp.title<<endl;
    cout<<temp.author<<endl;
    cout<<temp.pages<<endl;
    cout<<temp.price<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -