CIS 170C Final Exam.docx

30 July, 2024 | 11 Min Read

Question 1.1. (TCO 1) Which of the following statement about IDE is true? ( Points : 4)

   IDE only allows programmers to editing their code.

   IDE provides editing, compiling, and debugging in one software package.

   Visual Studio.Net is not an IDE.

   IDE stands for integrated development engine.

Question 2.2. (TCO 2) What does the symbol << represent in C++ programming? ( Points : 4) bout bin cin cout

Question 3.3. (TCO 2) A Main Function is enclosed inside _____. ( Points : 4) box brackets curly braces parentheses quotes

Question 4.4. (TCO 2) To improve readability and maintainability, you should declare _____ instead of using literal values such as 3.14159. ( Points : 4) variables functions classes constants

Question 5.5. ( TCO 3) What is the value of x after the following statement?

float x; x = 3.0 / 4.0 + 3 + 2 / 5 ( Points : 4)

   1.75

   3.75

   5.75

   4.15

Question 6.6. (TCO 4) _____ is often used in the design of a program to describe the program processing. ( Points : 4)

   Pseudocode

   Algorithm

   Program control

   Data flow

Question 7.7. (TCO 4) What is the decision symbol in a flow chart? ( Points : 4)

   Square

   Rectangle

   Circle

   Diamond

Question 8.8. (TCO 4) Which of the following is true about if/else structure? ( Points : 4)

   If structure is a single selection structure.

   If/else structure is a dual selection structure.

   If/else structure can be nested.

   All of the above

Question 9.9. (TCO 5) Which structure causes a statement or set of statements to execute repeatedly? ( Points : 4)

   Decision

   Repetition

   Sequence

   None of the above

Question 10.10. ( TCO 5) Which repetition structure is designed to have the code execute at least one time? ( Points : 4) For loop

   Do in a while loop

   While loop

   Do while loop

Question 11.11. (TCO 5) The while loop has two important parts: an expression that is tested for a true or false value, and _____. ( Points : 4) a statement or block that is repeated as long as the expression is true a statement or block that is repeated only if the expression is false one line of code that is repeated once if the expression is true a statement or block that is repeated once if the expression is true

Question 12.12. (TCO 5) A loop that never stops is called _____. ( Points : 4) a nested loop an infinite loop a pretest loop a post-test loop

Question 13.13. (TCO 6) Debugging is like being a(n) _____. ( Points : 4)

   accountant        attorney        police officer        detective

Question 14.14. (TCO 7) Code written in a specific format to perform a single task or calculation is called a _____. ( Points : 4)

   function        loop        decision statement        task

Question 15.15. (TCO 8) Unless otherwise specified, C++ variables are automatically passed by

_____. ( Points : 4)

   parameter        argument        reference        value

Question 1.1. (TCO 7) A return statement is not needed in a _____. ( Points : 4)

   defined stack        void function        stacked function        declared stack

Question 2.2. (TCO 8) What character is used to indicate a reference parameter? ( Points : 4)

   $

   &

   @

   ^

Question 3.3. ( TCO 8) The parameter of the following function is a(n) _____. char myFunction (int &x); ( Points : 4)

   action parameter        illegal parameter        value parameter        reference parameter

Question 4.4. (TCO 9) What type of menu first displays the main menu and then, based on the user’s selection, displays a submenu?( Points : 4)

   Single-level menu

   Multiple-level menu

   Step-level menu

   Sublevel menu

Question 5.5. (TCO 9) What is the method used to make sure that valid selections are processed? ( Points : 4)

   Input validation loop

   Including the default clause in the case structure

   Use of an else clause

   All of the above

Question 6.6. (TCO 9) What software entity contains both data and procedures (actions on the

data)? ( Points : 4)

   Objects

   Instances

   Events

   All of the above

Question 7.7. (TCO 10) To halt the execution of a program at a specific spot during debugging, you must use a _____. ( Points : 4) scope resolution operator step comment break point

Question 8.8. (TCO 11) If n represents the size of an array, what would be the index of the last element in the array? ( Points : 4)

   n-2        n        n-1

   Cannot be determined

Question 9.9. (TCO 11) When working with an array, the easiest way to traverse or visit all elements of the array is to _____. ( Points : 4)

   use a loop statement        sort the array and read it        do a binary search        use sequential coding

Question 10.10. (TCO 11) Given: myArray[3][4], what is the index for the first element (located in the first row and first column)?

( Points : 4)

   \[1]\[1]        \[0]\[1]        \[1]\[0]        \[0]\[0]

Question 11.11. ( TCO 12) Given the following array : int profit [5] = {10, 20, 31, 55, 66};

The following statement would replace which value? profit [3] = profit[2 - 1]; ( Points : 4)

   55  with  10        31  with  10        31  with  20        55  with  20

Question 12.12. (TCO 12) What is the character automatically included at the end of an array of characters? ( Points : 4)

   \n

   \0

   \z

   \\\*

Question 13.13. (TCO 13) Sequential files are accessed in _____. ( Points : 4)

   random order        binary order        consecutive order

   None of the above

Question 14.14. (TCO 13) Sometimes, a project will need to save data inputted by the user so it can be used again. This data stored will later be accessed from a _____. ( Points : 4) program file project file data file user file

Question 15.15. (TCO 13) Once you finish using a file, you should _____. ( Points : 4)

     append it        exit it        	 output it

   None of the above

Question 1.1. ( TCO 13) Compare and contrast the mode operators ios::in, ios::app, and ios::out. Provide a C++ code segment that illustrates the use of these mode operators. ( Points : 20) ios::in –> Open for input operations. ios::out –>Open for output operations.

ios::app –>All output operations are performed at the end of the file, appending the content to the current content of the file. This flag can only be used in streams open for output-only operations.

Program code need to be added from any c++ reference book.

Question 2.2. (TCO 9) Explain which is more appropriate for writing a menu program: a switch case or ifelse statements. Provide a snippet of code to support your position. ( Points : 15)

For writing a menu program, a switch statement is more appropriate because a switch statement has number of advantages over if else statements.

The switch-case works as follows. A variable is entered as the test variable in place of <test_variable> in the above statements. When the program reaches the switch statement, it examines the value of test_variable, and compares it to the values given by test_value_1, etc. When it first reaches a value that matches the value of test_variable, it executes all of the code following that case label. If no value is found in any of the specified cases that matches the value of test_variable, the statements specified in the default case are executed. The default must always be the last case provided in the switch-case structure. The termination of each case with the break; statement will be discussed shortly; for now, it is sufficient to state that the break statement causes the switch-case structure to exit, so that no further cases will execute.

switch-case structures are frequently seen in the context of menus for simple console programs. The following program gives a very short example of such a usage:

#include <iostream> using namespace std;

int main() {

int input;

cout << “1. Welcome message:"<< endl; cout << “2. Print a random number:"<< endl; cout << “Enter an option: “; cin » input;

switch (input) { case 1: { cout << “Welcome to a simple switch-case demonstration”<< endl; break;

}

case 2: { cout << rand() << endl; break;

}

default: { cout << “Good-bye."<< endl; break;

}

}

return 0;

}

The same code can be written using if/else statements:

#include <iostream> using namespace std;

int main() {

int input;

cout << “1. Welcome message:"<< endl; cout << “2. Print a random number:"<< endl; cout << “Enter an option: “; cin » input; if (input==1)

{

      cout \<\< "Welcome to a simple switch-case demonstration"\<\< endl;

}   

else if (input==2)

{

     cout \<\< rand() \<\< endl;

}     else

{

    cout \<\< "Good-bye."\<\< endl;

}

return 0;

}

To have menu using if/else statements, the program will have if-else ladder or multiple if/else statements which makes the program more difficult to understand and debug. So switch statements are more appropriate for menu programs.

Question 3.3. (TCO 11) Explain how a linear search is conducted to find a particular data value in an array. Provide a C++ program segment to illustrate your answer. ( Points : 15)

Linear search or sequential search is one of the searching algorithm in which we have some data in a data structure like array data structure and we have to search a particular element in it which is known as key. By traversing the whole data structure elements from start to end one by one to find key comparing with each data structure element to the key. In case of an array we check that the given key or a number is present in array at any index or not by comparing each element of array.

There can be two possible outcomes if we are assuming that data structure like array contains unique values.

1. Linear search successful Key Found means in array at an index we found value which matches to our key

2. Linear search failed to find the Key mean our key does not exist in data

C++ Program Example Code #include <stdio.h>

int main{

int array[100] search, c; search = <value to be searched>'; < read array from its source>;

c = -1;

for(int i = 0; i < 100; i++)

{

if (search == array\[i] 

{          c=i;          break;

 } } if (c>= 0) {

cout << ā€œvalue matches with array data #: ā€œ << c << endl;

} else

{

cout << ā€œValue not found in the arrayā€ << endl;

} return 0; }

Question 4.4. (TCO 7) Explain the difference between an argument and a parameter. Use a C++ program segment to illustrate your answer.( Points : 15)

A parameter represents a value that the procedure expects you to pass when you call it. The procedure’s declaration defines its parameters.

An argument represents the value you pass to a procedure parameter when you call the procedure. The calling code supplies the arguments when it calls the procedure.

For example: int main () { int x = 5; int y = 4; return sum(x, y);

}

int sum(int one, int two) { return one + two;

}

In main() you are passing 5 and 4, those are arguments. In sum() the variables: one and two, those are the parameters

Question 5.5. (TCO 5) Using a loop, write a program that adds and displays the total of all even integers from 1 to 10. ( Points : 15) int main()

{

int sum=0;     for (int i=1; i\<=10; i++)

{         if (i%10 == 0)         sum = sum + i;

}

cout \<\< "Sum = " \<\< sum;     return 0;

}

if (i%2 == 0)

Question 6.6. (TCO 4) What is the advantage of using the conditional operator? ( Points : 15)

The advantage of using the conditional operator is the ability to place a decision and its two possible outcomes in an abbreviated format. As an example of the usefulness of the conditional operator, consider the following code:

Cout << (a > b ? a : b) << ā€œ is greaterā€ << endl;

In this statement a is compared to b, and if a is larger,, the result is a, and if a is not larger, the result is b. The comparison and the displayed result are handled in a single, concise statement.

Question 7.7. (TCO 3) Explain the naming rules for creating variables and then provide three examples using the data types int, double, and char and assign values to them. ( Points : 15)

Variable names must be in mixed case starting with lower case.

Named constants (including enumeration values) must be all uppercase using underscore to separate words.

Variables with a large scope should have long names, variables with a small scope can have short names

The names of variables, constants, and functions are to begin with a lowercase letter.

The names of abstract data types, structures, typedefs, and enumerated types are to begin with an uppercase letter

Do not use identifiers which begin with one or two underscores (`_' or `__').

Names should not include abbreviations that are not generally accepted.

Choose variable names that suggest the usage.

Variable declaration:

int varInt = 10; double varDouble = 10.25; char varChar = ā€˜a’;

Related posts