CS141 Lab 1



Class Webpage:  http://www.cs.ucr.edu/~cs141-p/cs141_03spr/cs141_03spr.html


For the labs of the first week:

  1. Common used linux commands (ls, cp, mkdir, mv, rm, emacs...)
  2. Makefile
  3. argc, argv command line parameters.    
    • e.g. file (right-click your mouse, then choose "save link as..."):  arg.cc
  4. 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)


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)


1. Through linux "time" command
e.g.     $ time  YourProgramName
2. Provide with the codes in C++
Files:  mytime.cc  Makefile


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)

            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