Download C++ Exam 1 Study Guide: Unit Analysis, Exponential Notation, Software Development Phases and more Study notes Electrical and Electronics Engineering in PDF only on Docsity! Michael Morrison Problem Solving With C++ 2/20/2011 Professor David McPherson Exam 1 Study Guide Chapter 1 o Unit analysis Making sure to use consistent and correct units when making computations Cancel out corresponding units in the numerator and denominator Use one conversion factor at a time, cancel as you go If the final units are not correct, the numerical answer is also wrong English Engineering system and SI units 1 BTU = 1055 J o Exponential (4.27e3) vs. Scientific (4.27 x 103) Notation Use exponential to make entering numbers in a computer program easier Use scientific notation when performing hand calculations for verification Evaluating formulas that use very large or small numbers 10n x 10m = 10n+m 1/10-n = 10n Pico, nano, micro, milli, kilo, mega, giga, tera o Phases of software development I. Development and design Analysis (understand required outputs/inputs) Design (develop a solution/algorithm) Coding (actually write a C++ program that carries out the algorithm.) o Sequence – defines the order in which instructions are executed o Selection – allows a choice between different operations, based on some condition o Iteration – allows the same operation to be repeated based on some condition (a loop or repetition) o Invocation – involves invoking a set of statements when needed Testing/correcting o Testing – verify correctness and that requirements are met o Bug – A program error o Debugging – the process of locating an error and correcting/verifying it o Testing may reveal errors, but does not guarantee the absence of errors. II. Documentation (essential for user and for maintenance) Program description Algorithm development and changes Well-commented program listing Sample test runs Users’ manual III. Maintenance (The longest phase; possibly the primary source of revenue; good documentation is vital.) It includes: Ongoing correction of newly discovered bugs Revisions to meet changing user needs Addition of new features o Algorithms Step-by-step sequence of instructions Must terminate Describe how data is processed to produce the desired output Pseudocode – English-like phrases used to describe the steps Formula – mathematical equations Flowchart – diagrams with symbols o Four ways to construct a program o “Programming Language” (a set of instructions used to construct a program) Machine Can actually be used to operate a computer AKA executable programs, or executables Consists of a sequence of binary instructions Contains an instruction and an address Assembly Substitute word-like symbols, such as ADD, for binary opcodes Use decimal numbers and labels for memory addresses Assemblers – Translates programs into machine language Low level Tied directly to one type of computer (machine or assembly language) High level Instructions closer to real languages, like English Can be run on a variety of computer types (like C++, Java, etc.) Source code Can be written in a high- or low-level language Must be translated to machine instructions through either a… o Interpreter – each statement is translated individually and executed immediately after translation\ o Compiler – All statements are translated and stored as an executable program, or object program; execution comes later About C++ Chapter 3 o Assignment statement Left side is a variable (numberInput) = right side is a value (3.54) End with a semicolon You can use “+=” or “*=”, etc. to make something operate upon itself Prefix increment operator “++i” adds one, then assigns Postfix increment operator “i++” assigns, then adds one o Coercion – forcing a data value to another data type Value of expression on right side of an assignment will be coerced to the data type of the variable on the left side Variable on left side may also be used on the right side of an assignment o Formatting output “setw(n)” sets a width of n “setprecision(n)” sets the floating-point precision to n places (significant figures unless “fixed” is used – then it’s digits after the decimal place) “fixed” forces a decimal point and default of six digits after it o Calling a function: include header file if necessary, then [function name](data passed to the function) o Symbolic constant – constant value that is declared with an identifier using the “const” keyword (a constant’s value cannot be changed) Chapter 4 o An “if-else” statement implements a decision structure for two choices A condition is evaluated to a numerical value, with a non-zero value considered to be true and a zero value to be considered false Common problems: Misunderstanding what an expression is Using the assignment operator (=) instead of the relational operator (==) An “if-else chain” is created by nesting “if-else” statements inside the “else” portion of the outer “if-else” If any condition is true, the whole thing terminates The final “else” is executed only if no conditions were true This chain provides one selection from many possible alternatives o Relational expression – compares two operands or expressions Uses relational operators (such as <, >, <=, >=, ==, or !=>) evaluated to a numerical value of 1 or 0 (true or false) “char” values are automatically coerced to “int” values for comparison Strings with the first lower character is considered smaller o Logical operators – (&& is AND, || is OR, ! is NOT) o Compound statement – a sequence of single statements contained between braces Creates a block of statements, which is legal anywhere that a single statement is legal Any variable declared within a block is usable only within that block o Scope – the area within a program where a variable can be used (depends on where it was declared) o Switch statement – provides for one selection from many alternatives “switch” keyword starts the statement, and is followed by an expression to be evaluated “case” keyword identifies a value to be compared to the switch expression When a match is found, that corresponding case block is executed **All further cases after a match is found are executed unless a “break” statement is found.