Gearing up for the stretch run CSCI 21, Spring 2013.
-
Upload
adan-beeson -
Category
Documents
-
view
212 -
download
1
Transcript of Gearing up for the stretch run CSCI 21, Spring 2013.
Gearing up for the stretch runCSCI 21, Spring 2013
Some tips
Search for answers on Google
Watch YouTube videos
Find a student or students in the class who are doing well and put together a study group
Do not leave lab hours when you finish your programming challenge – stay around and get help on your projects
Take advantage of the instructor’s office hours and email (priority email answers are given to those who attend ALL of our lecture and lab meeting hours)
Some tips (cont.)
Read the book before coming to class be prepared to ask questions in class
Attempt the programming challenge before coming to class be prepared to ask questions in class
We all know this is a very difficult class, and it requires a lot of hard work on your part – unfortunately, there is no easier way to learn this stuff minimum (‘C’ effort) time spent each week outside of
class: 6 hours
More tips
Read each project carefully as soon as it is posted – ask for clarification in lecture, lab,by email, or in office hours when needed
Start your project early (as soon as it is posted)
Try and keep your code in a compiling state constantly
Strive to do more than the bare minimum – ‘C’ students do the bare minimum
Makefile
always named Makefile not makefile, or makefile.txt, or anything else
always do the following have a target to link the executable have a target to compile each class separately have a target to compile the driver separately have a target to clean (rm/del *.o) have a target to cleanall (rm/del *.o and .exe)
Makefile (cont.)
What does a Makefile do? runs a series of compiler/linker commands for you
make allows you to specify a single target and only run
that single command make target
What is a target? one compiler or linker command
Makefile (cont.)
example: a program that only has a single source file
source file: myprogram.cpp
Makefile:
myprogram.exe: myprogram.og++ -o myprogram.exe myprogram.o
myprogram.o: myprogram.cppg++ -c myprogram.cpp
Makefile (cont.)
example: a program that only has a single source file make
executes the topmost target and all of its dependencies
typing make on the Makefile on the last slide would cause the following to happen: topmost target: myprogram.exe (executes second) dependency: myprogram.o (executes first) result: if no compiler/linker errors, will create
myprogram.o and then myprogram.exe
Makefile (cont.)
example: a program that only has a single source file make myprogram.o
only executes the command associated with the target myprogram.o
Makefile (cont.)
example: a program that has several source files
source file: myprogram.cpp, myclass.cpp, myhelper.cpp, myclass.h, myhelper.h
Makefile:
myprogram.exe: myprogram.o myclass.o myhelper.og++ -o myprogram.exe myprogram.o myclass.o myhelper.o
myprogram.o: myprogram.cppg++ -c myprogram.cpp
myclass.o: myclass.cppg++ -c myclass.cpp
myhelper.o: myhelper.cppg++ -c myhelper.cpp
Makefile (cont.)
example: a program that has several source files now you can type any of the following make
commands: make (topmost target and all of its dependencies) make myprogram.o make myclass.o make myhelper.o
Makefile (cont.)
add clean and cleanall targets to your Makefile
Windows
clean:cmd /C del *.o
cleanall: cleancmd /C del myprogram.exe
Makefile (cont.)
add clean and cleanall targets to your Makefile
Mac/Linux
clean:rm –f *.o
cleanall: cleanrm -f myprogram.exe
Makefile -- exercise
Create a Makefile to compile the following source files and build an executable that links them all together: executable: project3.exe source files:
project3.cpp DLNode.cpp, DLNode.h DLList.cpp, DLList.h
clean and cleanall targets
Project 3
Hopefully you have read the Project 3 specs, which were posted on Wednesday evening, March 27
The spec is complex, so will require your careful attention
Questions or any points of clarification?
Project 3 – getting started
How do I start Project 3 when I do not know how to code a linked list? First Iteration
stub out the classes and driver create a Makefile make
Second Iteration stub out the functions in the DLNode class make
Project 3 – getting started (cont.)
Third Iteration stub out the functions in the DLList class make
Fourth Iteration and on… implement a function in DLNode or DLList (complete
DLNode before moving on to DLList) make implement a test of the function in your driver make run the executable to view the test output
Project 3 – getting started (cont.)
Final Iterations after all of the functions have been implemented and
tested, clear out your driver and begin implementing the driver as needed for the final project
do it in steps – one small part of the driver functionality, make, run executable
When you think you have everything in place test with many, many input files – do your best to
break your program before you have to submit it
Linked lists
What is a linked list? a data structure
what is a data structure? a dynamic data structure
grows and shrinks as you add/remove data dynamic: think dynamic memory dynamic memory: think pointers
built by linking nodes
Linked lists (cont.)
What is a node? a container for a piece of data and one or more links
(pointers) to other nodes linked lists are built dynamically by creating nodes,
storing the desired data in the nodes, and then linking the nodes together
Linked lists (cont.)
Note how the nodes are linked together – this is a linked list
Conceptually, a node looks like this
Linked lists (cont.)
What does a node look like in code?class Node{
private:
// data type depends on what you //want to store in your listint data;
// link to next nodeNode* next;
};
Linked lists (cont.)
This picture looks like a bunch of nodes – where is the list?
The linked list is just the algorithms that are used to add, retrieve, update, and delete the nodes, plus some tracking sentinels that keep track of where the first node is – see Start above?