+ All Categories
Home > Documents > 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD...

1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD...

Date post: 22-Dec-2015
Category:
Upload: colleen-cox
View: 216 times
Download: 0 times
Share this document with a friend
Popular Tags:
22
1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure Linux, g++ & dropboxes CSE 20232 CSE 20232 Lecture 1 - Preliminaries Lecture 1 - Preliminaries
Transcript
Page 1: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

1

Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure Linux, g++ & dropboxes

CSE 20232CSE 20232Lecture 1 - PreliminariesLecture 1 - Preliminaries

Page 2: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

2

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

Page 3: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

3

Syllabus

Grad TA Andrew Blaich ([email protected])

Undergrad TA’s Megan Lussier ([email protected]) Patrick Finnigan ([email protected])

Location 131 Debartolo, MWF, 9:35 – 10:25

Assignments (50%) Weekly programming

Tests (50%) Midterm & Final exam

Page 4: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

4

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

Page 5: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

5

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;

Page 6: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

6

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)

Page 7: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

7

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

Page 8: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

8

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, …

Page 9: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

9

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

Page 10: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

10

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

Page 11: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

11

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

Page 12: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

12

Simple C++ Program Structure Comment block

Filename, author, date, purpose, description, … Preprocessor directives

#include … Using statements

using namespace std; Main function

int main (){

DeclarationsStatementsreturn 0;

}

Page 13: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

13

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

Page 14: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

14

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;}

Page 15: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

15

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;}

Page 16: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

16

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;}

Page 17: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

17

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

Page 18: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

18

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

Page 19: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

19

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

Page 20: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

20

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

Page 21: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

21

Reading and Homework

For next time read in Deitel Lecture 1 (Wed)

Sections 1.2-1.4, 1.7-1.9, 1.13-1.17 Lecture 2 (Fri)

Sections 2.1-2.7, Appendices B, C, E.1-E.2

Page 22: 1 Introduction & Syllabus Computer Hardware/Software Hierarchy C / C++ Problem Solving / OOAD Development Environment / Tools Simple C++ program structure.

22

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


Recommended