CSC234 Lecture 20 - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

CSC234 Lecture 20

Description:

Topics to be covered on the exam. Topics not on the exam. Nature of the exam. ... produces 75 cases per ton, while Pinot Noir only produces 72. The type of grape ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 36
Provided by: markhutch
Category:

less

Transcript and Presenter's Notes

Title: CSC234 Lecture 20


1
CSC-234 Lecture 20
  • Review for the Final Exam

2
Todays Topics
  • Topics to be covered on the exam.
  • Topics not on the exam.
  • Nature of the exam.
  • What to bring to the exam.
  • How to prepare for the exam.

3
Topics Prior to the Mid-Term
  • UNIX basics.
  • Editing and compiling
  • Simple data types.
  • Formatted input and output.
  • Arithmetic operators.
  • Basic functions.
  • Header files and preprocessor directives.
  • Logical operators.
  • Relational operators.
  • Simple and compound logical expressions.
  • Selective execution.
  • Repetitive execution.

4
UNIX Basics
  • You should be VERY familiar with basic UNIX
    commands (and their DOS equivalents)
  • cd and variants and pwd.
  • cp and mv
  • mkdir (and rmdir)
  • chmod
  • ls, cat, more, head, man

5
Editing and Compiling
  • Even if you have been working in Windows with
    Visual Studio, you should understand how to
    compile programs.
  • cc hwx.c
  • gcc hwx.c
  • -o filename option for both compilers
  • -lm option for math for both compilers, and where
    this option goes on the command line
  • I will not test you on an editor.

6
Simple Data Types
  • You should understand the two basic families of
    primitive data types
  • Floating point
  • float, single precision, around 7 significant
    figures, 32 bits.
  • double, double precision, around 15 significant
    figures, 64 bits.
  • Integer
  • int, 32 bits, 2,000,000,000 approximate max value
  • long, 64 bits, and short, 16 bits.
  • char, ASCII encoded, basically 8 bits.

7
Formatted Input and Output
  • You need to understand
  • printf()
  • First argument is a string literal includes
    placeholders.
  • One variable in list for each placeholder (s,
    c, d, f, lf, ).
  • You should also understand 3d, 7.3f formats.
  • Escape sequences (\n, \t, and also \\, \, \).
  • scanf()
  • First argument is string literal consisting of a
    placeholder (like printf()).
  • Second arguments is an address of a variable
  • variablename, for int and float.
  • variablename, for string or other array.

8
Arithmetic Operators
  • You need to understand the six basic operators
    , , -, , /, and .
  • You should also know the precedence of these.
  • You need to realize that only works with
    integers.
  • You should also understand the and --
    operators, but dont need to know the shortcut
    operators (, etc.).
  • You do NOT need to know the ? operator.

9
Basic Functions
  • You need to understand the three parts of a
    function
  • Prototype.
  • Invocation or call.
  • Definition.
  • You need to know that a value-returning function
    must be part of an expression.
  • You need to understand what arguments are and how
    they work.

10
Header Files Preprocessing
  • You need to know include and define, but you do
    not need to know WHICH include is needed for the
    various library functions.
  • However, you should have SOME idea of what is
    included in those libraries, especially ltstdio.hgt
  • You should know the difference between ltfile.hgt
    and file.h.

11
Logical Operators
  • You need to know, and be able to use the various
    logical operators
  • and the difference between it and .
  • !
  • lt, gt, lt, and gt.

12
Relational Operators
  • You only need to know three
  • for AND.
  • for OR.
  • ! for logical negation.

13
Logical Expressions
  • You should be able to write a simple or compound
    logical expression.
  • Simple
  • (operand logical operator operand)
  • Compound
  • ((operand logical operator operand) logical
    relation (operand logical operator operand))

14
Selective Execution if
  • You should know that you MUST have an if
    statement, and that it contains a logical
    expression.
  • You should know that you MAY have as many else if
    statements as you need, and that each must
    contain a logical expression. You should be aware
    that using these is referred to as cascading.
  • You should know that you MAY have an else clause,
    and that it does NOT have a logical expression.
  • You should understand how nested if statements
    are equivalent to a single if with a compound
    logical expression.

15
Repetitive Execution while
  • You should understand both a while and a
    do-while, and know the differences in syntax.
    (That semicolon.)
  • You should have an idea why and when you might
    use one or the other. (It has to do with when the
    test is performed.)
  • You should know that this is an EVENT controlled
    loop.

16
Repetitive Execution for
  • You should understand the purpose and type of
    each expression in the for statement
  • Initializing expression, arithmetic.
  • Test expression, logical.
  • Incrementing (or decrementing) expression,
    arithmetic.
  • You should know that these are separated by
    semicolons, not commas.
  • You should know that this is a COUNT controlled
    loop.

17
Topics Since the Mid-Term
  • More on functions.
  • Pointers and pass-by-reference.
  • Command-line parameters.
  • Switch-case branching.
  • Arrays and strings.
  • Structures.
  • Files.
  • Enumerations.
  • Compiling multiple source files.

18
More on Functions
  • Basically, you should be able to write a function
    given a set of specifications (see following
    slide).
  • You should understand the difference between
    value-returning and void functions.
  • You should understand the difference between
    functions that take arguments and those that do
    not.
  • You should understand the difference between
    pass-by-value and pass-by-reference.
  • You should understand the concept of intent.

19
Function Example, Question
  • You are writing a program that deals with wine
    production and decide to write a function to
    convert tons of grapes to cases. Chardonnay
    produces 75 cases per ton, while Pinot Noir only
    produces 72. The type of grape will be passed in
    as a character c or p, the tons will be
    passed in as a float, and the integer cases will
    be returned. Write the function.

20
Solution
  • int iTonToCase (char cGrape, float fTons)
  • int iCases 0
  • if ((cGrape c cGrape C))
  • iCases (int)(fTons 75.0f)
  • else if ((cGrape p) cGrape P))
  • iCases (int)(fTons 72.0f)
  • else
  • printf (Unknown grape type.\n)
  • / end if /
  • return (iCases)

21
Pointers, Pass by Reference
  • You should know how to declare pointers, and how
    to set them equal to an address of another
    variable.
  • You should know how to dereference pointers to
    get to the underlying value, rather than address.
  • You should know how to use pointers in functions,
    for example, Change().

22
Command-Line Parameters
  • I would not put a question on this on the final,
    however, you should understand what the two
    declarations are and represent
  • int argc is the argument count, which includes
    the command.
  • char argv is the argument vector array (array
    of strings), where argv1 is the first
    command-line argument, etc.
  • You need to understand that command-line
    arguments are strings and must be converted to
    floats or ints, if they represent numeric data.

23
Selective Execution switch-case
  • You need to understand that the expression
    associated with the switch statement is integer,
    and limited to certain types of integers at that,
    AND that it is a variable of that type.
  • A switch statement has curly braces associated
    with its block of code.
  • You can have as many case statements as you need,
    each of which has a case label that is an integer
    or character literal (constant).
  • Multiple case labels can be associated with a
    single block of code.
  • Each case block of code is terminated by a break
    statement.
  • The default label is optional.
  • The ATM simulator is a good example of all this.

24
Arrays
  • You should know how to declare an array.
  • You should know about the off-by-1 issue, and
    how to deal with it.
  • You should know how to use an initializer list.
  • You should know how to access a specific element
    of the array.
  • You should know how to pass elements of the
    array and whole arrays as function arguments.
  • You should know that arrays are passed by
    reference automatically.
  • You should be able to work with a 2-D array.

25
Strings
  • You should know that a C string is a character
    array.
  • You should know that strings are null-terminated,
    and that you need to allow for that in the array
    declaration.
  • You should know that strings are immutable, which
    means you can declare an initial value for a
    string, but to change it you need to use a
    function.
  • You should probably understand how to use
    strcpy() and strcmp() functions.
  • You need to know that you need include
    ltstring.hgt to use those functions.

26
Structures
  • You should know that a structure is a
    user-defined data type.
  • You should know how to declare, use, and access a
    simple structure that has been previously
    defined.
  • We didnt do enough in this area, so IF I put one
    on the final, I would give you the definition,
    and ask you about the second bullet points.

27
Files
  • You should know how to declare a file pointer.
  • You should know how to open a file for reading or
    writing.
  • You should know how to read simple data from a
    file (ATM simulator modification).
  • You should know how to write simple data to a
    file (same example).
  • You should know how to close a file.
  • (Text files only.)

28
Enumerations
  • You should be able to declare and use an
    enumeration.

29
Compiling Multiple Files
  • You should know how to compile multiple files,
    and WHICH files to compile.
  • You should know that .h files are not compiled or
    listed in the compiler command.

30
Nature of the Test
  • Worth 100 points total, much like the mid-term
    and the last couple of quizzes.
  • 14 simple one or two line questions worth 5
    points each
  • Declare an enumeration of compass directions.
  • Declare an array of 10 floats.
  • Declare two pointers to floats.
  • 3 more complex questions worth 10 points each
  • Write a function to validate float inputs.

31
Little Stuff That Loses Points
  • Writing in all uppercase.
  • Forgetting semicolons.
  • Forgetting curly braces.
  • Forgetting parentheses (use extras).
  • Forgetting commas in scanf() and printf().
  • Stating anywhere on the test that, you didnt
    lecture on that, so we dont have to know that,
    if it was in the reading assignments.

32
What You Should Bring
  • One 8.5 x 11-inch flat piece of paper with notes
    on both sides. No accordion attachments or Advent
    calendar flaps.
  • Test is closed notes and closed book (closed
    neighbor, closed calculator, closed palm-top
    computer, closed laptop computer, no cell phones
    or other communication devices, etc.)
  • 2 or HB Pencils (pens, if you exude confidence,
    eraser if you dont)
  • Extra paper (should not be needed, use backs of
    test sheets, which are blank)
  • You may bring food or drink to the test, but you
    may not have Back Stage deliver a pizza to you
    during the test.

33
Preparation
  • READ THE BOOK
  • Review your notes and/or the web pages (the
    CSC-234 page, not Hippy Skivvies)
  • Review your homework assignments and quizzes
  • Relax, get a good nights sleep, and eat well
    beforehand. (But dont drink too much coffee or
    youll need to be going to the bathroom during
    the test.)

34
The Questions
  • Formatted output.
  • Character array.
  • Declare constants.
  • 2-D array and nested for loop.
  • If structure.
  • For loop.
  • Switch-case (10 points).
  • Multi-part file question (10 points).
  • Function question.
  • Array question.
  • UNIX question.
  • UNIX question.
  • Declare variables and constants and write an
    equation (10 points).
  • Write a function (10 points).
  • Write another function (10 points).

35
Todays Lessons
  • You should have some idea about what will be on
    the final exam.
  • You should know what to bring to the exam, and
    when and where it will be given.
  • You should know how to best prepare for the exam.
Write a Comment
User Comments (0)
About PowerShow.com