// demonstrates structure use with functions // Mikhail Nesterenko // 10/14/2009 #include #include using std::cout; using std::cin; using std::endl; using std::string; struct example{ int a; string b; }; void init(example &); // initializes the structure variable void output(const example&); // outputs members of the structure varabile example makeone(void); // creates a structure and returns it int main(){ example s1; init(s1); output(s1); example s2; s2 = makeone(); output(s2); } // assigns values to members of the structure passed as parameter void init(example &toinit){ cout << "Enter value for member \"a\": "; cin >> toinit.a; cout << "Enter value for member \"b\": "; cin >> toinit.b; } void output(const example &toout){ cout << "Members of structure variable are: "; cout << "a=" << toout.a << " b=" << toout.b << endl; } example makeone(void){ example toreturn; toreturn.a=1; toreturn.b="one"; return toreturn; }