• No results found

Fundamentals of Programming – C++


Academic year: 2020

Share "Fundamentals of Programming – C++"


Loading.... (view fulltext now)

Full text


Fundamentals of Programming –


Lecture 1: Introduction to Programming


Expected Background

■ “A one-semester college course in


■ 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.


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,


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


Course Outline (cont.)

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

■ Week 11: Applications, ■ Week 12: Database


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


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,


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.


Administrative Details (cont.)

■ Attendance is not required, but…

■ …you are responsible for everything said in


■ 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!


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.


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


The code you submit must be written


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.”


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,



■ 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


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,



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,



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:



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



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



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





■ 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



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



The Key Software Trend: Object


■ 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



Basics of a Typical C++


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

■ C++ program names extensions

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



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



Basics of a Typical C++


■ Common Input/output functions cin

» Standard input stream » Normally keyboard


» Standard output stream » Normally computer screen


» Standard error stream » Display error messages



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 #


© 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";


10 return 0; // indicate that program ended successfully


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


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.



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 – \



A Simple Program: Printing a

Line of Text



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


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