Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct product {
- string name; int weight; double price;
- } ;
- void use (product*);
- int main() {
- product apple = {"McIntosh Apple", 12, 1.50};
- cout << "Name: " << apple.name << endl;
- cout << "Weight: " << apple.weight << endl;
- cout << "Price: $" <<apple.price << endl << endl;
- cout << sizeof(apple) << " >= " <<
- sizeof(apple.name) << " + " <<
- sizeof(apple.weight) << " + " <<
- sizeof(apple.price) << endl <<endl;
- product* aptr = &apple;
- cout << "Product Name: " << aptr->name << endl;
- cout << "Weight: "<< aptr->weight << endl;
- cout << "Price: $" << aptr->price << endl << endl;
- use(aptr);
- cout << "After Using Product: " << aptr->name << endl;
- cout << "Weight: "<< aptr->weight << endl;
- cout << "Price: $" << aptr->price << endl << endl;
- }
- void use (product* a) {
- a->weight = a->weight / 2;
- a->price = a->price / 4;
- }
Advertisement
Add Comment
Please, Sign In to add comment