Lecture 1OutlineWhat is Unix?Logging into Linux - ConsoleLogging into Linux - PuttyBasic Unix Commands 1Basic Unix Commands 2Basic Unix Commands 3Programming Using g++What is C++?Library Headers and NamespacesConstants and typesConsole Input and Output 1Console Input and Output 2Console I/O ExampleIn-class ExerciseWednesday, August 25 1CS 215 Fundamentals of Programming II - Lecture 1Lecture 1Introduction sheetCourse webpagehttp://csserver.evansville.edu/~hwang/f10-courses/cs215.htmlHandouts, assignmentsSupplemental resourcesC, C++, Java comparisonBasic UnixSyllabus and schedule, textbooksCS Lab and KC-267Wednesday, August 25 2CS 215 Fundamentals of Programming II - Lecture 1OutlineWhat is Unix?Logging into LinuxBasic Unix commandsProgramming using g++What is C++?Library headers and namespacesConstants and typesConsole input and outputWednesday, August 25 3CS 215 Fundamentals of Programming II - Lecture 1What is Unix?Unix is an operating system that is highly configurableLinux is an open-source version of Unix.Ubuntu is a distribution of LinuxCS Lab and KC-267 have clients that dual-boot Ubuntu Linux and Windows 7Linux clients use csserver.evansville.edu for login and home directory serviceUnix is command-line orientedWednesday, August 25 4CS 215 Fundamentals of Programming II - Lecture 1Logging into Linux - ConsoleWednesday, August 25 5CS 215 Fundamentals of Programming II - Lecture 1Logging into Linux - PuttyWednesday, August 25 6CS 215 Fundamentals of Programming II - Lecture 1Basic Unix CommandsChanging passwords - old, new, new againyppasswd - on UE client machinespasswd - on VirtualBoxCreating (sub) directories (i.e., folders)mkdir <dir1> <dir2> …Example: mkdir cs215Listing directoriesls, ls -l, ls -a, ls -la Example: ls -l cs215Wednesday, August 25 7CS 215 Fundamentals of Programming II - Lecture 1Basic Unix CommandsChanging permissions ("change mode")chmod <mode> <name1> <name2> …Mode is three sets (owner, group, world) of three privileges (read, write, execute)Represented as 9 bits (r,w,x are 1, - is 0) in octal (base 8)Example: rwx------ is read, write, execute privileges for owner only becomes 700Example: chmod 700 cs215Wednesday, August 25 8CS 215 Fundamentals of Programming II - Lecture 1Basic Unix CommandsChanging directoriescd - to home directory, cd <dir>Path relative to current directory unless starts with /Examples: cd cs215, cd /etcAlso, . ("dot" - current), .. ("dot-dot" - parent), ~ ("tilde" - home)Wildcards* - 0 or more characters, e.g. project1.*? - exactly 1 character, e.g. project?.cppWednesday, August 25 9CS 215 Fundamentals of Programming II - Lecture 1Programming Using g++Separate text editor - emacs, vim, geditC++ source files have extension .cppUser-defined header files still use .hSeparate compiler - g++Command line options: -Wall, -o <progname>Example: g++ -Wall -o hello hello.cpp./<progname> is the command to run the program; default program name is a.outSeparate build facility - makeWednesday, August 25 10CS 215 Fundamentals of Programming II - Lecture 1What is C++?C++ is a programming language based on C with objects and object-oriented constructs; on-line comparison documentFocus will be on the use of classes to design and implement abstract data typesMinor syntactic differences, for exampleComments can start with // to end of lineAlways int main (), never void main ()No need for void in parameter listWednesday, August 25 11CS 215 Fundamentals of Programming II - Lecture 1Library Headers and NamespacesC++ library headers to not have .h extensionExample: #include <iostream>C libraries have same name prefixed with 'c'Example: #include <cmath>All library names are in namespace std. Prefix names with namespace. E.g. std::coutImport names with using statementsExample: using namespace std;Example: using std::cout;Wednesday, August 25 12CS 215 Fundamentals of Programming II - Lecture 1Constants and typesUse const to define constants (not #define)Example: const int MAX_SIZE = 80;Built-in boolean type bool with literals true and falseExample: bool done = false;Library string type string defined in <string> has =, relops, +. Example:string word1 = "hot", word2 = "dog";string word3 = word1 + word2;Wednesday, August 25 13CS 215 Fundamentals of Programming II - Lecture 1Console Input and OutputC++ I/O is done using character stream objectsConsole I/O defined in <iostream>cin - ("see-in") input stream connected to keyboardcout, cerr - ("see-out", "see-err") output streams connected to screenendl - ("end-ell") newline with buffer flushingWednesday, August 25 14CS 215 Fundamentals of Programming II - Lecture 1Console Input and OutputInput streams use extraction operator (>>)<input stream> >> <variable>Skips whitespaceOutput streams use insertion operator (<<)<output stream> << <expression>Both operators return the left-hand stream operand so that multiple operations may be chained togetherWednesday, August 25 15CS 215 Fundamentals of Programming II - Lecture 1Console I/O Exampleint anInt;double aDouble;cout << "Enter an integer and " << "a double: "cin >> anInt >> aDouble;cout << "You entered " << anInt << " and " << aDouble << endl;Wednesday, August 25 16CS 215 Fundamentals of Programming II - Lecture 1In-class ExerciseWrite a C++ program that asks for two real numbers and displays which number is the larger one. E.g., (user input in bold)Enter two real numbers: 3.4 -7.3The larger number is 3.4Use a text editor to type in the program and use g++ to compile the program. Test the program. When you are confident that it works, demonstrate it to the
View Full Document