#include struct wealth { double gAu; /* grams of gold */ double ozAg; /* ounces of silver */ double kC; /* carats of diamonds */ int pearls /* number of pearls */ }; // remember the compulsory ; at the end. void print(wealth w) { cout << w.gAu << " g gold + " << w.ozAg << " oz silver + " << w.kC << " kt diamond + " << w.pearls << " pearls\n"; } void main() { wealth mine; mine.gAu = 123; mine.ozAg = 11; mine.kC = 0.01; mine.pearls = 0; cout << "I've got "; print(mine); ... } // for convenience: void set(wealth & w, double a, double b, double c, int d) { w.gAu = a; w.ozAg = b; w.kC = c; w.pearls = d; } void main() { wealth jills; set(jills, 17, 8, 3.5, 9); cout << "jill's got "; print(jills); ... } // also for convenience wealth makewealth(double a, double b, double c, int d) { wealth w; set(w, a, b, c, d); return n; } void main() { wealth joes; ... joes = makewealth(0, 0.5, 0, 0); cout << "joe's got "; print(joes); ... } // arithmetic operations can be made too, for example wealth add(wealth x, wealth y) { return makewealth(x.gAu + y.gAu, x.ozAg + y.ozAg, x.kC + y.kC, x.pearls + y.pearls); } // or void addto(wealth & x, wealth y) { x.gAu = x.gAu + y.gAu; x.ozAg = x.ozAg + y.ozAg; x.kC = x.kC + y.kC; x.pearls = x.pearls + y.pearls; } // how to make a robber void rob(wealth & robber, wealth & victim) { addto(robber, victim); set(victim, 0, 0, 0, 0); }