• No results found

Fundamentals of Programming – C++

N/A
N/A
Protected

Academic year: 2020

Share "Fundamentals of Programming – C++"

Copied!
38
0
0

Loading.... (view fulltext now)

Full text

(1)

Fundamentals of Programming –

C++

Lecture 1: Introduction to Programming

(2)

Expected Background

■ “A one-semester college course in

programming.”

■ I assume you can write a program in some

language, understand variables, control structures, functions/subroutines.

■ Has background on C or C++. ■ If in doubt, let’s talk.

(3)

Course Outline

■ Week 1: Background, basics of C++, first

program, programming environments

■ Week 2: Raw materials: types, variables,

operators, program control

■ Week 3: Classes: declarations, constructors,

cleanup & garbage collection

■ Week 4: Packages, access specifiers, finals,

(4)

Course Outline (cont.)

■ Week 5: Polymorphism, abstract classes,

design patterns

■ Week 6: Interfaces & extends, inner

classes, callbacks via inner classes

■ Week 7: Arrays, container classes, iterators ■ Week 8: More on collections, collections of

(5)

Course Outline (cont.)

■ Week 9: Exception handling ■ Week 10: I/O

■ Week 11: Applications, ■ Week 12: Database

(6)

Administrative Details

■ Professor: Christine W. Pitos ■ Office: IT Office

■ “Business hours”: 7:30-11:30 & 1:00-5:00 ■ Email: chrisyyyy@gmail.com

■ Course Web sites

(7)

Administrative Details (cont.)

■ 12 weeks

■ Two consecutive 80-minute lectures per

week, a break in between the lectures.

■ Course notes in PowerPoint or HTML,

attached to the syllabus.

■ Course notes available (usually) Sunday

before class.

■ Send course questions to Blackboard,

(8)

Administrative Details (cont.)

■ Everything is attached to the syllabus.

Don’t look for assignments, etc. Look at the syllabus!

■ Homework usually weekly.

■ Submission instructions with each

assignment, usually printed listings and a softcopy.

■ Printing slides? Three to a page, at least.

(9)

Administrative Details (cont.)

■ Attendance is not required, but…

■ …you are responsible for everything said in

class.

■ I encourage you to ask questions in class. ■ This is Second Level Prograamming…you

are supposed to ask questions. Don’t guess, ask a question!

(10)

My Policy on Cheating

■ Cheating means “submitting, without proper

attribution, any computer code that is directly traceable to the computer code written by another person.”

I give students a failing course grade for

any cheating. Expulsion is also possible.

(11)

My Policy on Cheating

■ You may discuss homework problems with

classmates (although it is not to your advantage to do so).

■ You can use ideas from the literature (with

proper citation).

■ You can use anything from the

textbook/notes.

The code you submit must be written

(12)

Even More On Cheating

■ “In addition to any penalties imposed by the

instructor, including failing the course, all cheating and plagiarism infractions will be

reported in writing to the Associate Dean for the program, the Associate Dean of Faculty, the Dean of Student Affairs, and the Dean. They will

review and determine if expulsion should be

recommended. The report will become part of the student’s permanent record.”

(13)

Course Etiquette

■ Etiquette is “conduct in polite society” ■ No cell phones

■ No random comings and goings ■ If you are sleepy, go home

■ If you want to read email or surf the Web,

(14)
(15)
(16)
(17)
(18)
(19)

Activity

■ Group your self by row

■ Discuss in the group your plans in studying

computer programming by answering the ff. in 5 minutes:

– What is your team name?

– What programs would you like build/develop? – Why would you develop the said program?

■ Select a representative who will present

(20)

Programming Language Evolution

■ Machine language

■ Assembler

■ “3rd generation” (COBOL, FORTRAN, C)

■ "object-oriented" languages: C++

■ "scripting", Web, component-based, ...:

■ Java, Perl, Python, Visual Basic, Javascript, ■ Specialized (Lisp, Prolog, APL)

■ “4th generation” (SQL, GAMS, spreadsheets,

Mathematica)

(21)

Why So Many Languages?

■ Bring the language “closer” to the problem. ■ But 4GLs are typically focused on

specialized domains (e.g., relational databases).

■ We want a language that is general purpose,

(22)

22

Computer Languages

■ High-level languages

» Similar to everyday English, use common mathematical notations

» Single statements accomplish substantial tasks

■ Assembly language requires many instructions to accomplish simple tasks

» Translator programs (compilers)

■ Convert to machine language

» Interpreter programs

■ Directly execute high-level language programs

» Example:

(23)

23

History of C and C++

■ History of C

– Evolved from two other programming languages

» BCPL and B

■ “Typeless” languages

– Dennis Ritchie (Bell Laboratories)

» Added data typing, other features

– Development language of UNIX – Hardware independent

» Portable programs

– 1989: ANSI standard

– 1990: ANSI and ISO standard published

(24)

24

History of C and C++

■ History of C++

– Extension of C

– Early 1980s: Bjarne Stroustrup (Bell Laboratories)

– Provides capabilities for object-oriented programming

» Objects: reusable software components

■ Model items in real world

» Object-oriented programs

■ Easy to understand, correct and modify

– Hybrid language

» C-like style

» Object-oriented style » Both

(25)

25

C++ Standard Library

■ C++ programs

– Built from pieces called classes and functions

■ C++ standard library

– Rich collections of existing classes and functions

■ “Building block approach” to creating

programs

(26)

26

Java

■ Java – 1991: Sun Microsystems » Green project – 1995: Sun Microsystems

» Formally announced Java at trade show

– Web pages with dynamic and interactive content – Develop large-scale enterprise applications

– Enhance functionality of web servers

– Provide applications for consumer devices

(27)

27

Structured Programming

■ Structured programming (1960s)

– Disciplined approach to writing programs

– Clear, easy to test and debug, and easy to modify

■ Pascal

– 1971: Niklaus Wirth

■ Ada

– 1970s - early 1980s: US Department of Defense (DoD) – Multitasking

(28)

28

The Key Software Trend: Object

Technology

■ Objects

– Reusable software components that model real world items – Meaningful software units

» Date objects, time objects, paycheck objects, invoice objects, audio objects, video objects, file objects, record objects, etc.

» Any noun can be represented as an object

– More understandable, better organized and easier to maintain than procedural programming

– Favor modularity

» Software reuse

■ Libraries

– MFC (Microsoft Foundation Classes) – Rogue Wave

(29)

29

Basics of a Typical C++

Environment

■ C++ systems – Program-development environment – Language – C++ Standard Library

■ C++ program names extensions

– .cpp – .cxx – .cc – .C

(30)

30

Basics of a Typical C++ Environment

Phases of C++ Programs: 1. Edit 2. Preprocess 3. Compile 4. Link 5. Load 6. Execute Loader Primary Memory Program is created in the editor and stored on disk.

Preprocessor program processes the code.

Loader puts program in memory.

CPU takes each instruction and executes it, possibly storing new data values as the program executes.

Compiler

Compiler creates object code and stores it on disk.

Linker links the object code with the libraries, creates an executable file and stores it on disk

Editor Preprocessor Linker CPU Primary Memory . . . . . . . . . . . . Disk Disk Disk Disk Disk

(31)

31

Basics of a Typical C++

Environment

■ Common Input/output functions cin

» Standard input stream » Normally keyboard

cout

» Standard output stream » Normally computer screen

cerr

» Standard error stream » Display error messages

(32)

32

A Simple Program: Printing a

Line of Text

■ Before writing the programs

– Comments

» Document programs

» Improve program readability » Ignored by compiler

» Single-line comment

Use C’s comment /* .. */ OR Begin with // or

– Preprocessor directives

» Processed by preprocessor before compiling » Begin with #

(33)

© 2003 Prentice Hall, Inc. All rights reserved.

Outline 33 fig01_02.cpp (1 of 1) fig01_02.cpp output (1 of 1) 1 // Fig. 1.2: fig01_02.cpp 2 // A first program in C++. 3 #include <iostream.h> 4

5 // function main begins program execution

6 int main()

7 {

8 cout << "Welcome to C++!\n";

9

10 return 0; // indicate that program ended successfully

11

12 } // end function main

Welcome to C++!

Single-line comments. Preprocessor directive to

include input/output stream header file <iostream>. Function main appears

exactly once in every C++ program..

Function main returns an integer value.Left brace { begins function

body.

Corresponding right brace } ends function body.

Statements end with a semicolon ;.

Name cout belongs to n iostream.

Stream insertion operator. Keyword return is one of several means to exit function; value 0 indicates program terminated successfully.

(34)

34

A Simple Program: Printing a

Line of Text

■ Standard output stream object cout

– “Connected” to screen

<<

» Stream insertion operator

» Value to right (right operand) inserted into output stream

■ Escape characters – \

(35)

35

A Simple Program: Printing a

Line of Text

(36)
(37)
(38)

Assignment

Write a C++ program that displays the following shape:

References

Related documents

Berries without lesions harvested from symp- tomatic vines at maturity yielded musts with very similar quality characteristics in both the control and the treated plot at

to the further understanding of sections Chinenses and Synstylae and even the whole genus since a lot of close species (for exam- ple R. multiflora group) have undergone a

The contract considered in this paper is the wholesale price contract model, the wholesale price w is determined by the manufacturer and retailer jointly, and under

Both the European Security Strategy and China’s Position Paper on the New Security Concept emphasize the role of non-traditional threats in the international security

Up to 10 total objects which can consist of Interactive and Elaborative Objects – 8 objects will be standard Learning Services offered objects and 2 objects can be custom built

Lutron exposes lighting objects as BACnet ® Analog objects, Binary objects and Multi-State objects.. This will

The Statutory Regulation Notices related to failures to put in place care plans and risk assessments and failures to put in place safe systems for the use of bedrails, which

AN ODYSSEY TO THE HEART OF HELL &amp; BEYOND Meditations on Sanity, Suffering, Spirituality &amp; Liberation Welcome to the PDF of Darkness Shining Wild.. Included is not only