CSC 237 - Data Structures, Fall, 2008 Welcome to Data Structures! Tuesday, September 2 uses Monday’s schedule!

Slides:



Advertisements
Similar presentations
Lecture 3 Some commonly used C programming tricks. The system command Project No. 1: A warm-up project.
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Review of Scientific Programming in C and Fortran Michael McLennan Software Architect HUBzero™ Platform for Scientific Collaboration.
CS 206 Introduction to Computer Science II 09 / 09 / 2009 Instructor: Michael Eckmann.
Computer Science II Recursion Professor: Evan Korth New York University.
1 CENG 707 Data Structures and Algorithms Nihan Kesim Çiçekli Department of Computer Engineering Middle East Technical University Fall 2010.
C For Java Programmers Tom Roeder CS sp. Why C? The language of low-level systems programming  Commonly used (legacy code)  Trades off safety.
July Overview1 COMP 2011 Data Organisation 2004 Session 2 Lecturer: Alan Blair Head Tutor: Loc Huynh.
S Overview1 COMP 2011/2711 Data Organisation 2006 Session 1 Lecturer: Norman Foo Head Tutor: Loc Huynh; others to be nominated.
CSCE156: Introduction to Computer Science II Instructor Stephen Scott Website
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
Data Structures and Programming.  Today:  Administrivia  Introduction to 225, Stacks  Course website: 
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
Recursion Chapter Nature of Recursion t Problems that lend themselves to a recursive solution have the following characteristics: –One or more.
Introduction Ellen Walker CPSC 201 Data Structures Hiram College.
COP 3530 PROGRAM, FILE & DATA STRUCTURES Syllabus Syllabus Lab Information Lab Information Overrides Overrides Questions? Questions?
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Classes: A Deeper Look Part.
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
CSE 332: C++ debugging in Eclipse C++ Debugging in Eclipse We’ve now covered several key program features –Variable declarations, expressions and statements.
Some Basics && GDB overview Ram Sheshadri –
JAVA 0. HAFTA Algorithms FOURTH EDITION Robert Sedgewick and Kevin Wayne Princeton University.
Problem of the Day  Why are manhole covers round?
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
CPSC 102: Computer Science II Dr. Roy P. Pargas 408 Edwards Hall Office Hours 10:00-11:00 am MWF 2:00-3:00 pm TTh.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
CMSC 2021 CMSC 202 Computer Science II for Majors Fall 2002 Mr. Frey (0101 – 0104) Mr. Raouf (0201 – 0204)
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
1 CSC 222: Object-Oriented Programming Spring 2013 Course goals:  To know and use basic Java programming constructs for object- oriented problem solving.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
CSC Advanced Unix Programming, Fall, 2008 Welcome to UNIX System Programming! Tuesday, September 2 uses Monday’s schedule!
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
(language, compilation and debugging) David 09/16/2011.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
1 Today’s Objectives  Announcements Homework #3 is due on Monday, 10-Jul, however you can earn 10 bonus points for this HW if you turn it in on Wednesday,
CMSC 2021 CMSC 202 Computer Science II for Majors Spring 2002 Sections Ms. Susan Mitchell.
CMSC 2021 CMSC 202 Computer Science II for Majors Spring 2001 Sections Ms. Susan Mitchell.
CMSC 2021 CMSC 202 Computer Science II for Majors Spring 2003 Mr. Frey (0101 – 0104) Mr. Raouf (0201 – 0204)
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
Recursion A recursive definition is one which uses the word or concept being defined in the definition itself Example: “A computer is a machine.
CSC Java Programming, Fall, 2008 Week 3: Objects, Classes, Strings, Text I/O, September 11.
CSC Java Programming, Spring, 2010 Week 2: Java Data Types, Control Constructs, and their C++ counterparts.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Exceptions Exception handling.
Data Structures By Dr. Mehedi Masud ِAssociate Professor, Computer Science Dept. College of Computers and Information Systems Taif University 1.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 9.
C++ Functions A bit of review (things we’ve covered so far)
CSC 520 – Advanced Object Oriented Programming, Fall, 2010 Thursday, September 30 Week 5, Generics and Inheritance Techniques, Meyer Ch. 10 & 16.
Unit 1 - Introducing Abstract Data Type (ADT) Part 1.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
CSE 332: Scientific debugging in C++ Scientific Debugging in C++ (with Eclipse & gdb) By now we’ve covered several key C++ features –Variable declarations.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Examples (D. Schmidt et al)
CSC 222: Object-Oriented Programming
CSC 222: Object-Oriented Programming
Chapter 6 CS 3370 – C++ Functions.
CSc 020: Programming Concepts and Methodology II
DDC 2423 DATA STRUCTURE Main text:
CSC 222: Object-Oriented Programming
C++ History C++ was designed at AT&T Bell Labs by Bjarne Stroustrup in the early 80's Based on the ‘C’ programming language C++ language standardised in.
CSCE156: Introduction to Computer Science II
SPL – PS1 Introduction to C++.
CSC Java Programming, Fall, 2008
Presentation transcript:

CSC Data Structures, Fall, 2008 Welcome to Data Structures! Tuesday, September 2 uses Monday’s schedule!

Who am I? Dr. Dale E. Parson (a.k.a. Professor Parson), In a previous life I was an AT&T technician and then a Bell Labs software engineer for over 25 years. Also, I consult as Amplified Computing. I have taught at Albright College, Millersville University and Lehigh University. This is, in my opinion, the central course of the CSC curriculum. I have taught it at Albright and Millersville.

Who are you? Wide-awake Kutztown University computer science students who want to learn to design and implement data structures and algorithms in C++ at 8:00 AM three days a week! You have already taken CSC 125, CSC 136, Computer Science II, earning >= C. This course extends the topics developed in CSC 135. Also covered are: concepts of data abstraction, encapsulation, recursion; search and sort methods; and simple data structures. (Ah, this is the fine print for CSC 136!)

What are we planning to do? We will learn to build the data structures and algorithms that are at the core of substantial software systems. Containers such as lists, tables, stacks, queues, trees Sets and mappings from keys to values Algorithms for sorting or otherwise organizing data Algorithms and file I/O techniques for persistent storage We will use modular construction techniques, with the assistance of C++ abstract classes. We will use the standard template library (STL) for some projects.

References First day handout (syllabus) GNU make GDB

An example makefile makefile in ~parson/ DataStructures /lecture1/intro all: build TARGET = printdemo DEBUG = 1 include $(HOME)/makelib build: $(TARGET) $(TARGET): $(OBJFILES) $(CPPCC) $(OBJFILES) -o clean: subclean /bin/rm -f $(TARGET) $(TARGET).out $(TARGET).dif test: $(TARGET)./$(TARGET) a b c d e > $(TARGET).out diff $(TARGET).out $(TARGET).ref > $(TARGET).dif

makelib in my $HOME/ makelib CPPCC= g++ CXXFILES := $(wildcard *.cxx) OBJFILES := $(subst.cxx,.o,$(CXXFILES)) DEFFLAGS = ifeq ($(DEBUG),1) DEBUGFLAG = -g else DEBUGFLAG = endif INCFLAGS = -I. CPPFLAGS= $(DEFFLAGS) $(INCFLAGS) $(DEBUGFLAG) %.o : %.cxx $(CPPCC) -c $(CPPFLAGS) $< subclean: /bin/rm -f *.o

Some other files in my $HOME/.bash_profile -bash-3.00$ cat.bash_profile export EDITOR=/usr/local/bin/vim export VISUAL=/usr/local/bin/vim alias vi=vim alias make=gmake.vimrc -bash-3.00$ cat.vimrc set ai set ts=4 set sw=4 set expandtab set sta

Interface definitions split source along module / driver boundaries. printargs.h defines the interface to its module #ifndef PRINTARGS_H #define PRINTARGS_H #include /* Function: printargs Prints an array of strings to an output file. Parameters: outfile: output file for writing. stringv: array of \0-terminated strings to be printed. stringc: numbers of strings in stringv Return value: none Side Effects: none Preconditions: The outfile must be a non-NULL, open FILE. stringc must equal the number of strings in stringv. Each string in stringv must be terminated with a \0 character. Postconditions: none (no return values from this function). Invariants: none */ void printargs(FILE *outfile, const char **stringv, const int stringc); #endif

Implement the interface in a.cxx file. printargs.cxx implements the module of printargs.h /* printargs.cxx -- Function implementations for printargs.h. CSC237, Fall, 2008, Dr. Dale Parson, Class 1 example. This is a simple demo library module that prints an array of strings to an output file. */ #include "printargs.h" void printargs(FILE *outfile, const char **stringv, const int stringc) { int i ; for (i = 0 ; i < stringc ; i++) { fputs(stringv[i], outfile); fputs("\n", outfile); }

Invoke the interface from a client module or test driver. printmain.cxx is the test driver /* printmain.cxx -- main function that invokes printargs. CSC237, Fall, 2008, Dr. Dale Parson, Class 1 example. This is a simple driver for a demo library module that prints an array of strings to an output file. */ #include "printargs.h" int main(int argc, const char *argv[]) { printargs(stdout, argv, argc); return 0 ; }

Makefile-driven testing makefile is structured for testing -bash-3.00$ make clean test /bin/rm -f *.o /bin/rm -f printdemo printdemo.out printdemo.dif g++ -c -I. -g printargs.cxx g++ -c -I. -g printmain.cxx g++ printargs.o printmain.o -o printdemo./printdemo a b c d e > printdemo.out diff printdemo.out printdemo.ref > printdemo.dif

GDB for debugging -bash-3.00$ gdb --args printdemo a b c (gdb) break main Breakpoint 1 at 0x107f4: file printmain.cxx, line 13. (gdb) break printargs Breakpoint 2 at 0x10780: file printargs.cxx, line 14. (gdb) run Starting program: /export/home/faculty/parson/UnixSysProg/lecture1/printdemo a b c Breakpoint 1, main (argc=4, argv=0xffbffc54) at printmain.cxx:13 13printargs(stdout, argv, argc); 14(gdb) p argc 15$1 = 4 16(gdb) p &argc 17$2 = (int *) 0xffbffc34

GDB continued (gdb) cont Continuing. Breakpoint 2, printargs (outfile=0x20b20, stringv=0xffbffc54, stringc=4) at printargs.cxx:14 14 for (i = 0 ; i < stringc ; i++) { (gdb) step 15 fputs(stringv[i], outfile); (gdb) next /export/home/faculty/parson/UnixSysProg/lecture1/printdemo 16 fputs("\n", outfile); (gdb) next 14 for (i = 0 ; i < stringc ; i++) { (gdb) p i $3 = 0 (gdb) p &i $4 = (int *) 0xffbffb6c

C++ interfaces and implementation classes ~parson/DataStructures/lecture1/oo_variant We will walk through code and test execution in class. C++ abstract classes are used as interfaces. Derived C++ concrete classes provide implementation. Client code, including test drivers, use an interface without coding dependencies on underlying implementation class.

Unified Modeling Language (UML) Class Diagram of oo_variant print_main printmain.cxx > printargs_interface.h printargs_interface printargs_interface.cxx printargs(outfile : file, stringv : string[], stringc : int) printargs_simpleimpl printargs_simpleimpl.h printargs_simpleimpl.cxx

Programming practices Always check and handle error return codes! malloc() and new are exceptions that we will discuss. Error logs, exit codes and C++ exceptions are useful. Buffer overruns are annoying and dangerous See man page for gets(), for example. Make malloc/free or new/delete symmetrical. Always use { curly braces } for control blocks. Use both healthy and degenerate tests. » Ignoring these rules will cost you points.