Assessment Test

Sample Questions
Fundamentals of Programming

Objectives being tested

  1. Know and use techniques of problem solving and algorithm development:
    1. Be able to describe and apply top-down programming methods.
    2. Be able to define and use algorithms.
    3. Be able to write pseudo-code.
    4. Be able to describe the steps in program development:
      1. Analysis
      2. Design
      3. Implementation (and testing)
      4. Documentation
  2. Know the basic concepts of computer systems:
    1. Understand the hardware/software programming environment:
      1. Be able to describe the basic hardware components of a PC and their function.
      2. Be able to describe the levels of programming languages from machine-language to higher-level languages and their characteristics.
    2. Understand the purpose and use of compilers, interpreters, and assemblers.
    3. Understand the various hardware components: the CPU, ALU, memory, disk, input/output devices, etc.
    4. Know how data is represented.
    5. Know the steps in compiling and executing a program.
  3. Know and be able to use the basic program control structures and how they are coded in a programming language:
    1. Be able to describe and code the different types of sequence structures: assignment, I/O, etc.
    2. Be able to describe and code the different types of selection structures: If/Then/Else, Case, or Switch.
    3. Be able to describe the different types of iteration structures: While, Repeat (or Do/While), For:
      1. Know which is a pretest and posttest.
      2. Know the difference between counter loops and sentinel loops.
  4. Be able to construct a program from modules: procedures and functions:
    1. Know what parameters and how to use them.
    2. Know the difference between pass by value and pass by reference.
    3. Know how formal and actual parameters are related to each other.
    4. Be able to evaluate procedures and functions for correctness.
    5. Know the difference between void functions and value returning functions and how to use them.
  5. Design, code, test, and debug programs using the basic program control structures:
    1. Know the various design methods:
      1. Top-down modular method.
      2. Object oriented method.
    2. Understand 2-valued logic and its use in programming:
      1. Be able to evaluate: Not, And, and Or logic
      2. Be able to use If/Then/Else logic. (sp)
      3. Be able to construct truth tables.
    3. Build programs using statements that are sequence, selection, or iteration constructs.
    4. Build programs by using program modules.
    5. Know how to use stubs and drivers.
    6. Know how to formulate and use test data.
    7. Know how to use debugging techniques.
  1. Page 510. Functions can be used to improve programming productivity and implement __________________ of larger problems into a series of smaller problems.
    linkage
    execution
    compilation
    modularization.

  2. Page 42. _______________ is a tool programmers use to help them plan an algorithm.
    C++
    Modularization
    Pseudocode
    Standardization

  3. Page 6. _____________________ is a set of step by step instructions that accomplish a task.
    An algorithm
    A function
    Top down design
    Coding

  4. Page 89. The ________________ of a language, whether it is C++ or English, is the set of rules that you must follow to use the language.
    syntax
    semantics
    instructions
    flow

  5. Page 495. A function ________________ alerts the compiler that the function will be defined later in the program.
    definition
    prototype
    header
    body

  6. Page 365. Given
    InputProcessingOutputC++
    Integer item
    Integer total
    Algorithm:
    Processing Items: None
    1. Initialize the total to 0
    2. Prompt user for the cost of an item
    3. User enters the cost of the item
    4. Repeat while (the item is greater than 0)
      Add the item to the total.
      Prompt user for the cost of an item
      User enters the cost of the item
      End repeat while
    5. Display the total
    Display the total
    int item;
    int total = 0;
    
    cout << "Enter the cost of the item: ";
    cin >> item;
    while ( item > 0 )
    {
        total += item;
        cout << "Enter the cost of the item: ";
        cin >> item;   
    }
    cout << "Your total is " << total << endl;
    
    If the values 14, 26, 10, -1 are entered, the total is:
    49
    50
    10
    -1

  7. Pages 177-181. Evaluate:  10 % 5 + 2 / 4
    1
    .5
    0
    Cannot be evaluated.

  8. Page 2. There are two types of programs, ____________ and ________________ programs.
    utilities and server
    utilities and client
    user and web
    application and system

  9. Lecture. In computing, an arithmetic logic unit (ALU) is a digital circuit that performs arithmetic and logical operations. This operation is a function of the ALU.
    booting
    copying
    &&
    surfing

  10. Page 158. Use the ____________ class (data type) to store 0 or more characters.
    int
    char
    bool
    string

  11. Page 88. ____________________ locations are used to store variables while the program is running.
    Flash drives
    Memory (also called RAM)
    Arithmetic Logic Unit (ALU)
    Server

  12. Pages 3 and 160. Computer instructions and data are converted to _______________ code on a computer.
    Decimal (0 through 9)
    Unicode
    Binary (1's and 0's)
    ASCII

  13. Page 4. Software that converts computer instructions into machine instructions is called _________________ .
    translator
    word processor
    system
    compiler

  14. Page 97. You use the editor to enter the C++ instructions, called ________________, into the computer.
    source code
    a translator
    compiler
    assembler

  15. Page 364. Programmers use the _____________ structure, referred to more simply as a loop, to repeatedly process one or more program instructions until some condition is met, at which time the _______________ structure ends.
    selection
    sequence
    function
    repetition

  16. Page 513. ________________ refers to the process of passing a variable's address to a function.
    Passing by value
    Calling a function
    Passing by reference
    Parameters

  17. Pages 177-180, 381-384. Given
    InputProcessingOutputC++
    Integer sum
    Integer score
    Algorithm:
    Processing Items: None
    1. Initialize sum to 0
    2. Assign to score the value returned from getScore()
    3. Repeat while (score is not equal to -1)
      • Add score to sum.
      • Assign to score the value returned from getScore()
      • End repeat while
    Not part of code snippet
    sum=0;
    score = getScore();
    while (score != -1)
    {
    sum = sum + score;
    score = getScore();
    }
    What is the value of sum after the above code is executed? Use the values entered as 5, 3, 2, -1
    10
    -1
    2
    9

  18. Pages 378-381. Given:
    InputProcessingOutputC++
    Initialize Integer number1 to 3
    Initialize Integer number2 to 5
    Initialize Integer number3 to 7
    Algorithm:
    Processing Items: None
    1. Repeat while (number1 is less than 20)
         Calculate number1 as number1 + number2 * number3.
         Calculate number2 as number1 - number2
         Calculate number3 is number1 / 2
      End repeat while
    2. Display the total
    Display the value of number1
    int number1 = 3;
    int number2 = 5;
    int number3 = 7;
    while (number1 < 20)
    {
      number1 = number1 + number2 * number3;
      number2 = number1 - number2;
      number3 = number1 / 2;
    }
    cout << number1 << endl;
    
    What is displayed?
    3
    38
    19
    9

  19. Pages 298-304. Given:
    InputProcessingOutputC++
    Initialize Integer age to 0
    Initialize Character registered to ' '
    Algorithm:
    Processing Items: None
    1. Prompt user to enter age
    2. Read in age
    3. If (age greater than or equal to 18)
      1. Prompt user to enter if registered to vote
      2. Read in registered
        1. If (uppercase registered is equal to 'Y')
          1. Display "You can vote."
        2. Else
          1. Display "You must register to vote."
        3. End If
        4. Else
      3. Display "You are too young to vote."
    4. End If
    Display "You can vote."
    Display "You must register to vote."
    Display "You are too young to vote."
    int age =0;
    char registered = ' ';
    cout << "Enter your age: "; 
    cin >> age;
    if (age >= 18)
    {
      cout << "Are you registered to vote?(Y/N): ";
      cin >> registered;
      if (toupper(registered) == 'Y')
        cout << "You can vote." << endl;
      else
        cout << "You must register to vote." 
             << endl;
    }
    else
      cout « "You are too young to vote." « endl;
    
    What is displayed when 18 and n are entered?
    You can vote.
    You must register to vote
    You are too young to vote
    Cannot calculate

  20. Pages 239 - 240. Given:
    InputProcessingOutputC++
    Integer first number
    Integer second number
    Processing items: Integer swap
    Algorithm:
    1. Prompt user for the first number
    2. User enters the first number
    3. Prompt user for the second number
    4. User enters the second number
    5. if (the first number is greater than the second number)
      assign to temp the first number
      assign to the first number the second number
      assign to the second number the temp value
      End if
    Display the first number as the lowest
    and the second number as the highest.
    int first;
    int second;
    int temp;
    cout << "Enter your first number";
    cin >> first;
    cout << "Enter your second number";  
    cin >> second;
    if (first > second)
      {
        temp = first;
        first = second;
        second = temp;
      }
      cout << "Your lowest number is " 
           << first 
           << ".\n Your highest number is " 
           << second 
           <<endl;
      
    Which statement is true?

    if the first number is greater than the second number, swap the numbers
    if the first number is greater than or equal to the second number, swap the numbers
    swap the numbers
    none of the above

  21. Page 365. Given
    InputProcessingOutputC++
    Double bonus
    Double rate initialized to 10%
    Double sales
    Processing items: none
    Algorithm:
    1. Prompt user for the sales
    2. User enters the sales
    3. Repeat while (the sales are greater than or equal to 0)
      Assign to bonus the amount of sales times the rate.
      Display the bonus.
      Prompt user for the sales
      User enters the sales
    4. End repeat while
    Display the bonus.
    double bonus = 0.0;
    double rate = 0.1;
    double sales = 0.0;
    
    cout << "Enter the sales: ";
    cin >> sales;
    while ( sales >= 0 )
    {
        bonus = sales * rate;
        cout  << "The bonus is "  
              << bonus 
              << endl;
        cout << "Enter the sales: ";
        cin >> sales;   
    }
    
    What is the range of values that will allow the loop to continue looping?

    sales is any negative number
    sales is equal to -1
    sales is zero or a positive number.
    rate is 10%

  22. Page 608. To refer to the third variable in an array named salaries, use _____________
    salaries(3)
    salaries(2)
    salaries[3]
    salaries[2]

  23. Page 379. Given
    InputProcessingOutputC++
    Integer region's quarterly sales
    Integer region initialized to 1
    Integer total sales initialized to 0
    Processing items: counter (1 through 3)
    Algorithm:
    1. Repeat while (the region is less than or equal to 3)
         Prompt the user to enter the region's quarterly sales
         Enter the region's quarterly sales
         Add the region's quarterly sales to the total quarterly sales
         Add 1 to the region
      End repeat while
    2. Display the total quarterly sales
    Display the total quarterly sales.
    int regionSales = 0;
    int region = 1;
    int totalSales = 0;
    
    while ( region <= 3 )
    {
        cout  << "Enter region "  << region 
              << "'s quarterly sales: ";
        cin >> regionSales;   
        totalSales = totalSales + regionSales;
        region = region + 1;
    } //end while
    cout << "total: " << totalSales << endl;
    
    What statement below describes what will happen when this code completes execution?

    totalSales will contain the total of all of the values of regionSales that are entered.
    regionSales will contain the total of all of the values of regionSales that are entered
    totalSales will always be 0
    cannot project what totalSales will be

  24. Page 385. Given
    InputProcessingOutputC++
    Integer gross pay amount for a store
    Integer total gross pay amount initialized to 0
    Processing items: Integer store number (1 through 3)
    Algorithm:
    1. Initialize the store number to 1
    2. Repeat while (the store number is less than or equal to 3)
      Prompt the user to enter the store's gross pay
      Enter the store's gross pay
      Add the store's gross pay to the total gross pay
      Add 1 to the counter
    3. End repeat while
    Display the total gross pay.
    int storeGross = 0;
    int totalGross = 0;
    
    for (int store = 1; store <=3; store++)
    {
        cout  << "Store "  << store 
              << "gross: ";
        cin >> storeGross;   
        totalGross = totalGross + storeGross;
    } //end for
    cout << "Total: " 
         << totalGross 
         << endl;
    
    What type of loop is used:

    Sentinel
    Counter controlled
    post test loop
    accumulator

  25. Page 447. Given
    InputProcessingOutputC++
    Integer sales
    Integer total region sales
    Processing items: Integer region number (1 through 3)
    Algorithm:
    1. Repeat for each region (while the region is less than 3 incrementing the region by 1 for each iteration)
      Prompt the user to enter the sales amount for the region showing the region number
      Enter the sales
      1. Repeat
        Add sales to the total region sales
        Prompt the use to enter the next sales amount for the current region
        Enter the sales
      2. End repeat while the sales are greater than 0
      Display the region sales and the total region sales
      Assign 0 to the total region sales
    2. End for
    Display the total gross pay.
    int sales = 0;
    int  totRegSales = 0;
    for (int region = 1; region < 3; region += 1)
    {
      cout << "First sales amount for Region "
           << region << ": ";
      cin >> sales;
      do 
      {
        totRegSales = totRegSales + sales; 
        cout << "Next sales amount for Region "
             << region << ": ";
        cin >> sales;
      } while (sales > 0);
    
      cout << endl << "Region " << region
         << " sales: $" << totRegSales
         << endl << endl;
         totRegSales = 0;
    }
         
    
    How many times is the outer loop executed?

    cannot calculate unless you know the number of sales entered
    the number of times sales is entered
    2
    2 times the number of sales entered

  26. Page 394. _________________ values are easily distinguishable values that cannot be valid data that are used to end a loop.
    Character
    Bool
    Counter controlled
    Sentinel

  27. Page 767. Given:
    PseudocodeC++
    if file object.is_open() equals true
    if file object.is_open()
    if file object.is_open() equals false
    if Not file object.is_open()
    if (fileobject.is_open() == true)
    if (outFile.is_open())
    if (outFile.is_open() == false)
    if (!outFile.is_open())
    All 4 statements test a different condition
    The second and third statements are not valid statements
    Statements 1 and 2 are equivalent statements and statements 3 and 4 are equivalent statements
    The first 3 statements are valid and the 4th statement is invalid.

  28. Page 497. Given:
    PseudocodeC++
    Integer area
    Integer width initialized to some value
    Integer length initialized to some value

    assign to the variable area the value returned from a function that
    calculates the area of a rectangle given the length and the width of the rectangle.
    int area;
    int width; // for this problem assume a value is assigned to width
    int length; // for this problem assume a value is assigned to length

    area = calcRectangleArea(length, width);
    Which prototype is used with the call stated in the problem

    calcRectangleArea();
    int calcRectangleArea (int, int);
    void calcRectangleArea(int, int);
    void calcRecTectangleArea();

  29. Page 608. Each array element
    has a unique number called a subscript which identifies each element.
    can be of a different data type.
    is initialized automatically at declaration.
    defaults to pass by reference to a function.

  30. Page 651. You can visualize a one-dimensional array as a _____________ of variables.
    list
    string
    file
    group

  31. Page 689. Given
    InputProcessingOutputC++
    String object zipCode initialized to the null string Processing items: none
    Algorithm:
    1. Prompt user for a 5-digit ZIP code.
    2. Enter the zip code.
    3. If the zip code is of length 5
         display a message that the zip code is a valid length
      else
         display a message that the zip code is not a valid length
    Output whether the zip code is a valid length
    string zipCode = "";
    cout << "Enter a 5-digit ZIP code: ";
    cin >> zipCode;
    if (zipCode.length() == 5)
      cout << "Valid length" 
           << endl;
    else
      cout << "Incorrect length" 
           << endl;
    
    What is displayed when the user enters 01234?
    01234
    Valid length
    Incorrect length
    1234

  32. Page 608. The variable's position in an array is identified by the ______________.
    value
    field name
    subscript
    data type

  33. Page 610. Given:
    int list1[5] = {14, 22, 9, 12, 5};
    int list2[5];
    list2 = list1;
    assigns the values of list1 to list2.

    true
    false

  34. Page 552. Given the prototype:
    int getData(string);
    Which call to getData is a correct call that returns an integer to a variable int age?
    getData();
    age = getData(4);
    getData(message);
    age = getData("first");

  35. Pages 552 and 553. Given:
    InputProcessingOutputC++
    main() function 
    Double sale 1
    Double sale 2
    Double bonus rate
    Processing Items: none
    Algorithm:
    1. enter sale 1, sale 2, and bonus rate
    2. call the calcAndDisplay() function to calculate and display the total sales and bonus;
      pass the function the sale1, sale2, and bonus rate
    none
    double sale1 = 0.0;
    double sale2 = 0.0;
    double bonusRate = 0.0;
    cout << "Enter first sale: ";
    cin >> sale1;
    cout << "Enter second sale: ";
    cin >> sale2;
    cout << "Enter bonus rate: ";
    cin >> bonusRate;
    calcAndDisplay(sale1, sale2, bonusRate);
    
    Input (formal parameters)ProcessingOutputC++
    calcAndDisplay() function 
    (as formal parameters) Double sale 1
    Double sale 2
    Double bonus rate
    Double total sales
    Double bonus
    Processing Items: none
    Algorithm:
    1. total sales = sale 1 + sale 2
    2. bonus = total sales * bonus rate
    3. display total sales and bonus
    total sales
    bonus
    double num1;
    double num2;
    double rate ;
    double total = 0.0;
    double bonus = 0.0;
    total = num1 + num2;
    bonus = total * rate;
    cout << "Total: $"
         << total << endl;
    cout << "Bonus: $"
         << bonus << endl;
    
    Assume the user enters 10.0 for the first sale, 5.0 as the second sale and 0.1 as the bonus. What are the contents of total and bonus when they are displayed in the function calcAndDisplay?
    total is 0.0 and bonus is 0.0
    total is 15.0 and bonus is 16.5
    total is 15.0 and bonus is 1.5
    total is unknown and bonus is unknown

  36. Page 636
    Arrays, like simple data types, are passed by value unless the "&" (address of) operator is used.
    true
    false

  37. Page 609. Given:
    InputProcessingOutputC++
    Double array with 4 elements initialized to salary amounts. Processing items: x for values 0 through 3
    Algorithm:
    1. repeat for (each of the 4 array elements)
      add the salary amount stored in the current array element to the total
      end repeat for
    2. Display the total
    Total salaries
    double salaries[4] = {25.25, 50.00, 10.50, 14.25};
    double total = 0.0;
    for (int x = 0; x < 4; x +=1)
      total = total + salaries[x];
    cout << "Total: $" 
         << total 
         << endl;
    
    After execution of the code segment, what does the cout statement show as the value of total?
    100
    85.75
    14.25
    0

  38. Page 688. Given: string states = "";
    What is the value of states[0];
    garbage
    segment will not compile
    the Unicode value of " (a double quote)
    0 or null value

Valid XHTML 1.0 Strict