tutorial05.pptx - CSCI1120 Introduction to Compu ting Using...

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

CSCI1120 Introduction to Compu ting Using C++ Tutorial 5 Li Le SHB 1013 lil @cse.cuhk.edu.hk 1
Image of page 1

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

Reminder of Quiz Date: Tue 18 Oct 2016 Time: 3:30pm - 4:30pm (1 hr) Venue: ERB 803 Scope: lec01 - lec06 Format: close-book, close-notes, written 2
Image of page 2
Outline Solutions to Selected Questions from Past Mid term Exam Papers 3
Image of page 3

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

Problem 1 (a) int x = 0; x = 4++; cout << x; Is this code valid? What is the output of this code? Analysis: 4 is a constant . We can only apply "+ +" and "--" operators to variables. Result: Invalid 4
Image of page 4
Problem 1 (b) int x = 10, z = 0; int y = ++x + z--; cout << "x = " << x << ", z = " << z << endl; cout << "y = " << y << endl; What is the output of this segment? Analysis: “++” “--” Prefix : returns value after increment/decrement Postfix : returns value before increment/decrement Result: 5
Image of page 5

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

Problem 1 (c) int a = 4; if (a > 0) cout << "A"; cout << "B"; else cout << "C"; cout << "D"; Result: Invalid Is this code valid? What is the output of this code? Analysis: The syntax of if-else statement only allows one single statement after the condition and before the "else" keyword . However, here we have two statements. How to make it valid? { } 6
Image of page 6
Problem 1 (d) cout << "////// \\\\\\"; Is this code valid? What is the output of this code? Analysis: String constant must be enclosed in double quotes within one line . Result: Invalid How to make it valid? String constant can extend to more than a single line of code by putting a backslash sign (\) at the end of each unfinished line .
Image of page 7

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

Image of page 8
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '15

{[ 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