Download presentation
Presentation is loading. Please wait.
Published byAlban Daniels Modified over 9 years ago
1
1 Reading Assignments Linux, g++ & dropboxes Simple C/C++ Program (again) Edit, Compile, Test, Submit CSE 20232 Lecture 2 – More Preliminaries
2
2 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
3
3 UNIX/Linux Basics Basic commands ls list directory contents cdchange to another directory mkdir, rmdirmake or remove a directory (folder) pwddisplays current path rmremove a file mvmove or rename a file cpcopy a file lesspage through a text file mandisplay manual page on command
4
4 UNIX/Linux Basics Basic commands !! “bang bang” execute last command !xexecute last command x* |pipe output of one command into another historyshow list of previous commands ln - screate symbolic link <take input from file >send output to file >>append output to file
5
5 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; }
6
6 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 using namespace std; int main( ) { cout << “Hello World!” << endl; return 0; }
7
7 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 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; }
8
8 Simple Program using Integers to Sum two Vectors #include 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; }
9
9 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
10
10 UNIX/Linux Editors Console Editors vi Commands i – insert mode a – append mode r – replace mode x – delete character dd – delete line - 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
11
11 Debuggers Console Debuggers gdb Commands: help, run, print, break, cont, list, … GUI Debuggers DDD Kdbg Start both from Linux CDE menu
12
12 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
13
13 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.