Chapter 1 2

Chapter 1 2 - Chapters 1 & 2 Chapters Programming and...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapters 1 & 2 Chapters Programming and Programs Bjarne Stroustrup Bjarne www.stroustrup.com/Programming www.stroustrup.com/Programming Abstract Today, we’ll outline the aims for this course and Today, present a rough course plan. We’ll introduce the basic notion of programming and give examples of areas in which software is critical to our civilization. Finally, we’ll present the simplest possible C++ program and outline how it can be made into running code. how Stroustrup/Programming 2 Overview Course aims and outline Programming “Hello, world!” Compilation Stroustrup/Programming 3 This is a course In Programming For beginners who want to become professionals who are assumed to be bright Though not (necessarily) geniuses who are willing to work hard i.e., people who can produce systems that others will use Though do need sleep occasionally, and take a normal course load Using the C++ programming language Stroustrup/Programming 4 Not! A Washout course A course in “if you can get into the science/engineering parts of a if university, you can handle this course” university, The C++ programming language For students who want to become language lawyers who are assumed to be a bit dim and fairly lazy We try not to get bogged down in technical obscurities We try not to spoon feed Using Some untested software development methodologies and a Some lot of unnecessarily long words lot Stroustrup/Programming 5 The Aims Teach/learn After the course, you’ll be able to Fundamental programming concepts Key useful techniques Basic Standard C++ facilities Write small colloquial C++ programs Read much larger programs Learn the basics of many other languages by yourself Proceed with an “advanced” C++ programming course After the course, you will not (yet) be After not An expert programmer A C++ language expert An expert user of advanced libraries Stroustrup/Programming 6 The Means Lectures Attend every one Notes/Chapters Read a chapter ahead (about one per lecture) Read the chapter again after each lecture Feedback is welcome (typos, suggestions, etc.) Stroustrup/Programming 7 The Means (Cont.) Work Review questions in chapters Review “Terms” in Chapters Drills Always do the drills Always do the drills before the exercises Exercises Course specific Projects That’s where the most fun and the best learning takes place Quizzes Exams Stroustrup/Programming 8 Cooperate on Learning Except for the work you hand in as individual contributions, Except we strongly encourage you to collaborate and help each strongly other other If in doubt if a collaboration is legitimate: ask! If ask! 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) When you rely on the work of others, explicitly list all of your sources When – i.e. give credit to those who did the work i.e. Don’t study alone when you don’t have to Don’t Form study groups Do help each other (without plagiarizing) Go to your TA's office hours Go prepared with questions The only stupid questions are the ones you wanted to ask but didn’t Stroustrup/Programming 9 Why C++ ? You can’t learn to program without a programming language You The purpose of a programming language is to allow you to The express your ideas in code express C++ is the language that most directly allows you to express C++ ideas from the largest number of application areas C++ is the most widely used language in engineering areas http://www.research.att.com/~bs/applications.html Stroustrup/Programming 10 10 Why C++ ? C++ is precisely and comprehensively defined by C++ an ISO standard an And that standard is almost universally accepted C++ is available on almost all kinds of computers C++ Programming concepts that you learn using C++ Programming can be used fairly directly in other languages can Including C, Java, C#, and (less directly) Fortran Stroustrup/Programming Stroustrup/Programming 11 11 Rough course outline Part I: The basics Part II: Input and Output File I/O, I/O streams Graphical output Graphical User Interface Part III: Data structures and algorithms Types, variables, strings, console I/O, computations, errors, vectors Types, functions, source files, classes functions, Free store, pointers, and arrays Lists, maps, sorting and searching, vectors, templates The STL Part IV: Broadening the view Software ideals and history Text processing, numerics, embedded systems programming, testing, C, Text Stroustrup/Programming 12 12 etc. etc. Rough course outline (Cont.) Throughout Program design and development techniques C++ language features Background and related fields, topics, and languages Note: Appendices C++ language summary C++ standard library summary Index (extensive) Glossary (short) Stroustrup/Programming 13 13 Promises Detail: We will try to explain every construct used in this We course in sufficient detail for real understanding course Utility: We will try to explain only useful concepts, constructs, We and techniques and There is no “magic” We will not try to explain every obscure detail Completeness: The concepts, constructs, and techniques can The be used in combination to construct useful programs be There are, of course, many useful concepts, constructs, and techniques There beyond what is taught here beyond Stroustrup/Programming 14 14 More Promises Realism: the concepts, constructs, and techniques can be used the to build “industrial strength” programs to Simplicity: The examples used are among the simplest The realistic ones that illustrate the concepts, constructs, and techniques techniques i.e., they have been used to … Your exercises and projects will provide more complex examples Scalability: The concepts, constructs, and techniques can be The used to construct large, reliable, and efficient programs used i.e., they have been used to … Stroustrup/Programming 15 15 Feedback request Please mail questions and constructive comments to [email protected]_institution Your feedback will be most appreciated On style, contents, detail, examples, clarity, conceptual problems, On exercises, missing information, depth, etc. exercises, Book support website (www.stroustrup.com/Programming) Local course support website Stroustrup/Programming 16 16 Why programming? Our civilization runs on software Most engineering activities involve software Note: most programs do not run on things that look Note: like a PC like a screen, a keyboard, a box under the table Stroustrup/Programming 17 17 Ships Design Construction Management Monitoring Engine Hull design Pumps Stroustrup/Programming 18 18 Aircraft Communication Control Display Signal processing “Gadget” control Monitoring Stroustrup/Programming 19 19 Phones Voice quality User interfaces Billing Mobility Stroustrup/Programming Switching Reliability Provisioning Images 20 20 Energy Control Monitoring Analysis Design Design Communications Communications Visualization Visualization Manufacturing Manufacturing Stroustrup/Programming Stroustrup/Programming 21 21 PC/workstation There’s a lot more to computing than games, word There’s processing, browsing, and spreadsheets! processing, Stroustrup/Programming 22 22 Where is C++ Used? Just about everywhere Mars rovers, animation, graphics, Photoshop, GUI, OS, compilers, slides, Mars chip design, chip manufacturing, semiconductor tools, etc. chip See www.research.att/~bs/applications.html Stroustrup/Programming 23 23 A first program – just the guts… // … // int main() { cout << "Hello, world!\n"; return 0; // main() is where a C++ program starts // is // output the 13 characters Hello, world! // // followed by a new line // followed // return a value indicating success // return } // quotes delimit a string literal // quotes // NOTE: “smart” quotes “ ” will cause compiler problems. // will // so make sure your quotes are of the style " " // so // \n is a notation for a new line // is Stroustrup/Programming 24 24 A first program – complete // a first program: first #include "../../std_lib_facilities.h" // get the library facilities needed for now // get int main() { cout << "Hello, world!\n"; return 0; // main() is where a C++ program starts // main() // output the 13 characters Hello, world! // Hello, // followed by a new line // followed // return a value indicating success // return } // note the semicolons; they terminate statements // note // curly brackets { … } group statements into a block // curly // main( ) is a function that takes no arguments ( ) // // and returns an int (integer value) to indicate success or failure and Stroustrup/Programming 25 25 A second program second // modified for Windows console mode: // modified #include "../../std_lib_facilities.h" // get the facilities for this course // get int main() { cout << "Hello, world\n"; keep_window_open(); return 0; // main() is where a C++ program starts main() // output the 13 characters hello, world! // hello, // followed by a new line followed // wait for a keystroke // wait // return a value indicating success // return } // without keep_window_open() the output window will be closed immediately // before you have a chance to read the output (on Visual C++ 2003) // before Stroustrup/Programming 26 26 Hello, world! “Hello world” is a very important program Its purpose is to help you get used to your tools Compiler Program development environment Program execution environment Type in the program carefully Type carefully After you get it to work, please make a few mistakes to see how After the tools respond; for example the Forget the header Forget to terminate the string Misspell return (e.g. retrun) Misspell return retrun Forget a semicolon Forget { or } Forget … Stroustrup/Programming 27 27 Hello world It’s almost all “boiler plate” That’s normal Most of our code, and most of the systems we use simply exist to make Most some other code elegant and/or efficient some “real world” non-software analogies abound “Boiler plate,” that is, notation, libraries, and other support is Boiler what makes our code simple, comprehensible, trustworthy, and efficient. and Only cout << "Hello, world!\n" directly does anything Only directly Would you rather write 1,000,000 lines of machine code? This implies that we should not just “get things done”; we This not should take great care that things are done elegantly, correctly, and in ways that ease the creation of more/other software: and Style Matters! Style Stroustrup/Programming 28 28 Compilation and linking C++ source code C++ compiler Object code Executable program linker You write C++ source code Object code is simple enough for a computer to “understand” The linker links your code to system code needed to execute Source code is (in principle) human readable The compiler translates what you wrote into object code (sometimes called The machine code) machine Library Object code E.g. input/output libraries, operating system code, and windowing code The result is an executable program E.g. a .exe file on windows or an a.out file on Unix a.out Stroustrup/Programming 29 29 So what is programming? Conventional definitions Telling a very fast moron exactly what to do Telling very exactly A plan for solving a problem on a computer Specifying the order of a program execution Definition from another domain (academia) A … program is an organized and directed accumulation of resources program to accomplish specific … objectives … to Good, but no mention of actually doing anything The definition we’ll use Specifying the structure and behavior of a program, and testing that the Specifying program performs its task correctly and with acceptable performance program But modern programs often involve millions of lines of code And manipulation of data is central Never forget to check that “it” works Software == one or more programs Stroustrup/Programming 30 30 Programming Programming is fundamentally simple Just state what the machine is to do So why is programming hard? We want “the machine” to do complex things The world is more complex than we’d like to believe So we don’t always know the implications of what we want “Programming is understanding” And computers are nitpicking, unforgiving, dumb beasts When you can program a task, you understand it When you program, you spend significant time trying to understand the When task you want to automate task Programming is part practical, part theory If you are just practical, you produce non-scalable unmaintainable If hacks hacks If you are just theoretical, you produce toys Stroustrup/Programming 31 31 The next lecture Will talk about types, values, variables, Will declarations, simple input and output, very simple computations, and type safety. simple Stroustrup/Programming 32 32 ...
View Full Document

This note was uploaded on 02/18/2012 for the course CSCE 121 taught by Professor Walter daugherity during the Fall '09 term at Texas A&M.

Ask a homework question - tutors are online