Test 1 CSCI 130 Fall 2016


  1. Algorithms
    1. [3 points] Give the definition for an algorithm.

      An algorithm is a set of instructions which solve a problem in a finite amount of time.

      I feel that you neeed these components

      • Set of instructions, or step by step procedure
      • Solve the problem.
      • Finite time.
    2. [2 points] Describe why a programmer should develop and test an algorithm before beginning to code a solution.

      Developing and testing an algorithm allows the programmer to better understand the problem and any information missing. It helps to recognise any portions of the problem which are ambiguous. It allows the programmer to test to see if their solution works. Finally it provides an outline or roadmap for constructing a program.

      Any two of tese will be sufficient.

  2. Program construction.
    1. [5 points] Give the code required for nearly all c++ programs.
      /* comment, this was optional in the answer*/
      #include <iostream>
      
      using namespace std;
      int main() {
          return 0;
      }
      
    2. [1 point each] From the above code, give an example of each of the following program elements.
      • Reserved word using, namespace, int
      • Standard identifier std, main
      • Preprocessor directive #include <iostream>
  3. Comments
    1. [2 points] Why should a programmer include comments in a program? (You said to is not an acceptable answer).

      Comments provide future readers of the code information about how or why the program was written. Comments frequently provide insight into how to code works.

    2. [2 points] What happens to comments when a program is compiled?

      Comments are discarded when the code is compiled.

    3. [2 points] Describe the behavior for comments included in /* */.

      This type of comment begins with the /* and continues until a */ is encountered all text between these symbols is part of the comment. This can include new line characters, so the comment my remove many lines of code.

    4. [2 points] Describe the behavior for comments beginning with //

      This type of comment begins with the // symbol and continues until the end of a line.

  4. Data Types
    1. [1 point each] Name four different data types.

      Any of the following: int, char, string, stream, float

    2. [2 points] What is a data type?

      A set of values along with the operations on those values.

    3. [4 points] Select one data type and explain or demonstrate why it is a data type. (This answer should contain all elements of the previous answer.)

      String is a data type. The set of values is a collection of zero or more characters. Operations on a string include input and output as well as string concatenation.

      As long as you mention a data type, the range of values and a set of operations on that data type I will be happy.

  5. [3 points] What is a syntax error?

    A syntax error occurs when a statement does not follow the syntax or grammar of the language.

  6. [6 points] We have discussed two major software tools needed to produce a working program. Name the broad class of each and describe the task each performs.

    
    A text editor allows a user to enter text into a file.  This can include a program  or data.
    
    A compiler translates a program in a high level language into machine code.
    
       
  7. Programming Conventions
    1. [2 points] Give an example of a syntax rule.

      All statements must end in a semicolon (;)

    2. [2 points] Give an example of a programming convention.

      Code inside of a code block should be indented by a uniform amount.

    3. [2 points] Explain the difference between a syntax rule and a programming convention.

      All syntax rules must be followed or the program will not compile. A programming convention on the other hand usually makes the program easier to read or helps to eliminate programming errors.

    4. [4 points] Why should a programmer follow a programming convention?

      Programming conventions help to make the program easier to read, to eliminate common programming errors, or make the program easier to modify and debug. Following the conventions will lead to less frustration when programming.