Lecture 1 Introduction sheet Course webpage - - PowerPoint PPT Presentation

lecture 1
SMART_READER_LITE
LIVE PREVIEW

Lecture 1 Introduction sheet Course webpage - - PowerPoint PPT Presentation

Lecture 1 Introduction sheet Course webpage http://csserver.evansville.edu/~hwang/f10-courses/cs215.html Handouts, assignments Supplemental resources C, C++, Java comparison Basic Unix Syllabus and schedule, textbooks


slide-1
SLIDE 1

Wednesday, August 25 1 CS 215 Fundamentals of Programming II - Lecture 1

Lecture 1

 Introduction sheet  Course webpage

 http://csserver.evansville.edu/~hwang/f10-courses/cs215.html

 Handouts, assignments  Supplemental resources  C, C++, Java comparison  Basic Unix

 Syllabus and schedule, textbooks  CS Lab and KC-267

slide-2
SLIDE 2

Wednesday, August 25 2 CS 215 Fundamentals of Programming II - Lecture 1

Outline

 What is Unix?  Logging into Linux  Basic Unix commands  Programming using g++  What is C++?  Library headers and namespaces  Constants and types  Console input and output

slide-3
SLIDE 3

Wednesday, August 25 3 CS 215 Fundamentals of Programming II - Lecture 1

What is Unix?

 Unix is an operating system that is highly

configurable

 Linux is an open-source version of Unix.  Ubuntu is a distribution of Linux  CS Lab and KC-267 have clients that dual-boot

Ubuntu Linux and Windows 7

 Linux clients use csserver.evansville.edu for

login and home directory service

 Unix is command-line oriented

slide-4
SLIDE 4

Wednesday, August 25 4 CS 215 Fundamentals of Programming II - Lecture 1

Logging into Linux - Console

slide-5
SLIDE 5

Wednesday, August 25 5 CS 215 Fundamentals of Programming II - Lecture 1

Logging into Linux - Putty

slide-6
SLIDE 6

Wednesday, August 25 6 CS 215 Fundamentals of Programming II - Lecture 1

Basic Unix Commands

 Changing passwords - old, new, new again

 yppasswd - on UE client machines  passwd - on VirtualBox

 Creating (sub) directories (i.e., folders)

 mkdir <dir1> <dir2> …  Example: mkdir cs215

 Listing directories

 ls, ls -l, ls -a, ls -la  Example: ls -l cs215

slide-7
SLIDE 7

Wednesday, August 25 7 CS 215 Fundamentals of Programming II - Lecture 1

Basic Unix Commands

 Changing 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 700

 Example: chmod 700 cs215

slide-8
SLIDE 8

Wednesday, August 25 8 CS 215 Fundamentals of Programming II - Lecture 1

Basic Unix Commands

 Changing directories

 cd - to home directory, cd <dir>  Path relative to current directory unless starts with /  Examples: cd cs215, cd /etc  Also, . ("dot" - current), .. ("dot-dot" - parent),

~ ("tilde" - home)

 Wildcards

 * - 0 or more characters, e.g. project1.*  ? - exactly 1 character, e.g. project?.cpp

slide-9
SLIDE 9

Wednesday, August 25 9 CS 215 Fundamentals of Programming II - Lecture 1

Programming Using g++

 Separate text editor - emacs, vim, gedit

 C++ source files have extension .cpp  User-defined header files still use .h

 Separate 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.out

 Separate build facility - make

slide-10
SLIDE 10

Wednesday, August 25 10 CS 215 Fundamentals of Programming II - Lecture 1

What is C++?

 C++ is a programming language based on C

with objects and object-oriented constructs; on- line comparison document

 Focus will be on the use of classes to design

and implement abstract data types

 Minor syntactic differences, for example

 Comments can start with // to end of line  Always int main (), never void main ()  No need for void in parameter list

slide-11
SLIDE 11

Wednesday, August 25 11 CS 215 Fundamentals of Programming II - Lecture 1

Library Headers and Namespaces

 C++ library headers to not have .h extension

 Example: #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::cout

 Import names with using statements

 Example: using namespace std;  Example: using std::cout;

slide-12
SLIDE 12

Wednesday, August 25 12 CS 215 Fundamentals of Programming II - Lecture 1

Constants and types

 Use const to define constants (not #define)

 Example: const int MAX_SIZE = 80;

 Built-in boolean type bool with literals true

and false

 Example: bool done = false;

 Library string type string defined in

<string> has =, relops, +. Example:

string word1 = "hot", word2 = "dog"; string word3 = word1 + word2;

slide-13
SLIDE 13

Wednesday, August 25 13 CS 215 Fundamentals of Programming II - Lecture 1

Console Input and Output

 C++ I/O is done using character stream objects  Console I/O defined in <iostream>

 cin - ("see-in") input stream connected to keyboard  cout, cerr - ("see-out", "see-err") output streams

connected to screen

 endl - ("end-ell") newline with buffer flushing

slide-14
SLIDE 14

Wednesday, August 25 14 CS 215 Fundamentals of Programming II - Lecture 1

Console Input and Output

 Input streams use extraction operator (>>)

 <input stream> >> <variable>  Skips whitespace

 Output streams use insertion operator (<<)

 <output stream> << <expression>

 Both operators return the left-hand stream

  • perand so that multiple operations may be

chained together

slide-15
SLIDE 15

Wednesday, August 25 15 CS 215 Fundamentals of Programming II - Lecture 1

Console I/O Example

int anInt; double aDouble; cout << "Enter an integer and " << "a double: " cin >> anInt >> aDouble; cout << "You entered " << anInt << " and " << aDouble << endl;

slide-16
SLIDE 16

Wednesday, August 25 16 CS 215 Fundamentals of Programming II - Lecture 1

In-class Exercise

 Write 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.3 The larger number is 3.4

 Use 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 instructor.