programming exam prep

Card Set Information

programming exam prep
2013-12-10 08:48:22
programming exam

Show Answers:

  1. what is a program
    set of instructions for accomplishing a task
  2. what are the two key considerations when writing instructions
    • 1. write clear unambiguous instructions
    • 2. write in a language that is understood
  3. what does 1 represent
    true or the power being on
  4. what does 0 represent?
    false or the power being off
  5. why dont programmers program with 1 and 0
    time consuming and prone to cause errors
    • - not required by the compiler 
    • -essential for readers to understand program 
    • - cant have a comment within a comment
    • - /*comment*/
    • -minimum code should have one comment telling the reader what the program is intended to do the date and the author
  7. include statements
    - tell the compiler witch sets of eextra commands (functions to permit the user to use ) example standard IO
  8. semicolons
    each statement must end in a semicolon
  9. pseudocode
    • is a description of a computer program or algorithm 
    • -uses conventions of computer programming 
    • -written for humans to read rather than machines
  10. compiler directives
    • commands given to the compiler
    • always stars with #sign 
    • example #include <stdio.h>
    • tells the program to include the contents the program its making -- user telling the compiler to use it
  11. the main function
    • a function is just a program that returns a value 
    • every c program must contain one function 
    • that is the function that is executed when the program is run
  12. variables
    • -used to store values
    • -must be a type and must be written (it float double char)
    • -example:
    • Int number;

    To assign a value to the variable

    number = 4;
  13. variable declaration
    int area; variable declaration
  14. storing an initial value
    • int area= 1; 
    • called initializing a variable

    type shows how much memory to store for the variable

    ultimately all data is stored as numbers
  15. identifiers
    • the name of the variable 
    • rules: 
    • not to short or too long

    readers should be able to know what its used for

    use camel case



    don’t start with capital or number

    no blanks commas or special characters

    may contain letters underscores or digits

    must start with a letter not a number or underscore

    case sensitive

    don’t choose similar identifiers that differ by case
  16. expressions
    • -combinations of constants and variables and function calls
    • -have both value and type
    • -can have logical conditions that are true or false 
    • - has some operator (=<>)
  17. operators
  18. unary operators
    only has one argument
  19. binary operators
    two operands one on each side of the operator 

    %remainder “modulo”

    && and

    || or

    <= less than or equal to

    >= greater than or equal to

    ? conditional operator
  20. assignment operator
    used to change the value of a variable
  21. assignment statements
    value of a variable is replaced with the value of an expression
  22. algorithms
    computable set of steps to achieve a desired result
  23. algorithm process
    • 1.     
    • Identify the program requirements

    • 2.     
    • Investigate the problem

    • 3.     
    • Problem analysis

    • 4.     
    • Designm the algorithm

    • 5.     
    • Implement the algorithm
  24. boolean logic
    • Some operator create expressions that return
    • only  a true or false value 
    • n  Needed when
    • computer needs to know whats next

    n  True (1)

    n  False (0)

    n  && and

    n  || or

    • n  ! not causes expression
    • that is true to be false and vice versa
  25. if statements
    if (expression) statement;
  26. what is a block of statements
    statements surrounded by braces
  27. switch statement
    • a multiway conditional
    • statement that generalizes the if-else statement
    • - use it when there are multiple if statements
    • -   1 switch (expression)
    •    2 {
    •    3     case label1: statement1;
    •    4     case label2: statement2;
    •    5     ...
    •    6     case labeln: statement;
    •    7     default: defaultStatement;
    •    8 }

    cases are based on the value of the expression
  28. pointer
    • a variable whose value just happens to be a memory address
    • -position in memory called address
    • -manipulate the values stored at specific memory addresses
    • -strings are pointers 
    • int *x, y=24;
    • x=&y
    • x is assigned the location of the variable y in memory 
    • *-- extracts the address of y NOT THE VALUE

    • *x=&y DOES NOT WORK
    • use scanf ("%d", &*X);
    • or scanf("%d",x);
  29. pointers and strings
    • when using scanf dont use & to read the string
    • char word[20];
    • scanf("%s", word);

    char *jedi = "Mara Jade";

    cant alter the string -- segmentation fault
  30. syntax errors
    • prevent the program from compiling
    • violates grammar rules for the C language
  31. logic errors or semantic errors
    • prevent the program from running correctly in all situations
    • doesnt do what you want it to 
    • examples
    • infinite loop
    • misunderstanding operator precedence
  32. divide and conquer
    • use temporary printf statements to check the output 
    • helps you tell which part is working and which needs debugging
  33. run time errors
    • errors occur when you run a program 
    • two types:
    • logic errors 
    • fatal errors
  34. fatal error
    • when the executable crashes 
    • stack overflow
    • divide by zero etc
  35. counting loops
    for loop
  36. conditional loops
    • while 
    • do while
  37. for loops
    • number of passes through the loop is known in advance 
    • 1 for (expr1; expr2; expr3) 
    • 2  statement;

    expr1 initialize some parameter (control variable loop variable or index)

    expr2 is the condition that must be true for the loop to continue 

    expr3 is used to modify the value of the control variable initially assigned by expr1
  38. nesting loops
    • loop within a loop 
    • executed form the inside out 
    • 1 for (i = 1; i <= 4; i++)  
    • 2 {  
    • 3    for (j = 1; j <= 5; j+=2)   
    • 4    {   
    • 5       k = i + j;   
    • 6       printf("i=%d, j=%d, k=%d", i, j, k);   7    }   
    • 8 } 
    • In the example above, i is the outer loop counter and j is the inner loop counter. The outer loop is executed 4 times, when i =1,2,3, and 4. For each i value the inner loop is executed 3 times. Since j=1,3, and 5 the inner loop is executed 4*3 or 12 times.
  39. while loop
    • situations in which the number of passes is not known in advanced 
    • while (expression)   
    • 2  statement;

    • expression represents a condition that must be met
    • repeats until expression is not true

    • statement must include something that alters the expression to avoid infinite loop
    • can have nested loops
    • loop control variables should be integers
  40. break
    can be used to provide an early exit from for while a and do loops
  41. continue
    the continue statement causes the current iteration of a loop to stop and the next iteration to begin immediately
  42. do while
    will execute at least once
  43. usability looks at six components which are:
    • 1. learnability -- user can learn how to accomplish the basic task the first time that the software is used
    • 2. efficiency -- quick and minimum effort from the user
    • 3. memorability -- user can remember how to use it 
    • 4. errors - software is usable if user makes errors 
    • 5. satisfaction -- pleasant and enjoyable to use
    • 6. utility -- high utility when it provides the features needed to do the tasks
  44. float point arithmetic
    is not exact
  45. cancellation error
    when large number may cancel out the smaller number
  46. underflow
    very small computational result is represented by a zero
  47. overflow
    a error which results from an attempt to represent a computional relut that is too large to fit into the storage type
  48. automatic conversion
    • expression is being evaluated 
    • ex int converted to double 
    • going from d to i is okay
    • going from i to d loses info
  49. cast
    explicit conversion
  50. function
    self contained program segment that carries out some specific tast
  51. function definition has two components
    • header (including parameter declarations
    • body of the function )

    • general form 
    • 1 function_header  
    • 2 {   
    • 3     functionBody   
    • 4 }
  52. array
    data type that can hold multiple vaues