230 likes | 446 Views
CSE 20232 Lecture 1 - Preliminaries. Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure Linux, g++ & dropboxes. Introduction. John H Stewman, PhD Education BA (History), Duke
E N D
CSE 20232Lecture 1 - Preliminaries • Introduction & Syllabus • Computer Hardware/Software Hierarchy • C / C++ • Problem Solving / OOAD • Development Environment / Tools • Simple C++ program structure • Linux, g++ & dropboxes
Introduction • John H Stewman, PhD • Education • BA (History), Duke • BS (Computer Engineering), USF • MS (Computer Science), USF • PhD (Comp. Sci. & Engr.), USF • Research • Computer Vision – DARWIN project (Eckerd College) • Employment • US Navy • Eckerd College • Notre Dame
Syllabus • Grad TA • S. Niaz Arifin (sarifin@nd.edu) • Undergrad TA’s • Joey Schmitt • Joe Thompson • Location • 215 Debartolo, MWF, 9:35 – 10:25 • Assignments (50%) • Weekly programming • Tests (50%) • 2 Midterms & Final exam
What is a “Computer?” • Hardware • Input devices (mouse, keyboard, scanner,…) • Primary Memory (RAM) • Secondary Memory (Hard drive, CD, floppy,…) • Output devices (monitor, speakers, …) • CPU (central processing unit) • Control unit -- fetch-execute cycle • ALU (arithmetic logic unit) • Software • Operating System (Linux, Windows, UNIX, …) • Interpret commands and manage access to resources • Application (Word, FreeCell, Doom, …) • Provide productivity tools, entertainment • Create a “virtual” machine
Programming Language Preliminaries • Language hierarchy • Machine language • numeric codes for basic hardware operations • Assembly language • mnemonic codes for basic hardware operations • load, add, store, … • High-level language (Pascal, C/C++, Java, Ada …) • English-like instructions and constructs for combinations of basic hardware operations • x = 3; • if (x < y) x = y;
Programming Language Preliminaries • Interpreter • Reads, translates and executes program instructions on the fly • Compiler • Translates high-level source code into relocatable object code (assembly or machine)
C / C++ History • BCPL (Martin Richards 1967) • For writing compilers and operating systems • B (Ken Thompson 1970) • Based on BCPL & used to create early version of UNIX at Bell Labs • C (Dennis Ritchie) • Evolved from B & BCPL • Became the development language for UNIX • C programs can be portable (platform independent) • Standard is ANSI/ISO 9899; 1990
C / C++ History • C++ (Bjarne Stroustrup – early 1980’s) • Extension of C • Supports Object-oriented programming • User definable object classes • Facilitates development of reusable software components • C++ Standard Library • LARGE Collection of existing classes & algorithms • string, vector, list, set, map, … • sorts, comparitors, …
Problem Solving Steps • State the problem • Analyze the requirements • Inputs & outputs, precision, timeliness, environment … • Develop a design for the solution • OOAD - Identify key objects • Object attributes become data members • Object behavior become member functions • Identify how objects interact to solve problem • Develop algorithms for functions • Write pseudocode for algorithms • Refine program structure and repeat process • Top-down vs. bottom-up
Program Development Tools • Editor • Create the C++ source code • Save source to disk • Preprocessor • Scan source for preprocessor directives (#include, …) • Compiler • Scan source and translate into object code • Save object code to disk • Linker • Link various object code modules into final executable • Resolve addressing issues between modules • Save executable to disk • Loader • Place executable in main memory and start execution
Abstraction • Description of what something does not how • Data Abstraction • string, stack, queue, complex number • Functional abstraction • sqrt(), sort(), • Encapsulation • Binding of values and operations within a single program entity • Ex: C++ class or data type (int, string, …) • Information hiding • Separating implementation details from interface details • Ex: .h and .cpp files, public vs. private
Simple C++ Program Structure • Comment block • Filename, author, date, purpose, description, … • Preprocessor directives #include … • Using statements using namespace std; • Main function int main () { Declarations Statements return 0; }
C++ Basics • Comments are for humans and are ignored by the compiler • // rest of line after double slash is ignored • /* everything between markers is ignored */ • Include directives load predefined code interfaces so compiler “knows” about functions, classes, and other predefined entities • #include <iostream> • loads C++ header from “normal” location • Headers define entities within namespaces • #include <stdlib.h> • loads C-style header from “normal” location • No namespaces • #include “myStuff.h” • Loads user-defined header from current directory • May or may not contain namespaces
Simple C++ Program (helloWorld.cpp) // file: helloWorld.cpp // author: J H Stewman // date: 8/22/2006 // purpose: CSE 20232 – Notre Dame – demo // description: // this shows the world we care #include <iostream> using namespace std; int main( ) { cout << “Hello World!” << endl; return 0; }
Simple C++ Program (helloWorld2.cpp) // file: helloWorld2.cpp // author: J H Stewman // date: 8/22/2006 // purpose: CSE 20232 – Notre Dame – demo // description: // shows the world we care // (with scope resolution operator ::) #include <iostream> int main( ) { std::cout << “Hello World!” << std::endl; return 0; }
Simple C++ Program (addTwo.cpp) // file: addTwo.cpp // author: J H Stewman // date: 8/22/2006 // purpose: CSE 20232 – Notre Dame – demo // description: ages you by two years #include <iostream> using namespace std; int main( ) { int age; cout << “Hello, what is your age? ”; cin >> age; cout << “In two years you will be ” << age + 2 << endl; return 0; }
UNIX/Linux Basics • Basic commands • ls list current director contents • cd change to another directory • mkdir, rmdir make or remove a directory (folder) • pwd displays current path • rm remove a file • mv move or rename a file • cp copy a file • less page through a text file • man display manual page on command
UNIX/Linux Basics • Basic commands • !! “bang bang” execute last command • !x execute last command x* • | pipe output of one command into another • history show list of previous commands • ln - s create symbolic link • < take input from file • > send output to file • >> append output to file
UNIX/Linux Basics • Creating a symbolic link • ln –s /afs/nd.edu/coursefa.08/cse/cse20232.01/dropbox/jstewman mydrop • Compiling • Compile source to object file • g++ -g -c helloWorld.cpp • Link object file and create executable • g++ -o helloWorld helloWorld.o • Do it all in one step • g++ -g -o helloWorld helloWorld.cpp
Run / Test / Submit • Run your program from a Terminal or xterm by typing … • ./helloWorld • If it does not work correctly, it has a “bug,” so … • Make changes to source, recompile, link, and test again • This is called “testing and debugging” • To submit your program to your dropbox … • if you created a symbolic link (mydropbox) • cp hw1_1.cpp mydropbox/hw1 • otherwise ... • cp hw1_1.cpp /afs/nd.edu/coursefa.08/cse/cse20232.01/dropbox/your_afsid/hw1
Reading and Homework • For this week read in Deitel • Chapter 1 • Sections 1.2-1.6, 1.8-1.10, 1.14-1.17 • Chapter 2 • Sections 2.1-2.4 • Appendices • E.1-E.2
Demo • Go to Linux box and show use of … • Commands • Creation of symbolic link • Editor • GNU g++ Compiler/Linker • Testing & debugging • NOTE: sample programs will be placed on the class web site