University of Maryland Eastern Shore | The Eastern Shore's ...



CSDP222 Fall, 2011 Test 1 09-29-2011

This test is closed book.

1) Circle and correct the errors in the following program (program continues on next page):

(there are 6 errors)

#include

#include

#include

using namespace std;

const int SIZE = 20;

int my_strstr (char &str_to_check [], char &str_to_find [])

{

int i = 0;

while (str_to_check[i] != '\0')

{

int j = i;

int k = 0;

while (str_to_check[j] != '\0' &&

str_to_find[k] != '\0' &&

str_to_check[j] == str_to_find[j])

{

j++;

k++;

}

if (str_to_check[i] == '\0')

return i;

i++;

}

return -1;

}

void my_strcat (char str_to_concatenate_to [], char str_to_concatenate [])

{

int length_to_str_to_concatenate_to

= stringlen(str_to_concatenate_to);

int b = 0;

}

void main ()

{

char chr_arr [SIZE] = {'A','B','c','a','t','D'};

int index_where_found1 = my_strstr (chr_arr, "cat");

int index_where_found2 = my_strstr (chr_arr, "caz");

my_strcat(chr_arr, "cat");

system("pause");

}

2. A function __________ contains the statements that make up the function.

|a. |definition |

|b. |prototype |

|c. |call |

|d. |expression |

|e. |parameter list |

3. A function is executed when it is

|a. |defined |

|b. |prototyped |

|c. |declared |

|d. |called |

|e. |None of these |

4. The value in this type of local variable persists between function calls.

|a. |global |

|b. |internal |

|c. |static |

|d. |dynamic |

|e. |None of these |

5. Which of the following statements about global variables is true?

|a. |A global variable is accessible only to the main function. |

|b. |A global variable is declared in the highest-level block in which it is used. |

|c. |A global variable can have the same name as a variable that is declared locally within a function. |

|d. |If a function contains a local variable with the same name as a global variable, the global variable's name takes |

| |precedence within the function. |

|e. |All of these are true |

6. If a function is called more than once in a program, the values stored in the function's local variables do not _________ between function calls.

|a. |persist |

|b. |execute |

|c. |communicate |

|d. |change |

|e. |None of these |

7. What is the output of the following program?

#include

using namespace std;

void doSomething(int&);

int main()

{

int x = 2;

cout ................
................

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

Google Online Preview   Download