Montana State University



Assignment #3The first set of questions are from the book. There are questions, problems and programming exercises at the end of each chapter. Make sure you do the right one. If you don’t understand any of the questions – ask! Don’t guess and lose credit.Chapter 7 - Question #9. Chapter 7 - Question #12. Chapter 7 - Question #13 (This question applies to most scripting languages, not just JavaScript)Chapter 8 – Programming Exercise #1 – part c only. Chapter 8 – Programming Exercise #4. Note: Consider a continue a form of goto, so do not use continue in addition to goto or break.Chapter 8 – Programming Exercise #6.Chapter 9 – Problem #5 Consider the following pseudo code that has a procedure that swaps two integers. swap (a, b){tmp = a;a = b;b = tmp;}main{int val1 = 2, val2 = 4;printline “Before: val1 = “ + val1 + “, val2 = “ + val2;swap (val1, val2);printline “After: val1 = “ + val1 + “, val2 = “ + val2;}Write a real version of the program in each of the following languages. If C++ is used for the 3rd language, do not use C style syntax/pointers.CJavaC# or C++ Consider the following pseudo code that has a procedure manipulating an array.ArrayWork(int[] array){for (i = 0; i < array.length; i++)array[i] *= 2;for (i = 0; i < array.length; i++)print values[i] + “ “;array = new { 1, 1, 1, 1, 1 };for (i = 0; i < array.length; i++)print values[i] + “ “;}Main{Int[] values = { 1, 2, 3, 4, 5 };for (i = 0; i < array.length; i++)print values[i] + “ “;ArrayWork (values);for (i = 0; i < array.length; i++)print values[i] + “ “;}Write a real version of the program in each of the following languages. (If C++ is used for the 3rd language, do not use C style syntax/pointers.) Also, in each language, write 3 versions of the procedure. The difference in version will be how the parameter array is passed to the function.C By ValueBy ReferenceBy Reference to the array ReferenceJavaBy ValueBy ReferenceBy Reference to the array ReferenceC# or C++ By ValueBy ReferenceBy Reference to the array ReferenceYour output for each set will match and will be as follows:By Value1, 2, 3, 4, 52, 4, 6, 8, 101, 1, 1, 1, 11, 2, 3, 4, 5By Reference1, 2, 3, 4, 52, 4, 6, 8, 101, 1, 1, 1, 12, 4, 6, 8, 10By Reference to the array Reference1, 2, 3, 4, 52, 4, 6, 8, 101, 1, 1, 1, 11, 1, 1, 1, 1In the C version of code, you may hard code the array length as 5 in the loops.Do not remove logic from the ArrayWork procedure in any of the versions. That avoids the point of the project.Hint: It may not be possible to do each version for each of the languages listed. If it is not possible, describe (not code) how the same solution would be achieved.Explain why the final line of output is what it is for each of the 3 parameter passing variations. ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download