Computer Programming 1
Total Page:16
File Type:pdf, Size:1020Kb
Computer programming 1 Computer Programming Copyright © Milo Except where noted, all text is copyright Milo. Unless otherwise specified, all materials in this book are owned by the original copyright holder. PDF version of October 2007 This PDF is version 0 from 14 October 2007. The intent of this free downloadable college text book is to attempt to directly help poor and middle class students with the high cost of college text books by providing a high quality free alternative that can be used in the classroom for a subject that most college students are required to take. This free downloadable book is based on and includes materials from http://www.OSdata.com . Materials from OSdata.com have already been used in more than 300 colleges and universities around the world and have been quoted in studies and policy decisions by the U.S. Navy and the government of the Federal Republic of Germany. This is still a work in progress. Feedback and constructive criticism appreciated (especially feedback from professors who might want to use the finished book). While this book is still being written, professors are free to use specific chapters (or portions of chapters) as class handouts to supplement existing for-profit text books. This same policy will continue to apply after the book is completed, but this policy offers usefulness for many classes right now today even though the book is still incomplete. Poor students should not feel bad about using this book for free. You are exactly who this book is intended to help. You may optionally do volunteer work for the charitable organization of your choice (not political or religious activity — actual work for a charitable organization helping the poor, the elderly, the sick, the disabled, or the environment, etc.). Distributed on the honor system. If you print out this book or read substantial portions on a computer screen (after the book is completed), please send a $10 donation to the author at: Milo, PO Box 1361, Tustin, CA, 92781, USA. Donations will help support further research and writing. You do not have to make multiple donations when you download new editions/versions of this book. Those who make a donation have permission to print out future versions of this book, as well as back up and replacement copies of this book, for no additional donation (although additional donations would be appreciated). Remember that any donations are voluntary and donations are not expected from those who are poor or otherwise might be burdened by the cost of making a donation. Corporations or rich people who want to help support the writing of this book are encouraged to make donations and will be specifically mentioned for their support. author: Milo, PO Box 1361, Tustin, CA, 92781, USA The e-mail address for contacting the author changes regularly to avoid spam. The current e-mail address for contacting the author is on the website OSdata.com. 1 of 158 10/14/07 11:05 AM Computer programming 2 credits Elaine Higgins, Language Finger, Maureen and Mike Mansfield Library, University of Montana, http://www.lib.umt.edu/ Neal Ziring, The Language Guide, University of Michigan, http://www.engin.umd.umich.edu/CIS/course.des/cis400/index.html copyright information This free downloadable computer programming text book is Copyright © Milo except where specifically noted otherwise. Students have permission to download this free computer programming textbook (in whole or in part) and print out copies for personal use. Government schools and the instructors/professors/teachers at government schools have permission to download and print copies of this free computer programming textbook (in whole or in part) for personal use and for distribution to students in their classes. Schools/instructors/professors/teachers may charge a reasonable fee to cover the cost of printing, binding, and other related costs. The schools and educators granted permission in the paragraph above may change the order of material, add new material, delete existing material, and otherwise make changes that customize the book for their classes. Schools and educators are asked to provide copies of any new materials added and indicate whether they want to credited by name and institution or anonymously. Others wishing to print this free text book should contact the author with their request. Those who can afford to pay for this computer programming text book, should send cash donations to Milo, PO Box 1361, Tustin, California, USA, 92781. 2 of 158 10/14/07 11:05 AM Computer programming 3 goal of this text book The goal of this book is to provide a free downloadable text that can be used in college and high school computer programming classes. According to the Los Angeles Times college text books average $120 each (late 2006) and the major book publishers are still jacking up the prices. According to the LA Times, many poor students are barred from higher education (even though they have financial aid or a scholarship) because they simply can’t afford the price of text books, which can be more than a thousand dollars a semester/quarter. For-profit book publishing corporations use numerous malicious tricks to keep pushing up the price of text books and reduce the use of recycled used text books. Their racist purpose in engaging in these activities is to price text books out of the range of poor people so as to keep the mostly minority poor children from having the same equal access to education as rich white children. The major book publishers put out new (more expensive) editions of text books every three years. It just happens to be that three years is the amount of time for a text book to saturate the used text book market and cut into sales of new books. The book publishers claim that this is mere coincidence with the timing of their new editions and that they only publish new editions when they need to make improvements on the existing text. They claim it is mere coincidence that these “necessary” improvements happen to exactly match the sales cycle for every text book they publish! I do actively encourage students, teachers, and professional programmers to provide useful feedback and criticism to help make this project useful as a free downloadable college text book. Donations of money to help support the writing and hosting of this project are greatly appreciated. See mailing address above. using this text book This book is divided into two major sections. This organization reflects the way computer programming is normally taught: an overview class that gives a foundation in basic concepts, followed by a series of more advanced classes that go back over the same material in much more detail. The first section provides an introduction and overview to computer programming. This first section is further divided into general discussions and language specific discussions. It is generally unwise for beginners to attempt to learn more than one programming language at a time. Each programming language is color coded. The choice of colors is completely arbitrary and has nno meaning. The second section provides a detailed examination and reference for advanced studies in computer programming and computer science. Do not expect for this book to be assigned in the same order as it is written. There are many different ways to teach computer programming, so your particular professor or instructor is likely to change the order of presentation of the material, probably also deleting entire chapters and possibly inntroducing additional outside materials. In particular, there is more material in the introductory section than can reasonably be covered in a 3 of 158 10/14/07 11:05 AM Computer programming 4 single class. Your professor will decide which materials should be emphasized and which materials should be skipped. Some programming languages naturally emphasize some materials and don’t include others. Most schools start students on programming as quickly as possible. Don’t be surprised if your professor skips over some or all of the early chapters and tells you that some or all is material that you should already know. Once the introductory material has been covered, the advanced material can literally be taught in almost any order. Important Note: For the sake of clarity, much of the material in the first section is watered down and simplified. Most exceptions (including some important ones) will be overlooked. Many details (including some important ones) will be ignored. Terminology will be used in a casual manner without formal definitions. Including all that information would just bog down the discussion and make it more difficult to understand the basic principles. 4 of 158 10/14/07 11:05 AM Computer programming 5 table of contents Section 1: Introduction copyright information — page 1 goal of this textbook — page 3 using this text book — page 3 table of contents — page 5 picking a class — page 7 syllabus — page 7 computer programming — page 13 size of programs — page 13 basics of computer hardware — page 15 parts of a computer — page 15 processor — page 16 main storage — page 17 external storage — page 18 input/output — page 18 input — page 18 output — page 19 kinds of programming — page 20 programming languages — page 21 direct programming — page 21 machine and object code — page 21 assemblers — page 21 high level languages — page 21 interpreters — page 22 compilers — page 22 linkers — page 22 loaders — page 22 editors — page 23 command line interface — page 23 development environment — page 23 standards and variants — page 24 history of programming languages — page 25 Hello World — page 38 C — page 39 Pascal — page 41 PHP — page 42 creating a program — page 44 listings and errors — page 45 free form vs.