#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
void value_box(box maker1);
void address_box(box* maker2);
int main()
{
using namespace std;
box maker1;
cout << "Ener the maker's name: ";
cin.getline(maker1.maker, 40);
cout << "Ener the height,width,length,volume: ";
cin >> maker1.height >> maker1.width >> maker1.length >> maker1.volume;
box maker2;
cout << "Now we use value to transmit struct." << endl;
cout << "______________________________________________" << endl;
value_box(maker1);
cout << "Now we use address to transmit struct." << endl;
cout << "______________________________________________" << endl;
address_box(&maker2);
return 0;
}
void value_box(box maker1)
{
using namespace std;
cout << "The makes name is: " << maker1.maker << ", and the height is: " << maker1.height
<< ",width is " << maker1.width << ",length is " << maker1.length << ",volume is " << maker1.volume<< endl;
cin.get();
}
void address_box(box* maker2)
{
using namespace std;
cout << "Enter the maker's name: ";
cin.getline(maker2->maker, 40);
cout << "Ener the height,width,length,volume: ";
cin >> maker2->height >> maker2->width >> maker2->length;
maker2->volume = maker2->height*maker2->length*maker2->width;
cout << "The maker's name is: " << maker2->maker << ", and the height is: " << maker2->height
<< ",width is " << maker2->width << ",length is " << maker2->length << ",volume is " << maker2->volume << endl;
}
C++ primer plus第六版课后编程练习答案:7.3
最新推荐文章于 2024-09-17 11:03:04 发布