cse1222_midII_sample_solutions

# cse1222_midII_sample_solutions - CSE 1222 Sample Midterm II...

• Test Prep
• 2
• 100% (3) 3 out of 3 people found this document helpful

This preview shows pages 1–2. Sign up to view the full content.

CSE 1222 Sample Midterm II Solutions 1. cout << fixed << setprecision(3) << y << endl; 2. #include <iostream> using namespace std; int main() { int y; cout << "Enter integer: "; cin >> y; for (int x = 5; (x*x < 200*y+5) && (x+2 < y); x = 3*x) { cout << "x*y = " << x*y << endl; } return 0; } 3. 3^2 = 9 5^2 = 25 7^2 = 49 4. #include <iostream> using namespace std; int main() { int n; double sum = 0.0; cout << "Enter n: "; cin >> n; sum = 0.0; for (int i = 5; i <= n; i++) { for (int j = 2; j <= i; j++) { sum = sum + double(i-j)/double(i+j); } } cout << "Sum = " << sum << endl; return 0; } 5. In pass by value, the value is copied from the argument to the function parameter. Any change to the value of the function parameter inside the function has no effect on the value of the argument. In pass by reference, the memory location of the argument is copied to the function parameter. The argument and the parameter reference the same memory location. Changing the value of the function parameter inside the function will change the value of the argument. 1

This preview has intentionally blurred sections. Sign up to view the full version.

6. (a) What is the error in this program?
This is the end of the preview. Sign up to access the rest of the document.
• Fall '13
• ZickiHuang
• C++ Programming, Evaluation strategy, Boolean expression

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern