Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward...

43
Chapters 1 & 2 Chapters 1 & 2 Programming and Programming and Programs Programs Dr. Bjarne Stroustrup Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr.Walter Daugherity Dr. Ronnie Ward Dr. Ronnie Ward Dr. Teresa Leyk Dr. Teresa Leyk

Transcript of Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward...

Page 1: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

Chapters 1 & 2Chapters 1 & 2Programming and ProgramsProgramming and Programs

Dr. Bjarne Stroustrup Dr. Bjarne Stroustrup

Dr.Walter DaugherityDr.Walter Daugherity

Dr. Ronnie WardDr. Ronnie Ward

Dr. Teresa Leyk Dr. Teresa Leyk

Page 2: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

22

AnnouncementsAnnouncements

SyllabusSyllabus On the WebOn the Web

http://courses.cse.tamu.edu/teresa/engr112/112-index.html

Contact information – office hoursContact information – office hours Grading SchemeGrading Scheme Rules for the courseRules for the course Discussion of Scholastic DishonestyDiscussion of Scholastic Dishonesty Plus other good stuff…Plus other good stuff…

Page 3: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

33

AnnouncementsAnnouncements

WEB Page – WEB Page – http://courses.cse.tamu.edu/teresa/engr112/112-

index.html Lecture slidesLecture slides Lab assignmentsLab assignments Code you will needCode you will need SyllabusSyllabus Schedule of lecturesSchedule of lectures And much much more…And much much more…

Page 4: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

44

AnnouncementsAnnouncements

Schedule of LecturesSchedule of Lectures Pace of the course – day by dayPace of the course – day by day Exam Schedule Exam Schedule

Exams here – in this roomExams here – in this room During scheduled class timesDuring scheduled class times Not at nightNot at night

Extra learning event (ENGR 112 only)Extra learning event (ENGR 112 only) Industry NightIndustry Night Industry Rep Case StudyIndustry Rep Case Study

Page 5: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

55

AnnouncementsAnnouncements

ENGR 112B is for CECL, CEEL, ELEL majors who ENGR 112B is for CECL, CEEL, ELEL majors who have taken ENGR 111 and MATH 151 have taken ENGR 111 and MATH 151

CPSL majors should take CPSC 121CPSL majors should take CPSC 121

CPSC 113 is the next course after ENGR 112BCPSC 113 is the next course after ENGR 112B

Page 6: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

66

AnnouncementsAnnouncements

Required Textbook: "Programming – Principles and Practice Using C++” by Bjarne Stroustrup, Addison-Wesley,

ISBN 978-0321543721, December 2008. Book support website:

http://www.stroustrup.com/Programming

Page 7: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

77

AnnouncementsAnnouncements

Have you paid your tuition and fees?Have you paid your tuition and fees? Better do it Better do it Or you will be dropped from your classesOr you will be dropped from your classes

Are you a Vet?Are you a Vet? Go to financialaid.tamu.edu/veteransGo to financialaid.tamu.edu/veterans For information important to youFor information important to you

Page 8: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

88

AbstractAbstract

Today, we’ll outline the aims for this course and Today, we’ll outline the aims for this course and present a rough course plan. We’ll introduce present a rough course plan. We’ll introduce the basic notion of programming and give the basic notion of programming and give examples of areas in which software is critical examples of areas in which software is critical to our civilization. Finally, we’ll present the to our civilization. Finally, we’ll present the simplest possible C++ program and outline simplest possible C++ program and outline how it can be made into running code.how it can be made into running code.

Page 9: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

99

OverviewOverview

Course aims and outlineCourse aims and outline ProgrammingProgramming ““Hello, world”Hello, world” CompilationCompilation

Page 10: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1010

This is a courseThis is a course In ProgrammingIn Programming For Beginners, who want to become EngineersFor Beginners, who want to become Engineers

i.e., professionals who produce systems that others i.e., professionals who produce systems that others will usewill use

And are assumed to be BrightAnd are assumed to be Bright Though not necessarily geniusThough not necessarily genius

And hard workingAnd hard working Though do need sleep occasionally, and take about Though do need sleep occasionally, and take about

4 courses4 courses Using the C++ programming languageUsing the C++ programming language

Page 11: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1111

Not!Not!

A Washout course!!A Washout course!! A course inA course in

The C++ programming languageThe C++ programming language ForFor

Beginners, who want to become language lawyersBeginners, who want to become language lawyers Or are assumed to beOr are assumed to be

A bit dimA bit dim Fairly lazyFairly lazy

UsingUsing Some untested software development methodologies Some untested software development methodologies

and a lot of unnecessarily long wordsand a lot of unnecessarily long words

Page 12: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1212

The AimsThe Aims Teach/learnTeach/learn

Fundamental programming conceptsFundamental programming concepts Key useful techniquesKey useful techniques Basic Standard C++ facilitiesBasic Standard C++ facilities

After the course, you’ll be able toAfter the course, you’ll be able to Write small colloquial C++ programsWrite small colloquial C++ programs Read much larger programsRead much larger programs Learn the basics of many other languages by yourselfLearn the basics of many other languages by yourself Proceed with an “advanced” C++ programming courseProceed with an “advanced” C++ programming course

After the course, you will After the course, you will notnot (yet) be (yet) be An expert programmerAn expert programmer A C++ language expertA C++ language expert An expert user of advanced librariesAn expert user of advanced libraries

Page 13: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1313

The MeansThe Means

LectureLecture Attend every oneAttend every one Lecture slides will by posted on the WEB siteLecture slides will by posted on the WEB site

After the lectureAfter the lecture

Notes/ChaptersNotes/Chapters Read a chapter ahead (about one per lecture)Read a chapter ahead (about one per lecture) Feedback is welcome (typos, suggestions, etc.)Feedback is welcome (typos, suggestions, etc.)

Page 14: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1414

The Means (Cont.)The Means (Cont.) WorkWork

Review Questions in chaptersReview Questions in chapters LabsLabs

DrillsDrills ExercisesExercises

Case StudiesCase Studies ProjectProject QuizzesQuizzes Exams (Note: Exams will be held in this room Exams (Note: Exams will be held in this room

during class time)during class time)

Page 15: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1515

Warning:Warning:You really, really don’t want to see this on your record:You really, really don’t want to see this on your record:

F*F** Failure due to academic dishonesty* Failure due to academic dishonesty

Page 16: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1616

The AGGIE Honor CodeThe AGGIE Honor Code

An AGGIE does not lie, cheat or steal, An AGGIE does not lie, cheat or steal, nor tolerate those who do.nor tolerate those who do.

In particular:In particular:Don’t claim to have written code that you copied from others.Don’t claim to have written code that you copied from others.Don’t give anyone else your code (to hand in for a grade).Don’t give anyone else your code (to hand in for a grade).When you rely on the work of others, explicitly list all of your sources – When you rely on the work of others, explicitly list all of your sources – i.e. i.e. Give credit to those who did the work.Give credit to those who did the work.

See the discussion on the Honor Code in the Course SyllabusSee the discussion on the Honor Code in the Course Syllabus

Writing AssignmentWriting Assignment

Page 17: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1717

Cooperate on LearningCooperate on Learning Except for the work you hand in as individual Except for the work you hand in as individual

contributions, we contributions, we strongly strongly encourage you to encourage you to collaborate and help each othercollaborate and help each other

If in doubt if a collaboration is legitimate: If in doubt if a collaboration is legitimate: ask!ask! Don’t study alone when you don’t have to Don’t study alone when you don’t have to

Form study groupsForm study groups Do help each other (without plagiarizing)Do help each other (without plagiarizing)

Go to your TA's office hoursGo to your TA's office hours Go prepared with questionsGo prepared with questions The only stupid questions are the ones you wanted to ask The only stupid questions are the ones you wanted to ask

but didn’tbut didn’t

Page 18: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1818

How to be SuccessfulHow to be Successful Attend the lecturesAttend the lectures Read the chaptersRead the chapters Do the workDo the work Make use of TAs and PTsMake use of TAs and PTs Study groupsStudy groups Multiple resourcesMultiple resources

C++ Primer by Lippman, Lajoie, and MooC++ Primer by Lippman, Lajoie, and Moo Thinking in C++ by Bruce EckelThinking in C++ by Bruce Eckel

Develop skills – write a LOT of programsDevelop skills – write a LOT of programs Attend supplemental instruction (if available)Attend supplemental instruction (if available)

Page 19: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

1919

Why C++ ?Why C++ ? You can’t learn to program without a programming You can’t learn to program without a programming

language language The purpose of a programming language is to allow The purpose of a programming language is to allow

you to express your ideas in codeyou to express your ideas in code C++ is the language that most directly allows you to C++ is the language that most directly allows you to

express ideas from the largest number of express ideas from the largest number of engineering areas engineering areas

C++ is the most widely used language in the C++ is the most widely used language in the engineering areas you are likely to work inengineering areas you are likely to work in

http://www.research.att.com/~bs/applications.htmlhttp://www.research.att.com/~bs/applications.html

Page 20: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2020

Why C++ ?Why C++ ?

C++ is precisely and comprehensively C++ is precisely and comprehensively defined by an ISO standarddefined by an ISO standard

And that standard is almost universally acceptedAnd that standard is almost universally accepted

C++ is available on almost all kinds of C++ is available on almost all kinds of computers computers

Programming concepts that you learn using Programming concepts that you learn using C++ can be used fairly directly in other C++ can be used fairly directly in other languageslanguages

Including C, Java, C#, and (less directly) FortranIncluding C, Java, C#, and (less directly) Fortran

Page 21: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2121

Rough course outlineRough course outline The basicsThe basics

Types, variables, strings, console I/O, computations, errors, Types, variables, strings, console I/O, computations, errors, functions, source files. classesfunctions, source files. classes

I/OI/O File I/O, I/O streamsFile I/O, I/O streams Customizing I/OCustomizing I/O

GraphicsGraphics Output graphicsOutput graphics Graphic classesGraphic classes Graphical User InterfaceGraphical User Interface

Page 22: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2222

Rough course outline (Cont.)Rough course outline (Cont.) Data structures and algorithmsData structures and algorithms

The STLThe STL Lists, maps, sorting and searching, vectors, templates, Lists, maps, sorting and searching, vectors, templates,

matricesmatrices Broadening the viewBroadening the view

C and Java, embedded systems programming, history and C and Java, embedded systems programming, history and ideals, etc.ideals, etc.

ThroughoutThroughout Program design and development techniquesProgram design and development techniques C++ language featuresC++ language features Background and related fields, topics, and languagesBackground and related fields, topics, and languages

Page 23: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2323

PromisesPromises DetailDetail: We will try to explain every construct used in : We will try to explain every construct used in

this course in sufficient detail for real understandingthis course in sufficient detail for real understanding There is no “magic”There is no “magic”

UtilityUtility: We will try to explain only useful concepts, : We will try to explain only useful concepts, constructs, and techniquesconstructs, and techniques We will not try to explain every obscure detailWe will not try to explain every obscure detail

CompletenessCompleteness: The concepts, constructs, and : The concepts, constructs, and techniques can be used in combination to construct techniques can be used in combination to construct useful programsuseful programs There are, of course, many useful concepts, constructs, and There are, of course, many useful concepts, constructs, and

techniques beyond what is taught heretechniques beyond what is taught here

Page 24: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2424

More PromisesMore Promises RealismRealism: the concepts, constructs, and techniques can : the concepts, constructs, and techniques can

be used to build “industrial strength” programsbe used to build “industrial strength” programs i.e., they have been used to …i.e., they have been used to …

SimplicitySimplicity: The examples used are among the : The examples used are among the simplest realistic ones that illustrate the concepts, simplest realistic ones that illustrate the concepts, constructs, and techniquesconstructs, and techniques Your exercises and projects will provide more complex Your exercises and projects will provide more complex

examplesexamples ScalabilityScalability: The concepts, constructs, and techniques : The concepts, constructs, and techniques

can be used to construct large, reliable, and efficient can be used to construct large, reliable, and efficient programsprograms i.e., they have been used to …i.e., they have been used to …

Page 25: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2525

Feedback requestFeedback request

Please mail questions and constructive comments toPlease mail questions and constructive comments [email protected]@neo.tamu.edu

We willWe will Post summaries of the most important questions and answers Post summaries of the most important questions and answers Adjust future lectures where needed and possibleAdjust future lectures where needed and possible Revise future versions of this courseRevise future versions of this course

Your feedback will be most appreciatedYour feedback will be most appreciated On style, contents, detail, examples, clarity, conceptual problems, exercises, On style, contents, detail, examples, clarity, conceptual problems, exercises,

missing information, depth, etc.missing information, depth, etc.

Course website:Course website:http://courses.cse.tamu.edu/teresa/engr112/112-index.html

Page 26: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2626

Why programming?Why programming?

Our civilization runs on softwareOur civilization runs on software Most engineering activities involve softwareMost engineering activities involve software

Note: most programs do not run on things that Note: most programs do not run on things that look like a PClook like a PC a screen, a keyboard, a box under the tablea screen, a keyboard, a box under the table

Page 27: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2727

ShipsShips

DesignDesign ConstructionConstruction ManagementManagement

MonitoringMonitoring EngineEngine HullHull PumpsPumps

Page 28: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2828

AircraftAircraft

CommunicationCommunication ControlControl DisplayDisplay

Signal processingSignal processing Gadget controlGadget control MonitoringMonitoring

Page 29: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

2929

PhonesPhones

Voice qualityVoice quality User interfacesUser interfaces BillingBilling MobilityMobility

SwitchingSwitching ReliabilityReliability ProvisioningProvisioning ImagesImages

Page 30: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3030

PowerPower

ControlControl MonitoringMonitoring AnalysisAnalysis Design Design

CommunicationCommunications s

Visualization Visualization Manufacturing Manufacturing

Page 31: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3131

PC/workstationPC/workstation

There’s a lot more to computing than There’s a lot more to computing than games, word processing, browsing, and games, word processing, browsing, and spreadsheets!spreadsheets!

Page 32: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3232

Where is C++ Used?Where is C++ Used? Just about everywhereJust about everywhere

Mars rovers, animation, graphics, Photoshop, GUI, OS, compilers, slides, chip design, chip manufacturing, semiconductor tools, etc.

See: http://www.research.att/~bs/applications.html

Page 33: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3333

A first program – just the guts…A first program – just the guts…

// // ……

int main()int main() // main() // main() is where a C++ program is where a C++ program startsstarts

{{cout << "Hello, world!\n";cout << "Hello, world!\n"; // // output the 12 characters output the 12 characters Hello, Hello, worldworld

// // followed by a new linefollowed by a new linereturn 0;return 0; // // return a value indicating successreturn a value indicating success

}}

// // quotes delimit a string literalquotes delimit a string literal// NOTE: // NOTE: quotes of this style quotes of this style “ ” will cause compiler problems.“ ” will cause compiler problems.// // so make sure your quotes are of the style " "so make sure your quotes are of the style " "// \n // \n is a notation for a new lineis a notation for a new line

Page 34: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3434

A first program – completeA first program – complete// a first program// a first program

#include "../../std_lib_facilities.h"#include "../../std_lib_facilities.h" // get the facilities for this course// get the facilities for this course

int main()int main() // main() is where a C++ program starts// main() is where a C++ program starts{{

cout << "Hello, world\n";cout << "Hello, world\n"; // output the 12 characters Hello, // output the 12 characters Hello, worldworld

// followed by a new line// followed by a new linereturn 0;return 0; // return a value indicating success// return a value indicating success

}}

// note the semicolons; they terminate statements// note the semicolons; they terminate statements// curly brackets { … } group statements into a block// curly brackets { … } group statements into a block// main( ) is a function that takes no arguments ( ) // main( ) is a function that takes no arguments ( ) // and returns an int (integer value) to indicate success or failure// and returns an int (integer value) to indicate success or failure

Page 35: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3535

A second program A second program // modified for Windows™ console mode// modified for Windows™ console mode

#include "../../std_lib_facilities.h"#include "../../std_lib_facilities.h" // get the facilities for this course// get the facilities for this course

int main()int main() // main() is where a C++ program starts// main() is where a C++ program starts{{

cout << "Hello, world\n";cout << "Hello, world\n"; // output the 12 characters hello, // output the 12 characters hello, worldworld

// followed by a new line// followed by a new linekeep_window_open();keep_window_open(); // wait for a keystroke// wait for a keystrokereturn 0;return 0; // return a value indicating success// return a value indicating success

}}

// without keep_window_open() the output window will be closed // without keep_window_open() the output window will be closed immediately immediately

// before you have a chance to read the output (on Visual C++ 2003)// before you have a chance to read the output (on Visual C++ 2003)

Page 36: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3636

Hello worldHello world ““Hello world” is a very important programHello world” is a very important program

Its purpose is to help you get used to your toolsIts purpose is to help you get used to your tools CompilerCompiler Program development environmentProgram development environment Program execution environmentProgram execution environment

Type in the program Type in the program carefullycarefully After you get it to work, please make a few mistakes to see how the After you get it to work, please make a few mistakes to see how the

tools respond; for exampletools respond; for example Forget the headerForget the header Forget to terminate the stringForget to terminate the string Misspell return (e.g. retrun)Misspell return (e.g. retrun) Forget a semicolonForget a semicolon Forget Forget {{ or or } } ……

Page 37: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3737

Hello worldHello world It’s almost all “boiler plate”It’s almost all “boiler plate”

Only cout << "Hello, world\n" directly does anythingOnly cout << "Hello, world\n" directly does anything That’s normalThat’s normal

Most of our code, and most of the systems we use simply exist to make Most of our code, and most of the systems we use simply exist to make some other code elegant and/or efficientsome other code elegant and/or efficient

““real world” non-software analogies aboundreal world” non-software analogies abound ““Boiler plate,” that is, notation, libraries, and other support is Boiler plate,” that is, notation, libraries, and other support is

what makes our code simple, comprehensible, trustworthy, what makes our code simple, comprehensible, trustworthy, and efficient.and efficient. Would you rather write 1,000,000 lines of machine code?Would you rather write 1,000,000 lines of machine code?

This implies that we should not just “get things done”; we This implies that we should not just “get things done”; we should take great care that things are done elegantly, correctly, should take great care that things are done elegantly, correctly, and in ways that ease the creation of more/other software:and in ways that ease the creation of more/other software:

Style Matters!Style Matters!

Page 38: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3838

Compilation and linkingCompilation and linking

You write C++ source codeYou write C++ source code Source code is (in principle) human readableSource code is (in principle) human readable

The compiler translates what you wrote into object code (sometimes called The compiler translates what you wrote into object code (sometimes called machine code)machine code) Object code is simple enough for a computer to “understand”Object code is simple enough for a computer to “understand”

The linker links your code to system code needed to executeThe linker links your code to system code needed to execute E.g. input/output libraries, operating system code, and windowing codeE.g. input/output libraries, operating system code, and windowing code

The result is an executable programThe result is an executable program E.g. aE.g. a .exe .exe file on windows or an a.out file on Unix file on windows or an a.out file on Unix

C++ compiler

C++ source code

Object code

linkerExecutable program

Page 39: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

3939

So what is programming?So what is programming? Conventional definitionsConventional definitions

Telling a Telling a veryvery fast moron fast moron exactlyexactly what to do what to do A plan for solving a problem on a computerA plan for solving a problem on a computer Specifying the order of a program executionSpecifying the order of a program execution

But modern programs often involve millions of lines of codeBut modern programs often involve millions of lines of code And manipulation of data is centralAnd manipulation of data is central

Definition from another domain (academia)Definition from another domain (academia) A … program is an organized and directed accumulation of resources A … program is an organized and directed accumulation of resources

to accomplish specific … objectives …to accomplish specific … objectives … Good, but no mention of actually doing anythingGood, but no mention of actually doing anything

The definition we’ll useThe definition we’ll use Specifying the structure and behavior of a program, and testing that the Specifying the structure and behavior of a program, and testing that the

program performs its task correctly and with acceptable performanceprogram performs its task correctly and with acceptable performance Never forget to check that “it” worksNever forget to check that “it” works

Software == one or more programsSoftware == one or more programs

Page 40: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

4040

ProgrammingProgramming Programming is fundamentally simpleProgramming is fundamentally simple

Just state what the machine is to doJust state what the machine is to do So why is programming hard?So why is programming hard?

We want “the machine” to do complex thingsWe want “the machine” to do complex things And computers are nitpicking, unforgiving, dumb beastsAnd computers are nitpicking, unforgiving, dumb beasts

The world is more complex than we’d like to believeThe world is more complex than we’d like to believe So we don’t always know the implications of what we wantSo we don’t always know the implications of what we want

““Programming is understanding”Programming is understanding” When you can program a task, you understand itWhen you can program a task, you understand it When you program, you spend significant time trying to understand the When you program, you spend significant time trying to understand the

task you want to automatetask you want to automate Programming is part practical, part theoryProgramming is part practical, part theory

If you are just practical, you produce non-scalable unmaintainable hacksIf you are just practical, you produce non-scalable unmaintainable hacks If you are just theoretical, you produce toysIf you are just theoretical, you produce toys

Page 41: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

4141

To doTo do

Get the textbookGet the textbook ReadRead

ForewordForeword Chapter 0Chapter 0 Chapters 1, 2, and 3Chapters 1, 2, and 3 Appendix G2Appendix G2

DoDo Appendix G2 in labAppendix G2 in lab Get CPSC computer accountsGet CPSC computer accounts

Page 42: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

4242

The next lectureThe next lecture

Will talk about types, values, variables, Will talk about types, values, variables, declarations, simple input and output, very declarations, simple input and output, very simple computations, and type safety.simple computations, and type safety.

Page 43: Chapters 1 & 2 Programming and Programs Dr. Bjarne Stroustrup Dr.Walter Daugherity Dr. Ronnie Ward Dr. Teresa Leyk.

4343

TermsTerms C++C++ coutcout CommentComment CompilerCompiler ExecutionExecution Execution environmentExecution environment HeaderHeader LinkerLinker main()main() Object codeObject code

OutputOutput ProgramProgram ProgrammingProgramming Programming languageProgramming language SoftwareSoftware Software Development Software Development

Environment (SDE)Environment (SDE) Source codeSource code

For an extensive on-line glossary, see For an extensive on-line glossary, see http://www.research.att.com/~bs/glossary.htmlhttp://www.research.att.com/~bs/glossary.html