CS 1400 Chapter 1 Introduction and Background
What is a program? Def: A logical sequence of instructions to a computer that leads to a solution of a problem. important points: –logical sequence of instructions instructions are to be carried out in the order given –instructions to a computer while a program may produce instructions to a user, the program itself contains instructions to the computer –leads to a solution a solution may be a number, a decision, an action, etc.
Designing a program… Issues: –logical flow of instructions –mathematics and formulas –appearance of the display screen and how information is presented to the user –operation and “user friendliness” –documentation
Computers are not smart! While instructions to a friend may assume implied understanding and intelligence, instructions to a computer need to be simple, specific, and detailed. The computer will not attempt to determine the purpose of your instructions – it will only blindly carry them out.
Hardware CPU memory input devices output devices storage
What is memory? Memory can be thought of as a collection of mailboxes –Each mailbox has a unique address contents –A CPU may store something into a box retrieve the current contents of a box
Mailbox analogy limitations… A memory box or cell –may only contain one item storing a new item into a box causes the older contents to be overwritten –always contains one item before a program stores an item into a box, it will contain something (garbage) left over from the previous use
Memory (continued)… A memory cell may contain… –a number –a program instruction (more to be learned later) A memory cell address is a word assigned by a program –begins with a letter –contains only letters, digits, and underscore
Some memory cell addresses… Valid cost time age_of_the_oldest_person payrate_as_of_2007 Invalid time of day 9th_of_July $profit
Software We will use three types of software –operating system (Windows, Vista, Linux, etc) controls hardware during execution of other software –tools (Visual C++, Explorer, Word, etc) previously written programs to do common jobs –user programs custom designed new programs for special jobs
Visual C++, Visual.NET A useful software tool to help in the development of C++ user programs Contains capabilities for: –text editing –compiling –linking –debugging and execution –and more…
What is C++? C++ is a programming language –Like English: requires proper use –syntax (grammar) –semantics (meaning) –Unlike English: unambiguous context free
Components of a user program key words operators punctuation memory cell names statements or instructions
Computers can… Get a number from an input device and store it to memory Retrieve numbers from memory and perform calculations, and place the result back into memory Retrieve a number from memory and display it on an output device Display a message on an output device
Pseudocode Example: “Write a program to calculate the volume of a box, using dimensions provided by the user.” Create memory cells height, width, depth, and volume Print “Enter height, width, and depth of box:” Get height from user Get width from user Get depth from user volume = height * width * depth Print “Volume is: “ Print volume