130 likes | 272 Views
CSE 20232 Lecture 2 – More Preliminaries. Reading Assignments Linux, g++ & dropboxes Simple C/C++ Program (again) Edit, Compile, Test, Submit. Reading Assignments. Begin reading in Deitel … Week 1 Sections 1.2-1.4, 1.7-1.9, 1.13-1.17 Sections 2.1-2.4 Week 2 Sections 2.5-2.7,
E N D
CSE 20232Lecture 2 – More Preliminaries • Reading Assignments • Linux, g++ & dropboxes • Simple C/C++ Program (again) • Edit, Compile, Test, Submit
Reading Assignments • Begin reading in Deitel … • Week 1 • Sections 1.2-1.4, 1.7-1.9, 1.13-1.17 • Sections 2.1-2.4 • Week 2 • Sections 2.5-2.7, • Appendices B, C, E.1-E.2
UNIX/Linux Basics • Basic commands • ls list directory 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
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; }
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 (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; }
Simple Program using Integers to Sum two Vectors #include <iostream> using namespace std; int main( ) { int x1, y1, x2, y2, rx, ry; // v1, v2, and result // prompt user and acquire inputs cout << "Enter x and y components of vector (v1): "; cin >> x1 >> y1; cout << "Enter x and y components of vector (v2): "; cin >> x2 >> y2; // compute vector sum and display result rx = x1 + x2; ry = y1 + y2; cout << "(v1 + v2) is the vector (" << rx << ',' << ry << ')' << endl; return 0; }
UNIX/Linux Basics • Creating a symbolic link • ln –s /afs/nd.edu/coursefa.06/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
UNIX/Linux Editors • Console Editors • vi Commands • i – insert mode • a – append mode • r – replace mode • x – delete character • dd – delete line • <esc> - exit mode • :! – exit with no change • ZZ – exit and save file • pico • GUI Editors • nedit – start from command line – nedit pgm.cpp & • emacs – start from command line – emacs pgm.cpp & • & runs program in background so console isn’t locked
Debuggers • Console Debuggers • gdb • Commands: help, run, print, break, cont, list, … • GUI Debuggers • DDD • Kdbg • Start both from Linux CDE menu
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.06/cse/cse20232.01/dropbox/your_afsid/hw1
Demo • Go to Linux box and show use of … • Commands • Creation of symbolic link • Editors • GNU g++ Compiler/Linker • Testing & debugging • NOTE: sample programs will be placed on the class web site