cse1222_midII_sample_solutions

cse1222_midII_sample_solutions - CSE 1222 Sample Midterm II...

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
6. (a) What is the error in this program?
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern