{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSE250 HW2 Solution

# CSE250 HW2 Solution - CSE 250 Spring 2011 Homework 2 Due...

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

CSE 250 Spring 2011 Homework 2 Due Date: Feb 28, Monday, by 2:05pm Total Points: 25 1. Yes, foo does swap the values of the array elements i and j when they are in bounds. If one or both of them is out of bounds, foo will still try to change those locations in memory, which may result in a segmentation fault, or just erroneous values being swapped into the valid region of memory for a[] . 2. The line x[X SIZE] = 5; is indexing out of bounds, which may result in a run-time error (Segmentation Fault), but may instead execute and overwrite some other variable leading to strange behavior or data. The line x[n] = 10/n; would throw an Arithmetic Exception run-time error if it followed the previous line ( int n = 0; ), because you’d be trying to divide by 0. 3. Computer c1; - Declares a Computer object. Computer c2(‘‘Ace’’,‘‘AMD Athlon 2000’’, 512, 60); - Declares and instantiates a Computer object, using the constructor to set the data fields to the specified parameters. Lap Top c3(‘‘Ace’’,‘‘AMD Athlon 2000’’, 512, 60); - This is an invalid statement and will not compile. The Lap Top class only has one constructor, which requires two more arguments than the Computer constructor. Lap Top c4(‘‘Ace’’,‘‘AMD Athlon 2000’’, 512, 60,15.5, 7.5); - Declares and instantiates a Lap Top object. cout << c2.manufacturer << ", " << c2.processor << endl; - Compilation Error, manufac- turer and processor are private variables.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

CSE250 HW2 Solution - CSE 250 Spring 2011 Homework 2 Due...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online