Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Compare the Ada case statement with the C++ switch statement, particularly in

ID: 3561104 • Letter: 1

Question

1. Compare the Ada case statement with the C++ switch statement, particularly in terms of readability and reliability.

2. Consider the following, written in C++ form:

void alter(int a, int b) {

            a = 4;

            b = 8;

            }

            int main() {

                      int array[5] = {3,4,5,6,7};

            int index = 1;

            alter(index,array[index])

            return 0;

            }

For each of the following conditions, determine the value of index and the values in array after the code is executed.

Parameters are...

a.         passed by value

b.         passed by reference

c.         passed by name

3. Explain how a reference to a nonlocal variable is resolved when static chains are used.

4. Suppose someone designed a stack abstract data type in which the top function returned an access path (or pointer), rather than returning a copy of the top element. This is not true data abstraction. Why?

5. Explain how C#

Explanation / Answer

4)

If a pointer to the top value on the stack is returned, there is nothing to prevent the main program from then changing the top element of the stack (essentially, performing a pop followed by a push). Indeed, with a pointer, the main program can retrieve or change anything stored in the stack, bypassing the operations provided by the ADT. For example,
s: stack (int);
p: *int;
p = s.top;
*p = 257;

5)

As each selectable segment must end with an unconditional branch, goto or break, it's always sure that there will be no conflicts over different cases.