Key to CSE390C Midterm, Spring 2025 handout #5 1. Parameter Mystery. The program produces the following output. 18 j*e 3 7 biden? 13 b*den 7 7 j*e? 7 j*e 3 7 b*den 2. Pointer Mystery. The program produces the following output. 0xcc00 c-mputer 11 28 science!! 0xcc00 s-ience!! 16 36 science!!!! 0xcc00 computer 36 28 science!!!! 3. The code would be converted to prefix notation as follows: operator=(x, operator+(3, 9)) operator=(y, operator*(operator+(x, 2), 4)) operator<<(operator<<(operator<<(cout, "x = "), x), endl) operator-=(x, operator=(y, operator-(15, operator*(3, 4)))) operator<<(operator<<(y, operator<<(operator<<(cout, x), " ")), endl) 4. One possible solution appears below. double evaluate(istream & input) { double result; input >> result; string op; double num; while (input >> op >> num) { if (op == "+") { result += num; } else { // op == "-" result -= num; } } return result; } 5. One possible solution appears below. void mirror(const vector<int> & vector1, vector<int> & result) { for (int n : vector1) { result.push_back(n); } for (int i = vector1.size() - 1; i >= 0; i--) { result.push_back(vector1[i]); } } 6. One possible solution appears below. class money { public: money(int d, int c) { dollars = d; cents = c; } int get_cents() const { return 100 * dollars + cents; } string to_string() const { ostringstream out; out << "$" << dollars << "."; if (cents < 10) { out << 0; } out << cents; return out.str(); } private: int dollars, cents; }; 7. One possible solution appears below. vector<string> & operator+=(vector<string> & v, const string & value) { v.push_back(value); return v; }
Stuart Reges
Last modified: Tue May 13 18:14:51 PDT 2025