AMAT-2120 Course Material
-
General:
-
Hardware vs Software.
-
Basics of computer operation. CPU vs Memory vs Peripheral devices.
-
Operating system and Low level utilities (console shell, window manager) vs
Application programs.
-
Notions of algorithm, computer program (Sect.1.1), translation/compilation
(p.10), syntax (p.15).
-
Units of information: bit, byte (Sect.2.8) and the multiples -- KB, MB
(Asst.4 Q.2a).
-
General understanding of how computers store numbers and characters.
Binary, octal, and hexadecimal values (practical conversion to/from
base 10 and between; cf. Ex.9 on p.59).
ASCII codes (principle; - don't memorize).
-
Elements of the UNIX system:
-
Files and directories. Directory tree. Root dir. ('/'), current dir
(' . '),
parent (upper level) dir. ('. .'), subdirectories.
Absolute and relative path.
Case sensitivity of file and directory names.
-
Notions of algorithm, computer program (Sect.1.1), translation/compilation
(p.10), syntax (p.15).
-
Command-line interface of console programs. Command-line arguments of a program.
Special meaning of the '&' character at the end of command.
-
How to create a file from scratch: cat command; editors.
Automatically generated files (e.g. a.out; results_file created by your program).
-
Frequently used shell commands:
whoami, pwd, cd, ls and ls -l (full info),
mkdir, rmdir, cp, mv, rm,
chmod, script.
-
Elements of the C language:
-
Structure of main function (Fig.1.14).
Declarations (definitions) vs executable statements. Comments.
-
Data types and variables: types int,
float, double, char. Explicit casts (p.234).
Operator sizeof (p.75).
-
Preprocessor directives
- #include: Two versions of syntax:
(a) for C library files
(<stdio.h>);
(b) for programmer's files ("myfunc.c")
- #define:
Two purposes:
(a) symbolic names of constants
(e.g. #define _MAXN 100)
(b) for conditional compilation
(e.g. #define _DEBUG),
a tool to enable/disable
parts of the code instead of commenting/uncommenting them
- #ifdef / #else / #endif: for conditional compilation
-- see e.g. Lab 4 (Friday's program) and p.112-114.
- Output and Input
-
printf operator.
Format specifiers (%d, %f, %c: p.48;
%o, %x: p.54; %s (for strings): p.343). Endline character
'\n'.
Optionally:
format modifiers (p.52), other special characters (p.41).
-
scanf operator. Necessary & in the argument.
Necessary preceding prompt with printf (pp.100-104).
-
Evaluation of expressions
-
Basic arithmetic. Precedence rules. (Sect. 2.2)
Assignment operators (sect. 3.1). Shorthand forms (+= etc.)
Difference between prefix (i++) and postfix (++i) forms.
(p.88, also #3 in Midterm: lines 17,22 of code).
- Auxiliary (intermediate) variables. Example:
swap procedure (Notes).
-
Integer and floating point division. Modulus operator % (p.44).
-
C's treatment of boolean values as integers (p.125, also p.132).
Logical operators: AND (&&), OR (||), NOT (!).
(See Quiz 1/#4,
Quiz 2/#2).
Attn: (1) if x is any nonzero number, then (x&&x) is a logical
expression that evaluates to TRUE, that is to 1.
(2) Arithmetical negation (unary minus, p.44) is different from logical
negation (!, bottom of p.126, also
Quiz 2/#2h)
-
Bitwise AND (&) and OR (|) (p.459-461+,
Quiz 2/#2).
[Optional: other
bitwise operators: XOR(^), NOT (~), shifts (>>,
<<).]
-
Relational (comparison) operators (p.124,
Quiz 2/#2): >, <, etc.
Difference between the "equal to" operator == and the assignment
operator = . (Quiz 2/#1).
- Flow control
- The if-else construction (Sect.4.2, p.129).
Single and compound statements. Use of braces and semicolon.
if without else (one-way selection).
Nested if (Sect. 4.3).
-
Loops: for (p.184) and while (p.163), their functional
equivalence (see notes or pp.185,194) and flow charts.
Loop do-while (p.198).
-
Using loops in iterative mathematical procesures. Examples: summation,
recurrence relations, work with arrays, calculation of min/max.
Attn: necessary variables (accumulator,
auxiliary storage for members of recurrence sequences -- see notes).
Initialization of values, such as summation accumulator.
-
Practical issue: use debugging output to print all changing values from
inside the loop.
- Addresses and pointers.
- Variable address vs Variable value (Fig.3.3, p.90).
- Declaration of pointers. Syntax of assignments containing
addreses and pointers.
(Sect.3.2, esp. Exercise.11, p.99; Quiz 2/#3)
- Functions.
-
Passing arguments to/from functions: by value and by reference
(in the latter case: '&' symbol on caller's side vs '*' in function's
header). (Sect.6.5 p.252; Asst 5/#2)
-
- Commonly used library functions (see tables in App.D p.619
for reference; need to remember only a few functions.)
- printf, scanf -- from stdio.h
- pow, sqrt, ln, exp, sin, cos, fabs,
etc. -- from math.h
(Important:
use gcc with -lm option when math.h is
#include'd.)
-
atoi, atof, malloc -- from stdlib.h
-
strlen, strcpy -- from string.h
-
Programmer-defined functions (Sect.6.1). Prototype (declaration) vs Definition.
Header, use of semicolon. Special cases: empty parameter list;
void return "type".
- [Optional: Functions as variables. Entry point as a pointer.
Passing functions as arguments to other functions. (Notes, Suppl.Materials
on webpage).]
- Arrays
-
Static arrays (Arrays of fixed length) -- Sect.7.1, p.270.
Indexing convention: first element has index 0.
Bounds of index: [0,size-1]. Initialization in a loop (p.280).
-
Arrays as pointers (Sect.8.1). Dynamic memory allocation:
malloc function (p.402).
-
Character strings
-
Representation in memory (Fig.9.1); NULL character. Length of string is one less than Size of representing array
(cf. description of strlen function on bottom of p.356, also:
Quiz 2/#5).
-
Using NULL character as termination condition in string processing loops
(Example: string copy program -- Notes or p.344).
-
Command-line arguments
-
Arguments of main function.
Argument count. (Sect.12.4, esp. Program 12.4 on p.472).
(Note: argv[0] is always the program's own name.)
-
Parsing command line arguments: converting a string to an integer or double with
atoi, atof functions (p.623, <stdlib.h>, line 4).
-
Common programming errors. Besides recalling own experience,
review Sections 1.6, 2.6, 3.6 (items 8,9 optional),
4.5, 5.5 (ignore mention of switch; item 2 optional),
6.6 (par.1,2 on p.261 optional), 7.5, 8.4 (as much as you can handle),
9.5.
The best way to study errors is to try them on purpose and
watch the effect.
-
Elements of the C++ language: [Since neither C structures,
nor templates were not mentioned in the course,
use textbook discretely. You are only responsible for the material
covered in class.]
- C++ classes
-
A class as an (abstract) programmer-defined type. (Sect.13.4, p.520.)
Instance of a class as variable of that special type.
-
Class declaration. Data members and member functions.
Access specifiers: public vs private (p.522).
Syntax (braces, colons, semicolon).
-
Reference to a class member through a "period" syntax:
<class_instance_name> . <member_name>
- [Optional:
Reference to a member of class instance defined indirectly (through a pointer):
<class_instance_ptr> -> <member_name>
(Example, Notes)]
-
Definition (implementation) of class member functions.
Prefix <class name>::
-
Class members "know" of each other: examples of member functions
without arguments.
-
Constructors (default and with arguments) and destructors
of class. Possibility of debugging output from
constructors/destructors.
-
Tracing execution of a C++ code. (Asst.5 #4)
-
Reference parameters in C++ (p.512, 515, 518;
Asst.5 #3)
-
[Optional: C++ style comments // vs C style comments /* */ ]
-
Stream classes for input/output in C++ (see notes,
Asst.5,
Lab 10).
[won't be much emphasized on exam]
-
File stream libraries: <ifstream.h>, <ofstream.h>.
Declaring i/o files as instances of classes ifstream,
ofstream.
-
Connecting streams with filenames: function open(). Meaning
of the value of fail() when opening a file for reading.
-
Operators >> (input) and << (output). Function eof().
-
[Optional: C++ style
console i/o (#include <iostream.h>, cout<<, cin>>)
vs C style i/o (#include <stdio.h>, printf, scanf).
]
-
[Optional: Notions of encapsulation, inheritance, polymorphism
(p.592; Notes). ]
-
Elements of Programming Style.
- Clarity of code
-
Header of program. Nesessity and relevance of comments.
-
Enhance readability of code: use
line breaks, indentation (p.25), placement of braces (p.135),
brackets when non-obvious precedence,
explicit casts (p.456),
decimal dot in fl.pt.constants even such as '0.0'.
-
Avoid long expressions
-
Keep to de-facto standards (e.g. always name command line arguments
argv, argc, though it is not a syntax requirement.)
- Use meaningful names for variables, functions, and classes.
Adopt a naming convention for multi-word variables and functions
(myFunc, my_func), and for pointer variables (x_ptr, ptX).
-
Be consistent in adopted style.
- Structure of program
-
Attainable goal:
main() function in a C program should contain no more
that 10 executable lines.
main() function in a C++ program should consist of 3 lines.
-
Use modular design to keep functions short.
-
User-friendliness of program (Does it print its purpose?
Show prompt for input? Treat invalid input? Is it overall
convenient for the user?)
- Development and debugging style
-
Develop incrementally
-
Keep the code compilable at every stage of development.
Fix errors as early as they first appear, not after writing
100 lines of code.
-
Use the strictest warning option -Wall when compiling.
Pay no less attention to "warnings" than to "errors".
-
Have all variables initialized before they are referred to.
-
Print intermediate values as often as appropriate
(in debugging version). In case of incorrectly working
program, insert debugging outputs.
-
Use function stubs (p.223-224) to shape the program
as early as possible, only then implement true input or math.
-
A minimum of Maple. (Optional, but good to review if you are taking
AMAT-2130 in winter.)
-
Maple as a calculator
-
Using Maple's help system
-
Parallels and differences between Maple and C:
-
C program needs compilation, Maple works interactively
-
Assignments: C's = vs Maple's :=
-
Indexing conventions: array index starts from 0 in C, and from 1 in
Maple.
-
Maple has many math functions (such as sqrt, sin, min etc.)
that need not be included by a special action.
In addition, specialized library can be included by operator
with, analog of C's #include.
See Lab 11.