Skip to content

Instantly share code, notes, and snippets.

@mahata
Created September 16, 2011 18:48
Show Gist options
  • Save mahata/1222799 to your computer and use it in GitHub Desktop.
Save mahata/1222799 to your computer and use it in GitHub Desktop.
C++ Primer 7.3
#include <iostream>
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
void displayBox(box _box);
void calcBoxVolume(box * _box);
int main()
{
box xbox;
memset(xbox.maker, 0, sizeof(xbox.maker));
strncpy(xbox.maker, "Microsoft", sizeof(xbox.maker) -1);
xbox.height = 10.0;
xbox.width = 20.0;
xbox.length = 30.0;
calcBoxVolume(&xbox);
displayBox(xbox);
return 0;
}
void calcBoxVolume(box * _box)
{
_box->volume = _box->height * _box->width * _box->length;
}
void displayBox(box _box)
{
using namespace std;
cout << "maker: " << _box.maker << endl;
cout << "height: " << _box.height << endl;
cout << "width: " << _box.width << endl;
cout << "length: " << _box.length << endl;
cout << "volume: " << _box.volume << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment