CramX Logo
COMP122: Week 2 - Variable Assignments, Conditional Logic, and Control Structures - Document preview page 1

COMP122: Week 2 - Variable Assignments, Conditional Logic, and Control Structures - Page 1

Document preview content for COMP122: Week 2 - Variable Assignments, Conditional Logic, and Control Structures

COMP122: Week 2 - Variable Assignments, Conditional Logic, and Control Structures

A homework assignment covering variable assignments, conditional logic, and control structures in C++.

Eli Simmons
Contributor
4.5
0
12 months ago
Preview (2 of 5 Pages)
100%
Log in to unlock
Page 1 of 2
COMP122: Week 2 - Variable Assignments, Conditional Logic, and Control Structures - Page 1 preview image1COMP122: Week 2-Variable Assignments, Conditional Logic, and ControlStructuresCOMP122Week 2 HomeworkCompletethe following problems.1. Suppose you are given the following variable declarations:int x, y;char ch;What values (if any) are assigned to x, y, and ch after each of these statements execute?Assume that the input to each statement isthe same:5 28 36a. cin >> x >> y >> ch;b. cin >> ch >> x >> y;c. cin >> x >> ch >> y;d. cin >> x >> y;cin.get(ch);(a)x=5,y=28,ch='3'(b)x=28,y=36,ch='5'(c)x=5,y=36,ch=28(undefined behavior)(d)x=5,y=28,ch='\n'2. Suppose you are given the following variable declarations:int x, y;char ch;What values (if any) are assigned to x, y, and ch after each of these statements execute?Assume that the input to each set of statements is as follows:13 28 D14 E 98A B 56a. cin >> x >> y;cin.ignore(50,'\n');cin >> ch;b. cin >> x;cin.ignore(50,'\n');
Page 2 of 2
COMP122: Week 2 - Variable Assignments, Conditional Logic, and Control Structures - Page 2 preview image
Preview Mode

This document has 5 pages. Sign in to access the full document!