Homework 4

Instructions: Work through the following problems and record your answers. On completion of your work, THEN access the Blackboard system. Once you access the BlackBoard system you will NOT be able to back out to rework your answers.


1.   Write a program that adds numbers from 1 to 10 inclusive and puts the result within the object identified by the name "value".

2.      What will be the output after the following main function is executed?

void main( )
{
    
int low, high;
    
low = 1;
    
high = 5;
    
while ( low < high)
    
{
           
cout<<low<<","<<high<<endl;
           
low = low + 1;
           
high = high - 1;
     
}// End while
}// End main

 

3.      Name four different programming paradigms.

4.      Suppose "f" is a function that returns the result of reversing the string of symbols given as its input, and "g" is a function that returns the concatenation of the two strings given as its input. If "x" identifies the string abcd, what is returned by g(f(x),x)?

5.      Suppose the function "m" expects two numeric values as its parameters and returns the smaller of the two values as its output value. If "w", "x", "y" and "z" represent numeric values, what is the result returned by m(m(w,x),m(y,z))?

6.      What is the difference between the meaning of the "double bar" (=) symbol in the statement

If ( x == 5 ) then {...}
      as opposed to the assignment statement
      x = 2 + y?

7.      Rewrite the following program segment using a single if statement instead of nested if-then-else statements.

If (W=5) then
{
    assign Z the value 7
}// End of Then
else
{
    if (W=6) then
  
{
        assign Y the value 7
   }// End of Then
   e
lse
   {
        if (W=7) then assign X the value 7
  
}// End of Else
}// End of Else

8. Rewrite the following program segment using a single switch statement instead of nested if-then-else statements.

If (W=5) then
{
    assign Z the value 7
}// End of Then
else
{
    if (W=6) then
  
{
        assign Y the value 7
   }// End of Then
   e
lse
   {
        if (W=7) then assign X the value 7
  
}// End of Else
}// End of Else

9.      Summarize the following rat's nest routine with a single if-then-else statement

	if X>5 then goto #80
	X = X + 1;
	goto 90
80	X=X+2
90 	stop

10.      John Programmer argues that the ability to declare constants within a program is not necessary because variables can be used instead. For example, the below example  can be handled by declaring AirportAlt to be a variable and then assigning it the required value at the beginning of the program. Why is this not as good as using a constant value?

Void main( )
{
           
const AirportAlt = 2135;
           
:::
           
if (densityAlt>AirportAlt)
           
{
                       :::
                       //
Abort take-off
           
} //End of if
} // End of main

11. Functions are to program abstraction as arrays are to _________ abstraction.

12. The ___________ programming paradigm most closely matches the von Neumann hardware architecture.

13. The longest phase of the software engineering life cycle for most applications is _______.

14.How does a do-while statement in C++ differs from the classic repeat-until?

15. Three key ideas of high level language programming are ___, ___ and ___.