For the labs of the first week:
-
Quick reminder of big-o notation
-
Intro to Linux and how to use C++ in linux
- Common used linux commands (ls, cp, mkdir, mv, rm, emacs...)
- Makefile
- argc, argv command line parameters.
- e.g. file (right-click your mouse, then choose "save link
as..."): arg.cc
- Discuss debugging: gdb (or ddd) and simple
commamds
(setting a break, tracing step by step etc)
Take a look at the programming material from:
http://www.cs.ucr.edu/~klick/tutorials.htm
Anwar Adi's Intro
to programming tools in Linux page
GNU
Emacs Reference Card (pdf, 80 KB)
-
Discuss recursive programming:
An example quickly with a simple linked list
of numbers search for a number and return the pointer of the record delete
a record that corresponds to a number.
Download Files (Right-click your mouse, then choose "save link as..."):
link.h link.cc
main.cc Makefile
(Please see comments inside the files)
-
Count time in a C++ execution:
1. Through linux "time" command
e.g. $ time YourProgramName
2. Provide with the codes in C++
Files: mytime.cc
Makefile
-
Calculate Fibonnaci number
printFib(N): Given a number N print the Nth
Fibonacci number
Do this in two ways:
1. Recursively with aux function fib: fib(n) = fib(n-1) +
fib(n-2)
2. Iteratively:
printFib()
a_k = 0
a_k+1 = 1
for i = 2 to N
a_k+2 = a_k
+ a_k+1
a_k = a_k+1
a_k+1 = a_k+2
- Implement both ways and count time difference
as a function of N. Create a table and observe the trend.
- Have a piece of paper and keep track of which people completed
their programs. (High pass, Low pass, fail)
-
Advanced stuff for keen students:
Get a simple list
and inverse it a->b->c->d turn it to d->c->b->a
a. as you want (possibly copy the list)
b. without using any additional list elements (in place)
Take Home Assignment
click here