zoukankan      html  css  js  c++  java
  • C++primer plus第六版课后编程题答案7.3

    7.3

    #include <iostream>
    using namespace std;
    struct box{
    	char marker[40];
    	float height;
    	float width;
    	float length;
    	float volume;
    };
    void show(const box b);
    void set(box &b);
    void main73()
    {
    	box b[2]={{"mybox",5,6,8,0},{"herbox",10,10,10,0}};//初始化结构数组
    	cout<<"now the box valus is :"<<endl;
    	cout<<"b[0] is :"<<endl;
    	show(b[0]);
    	cout<<"b[1] is :"<<endl;
    	show(b[1]);
    	set(b[0]); //因为我这里是数组,数组传递的时候其实就是传递其引用!
    	set(b[1]);
    	cout<<"after set ,the box valus is:
    
    
    ";
    	cout<<"b[0] is :"<<endl;
    	show(b[0]);
    	cout<<"b[1] is :"<<endl;
    	show(b[1]);
    
    	system("pause");
    
    }
    void show(const box b)
    {
    	cout<<"maker:"<<b.marker<<endl;
    	cout<<"height:"<<b.height<<"
    "<<b.width<<"
    length:"<<b.length<<endl;
    	cout<<"volume:"<<b.volume<<endl;
    }
    
    void set(box &b)
    {
    	b.volume=b.height*b.width*b.length;
    }


  • 相关阅读:
    集合操作
    聚合函数
    图存储3-十字链表
    图存储2-邻接表
    图存储1 临接矩阵
    字符串逆序,字符串翻转
    读写文件
    加密算法
    静态变量-动态变量
    【Qt】UserDefindeControl
  • 原文地址:https://www.cnblogs.com/qq84435/p/3664890.html
Copyright © 2011-2022 走看看