Fundamentals of Programming with C++ – Module I Quick Review
Problem-Solving Life-Cycle
- Key phases:
• Understand the statement → identify inputs, outputs, constraints.
• Analyse → decompose into sub-tasks, spot challenges.
• Plan → draw hierarchy chart.
• Develop → choose design strategy. - Design strategies:
• Top-Down: decompose main task into finer modules (structured languages: C, FORTRAN).
• Bottom-Up: build small reusable components, then integrate (OOP languages: C++, Java).
Fundamental Program Statements
- Input / Output: acquire data (keyboard, files) and present results (screen, files).
- Decision-Making: selection constructs (if-else, nested if, switch-case).
- Looping: repetition constructs (for, while, do-while).
Algorithms
- Definition: finite, ordered sequence of steps to solve a problem.
- Essential properties: clear, finite, feasible, language-independent; may accept zero+ inputs and produce ≥ one output.
- Selection skeleton: if (cond)statements else alt.
- Loop skeletons:
• For: initialise → test → update.
• While: test before body.
• Do-while: execute once, then test.
Flowcharts
- Purpose: visual step-by-step depiction of algorithm.
- Core symbols:
• Oval – Start/Stop.
• Parallelogram – Input/Output.
• Rectangle – Process.
• Rhombus – Decision (two exits: Yes/No).
• Arrow – Control flow.
• Connectors – on-page/off-page links. - Good practice: consistent symbols, top-to-bottom or left-to-right flow, clear labels, adequate spacing.
Programming Basics
- Computer program: ordered set of executable instructions yielding specific results.
- Language classes:
• Low-level: Machine language (binary 0/1), Assembly (mnemonics like MOV, ADD).
• High-level: human-oriented syntax, machine-independent (C, C++, Python …).
Language Translators
- Compiler: translates entire high-level source to machine object code in one pass; reports errors post compilation.
- Assembler: converts assembly mnemonics to binary object code.
- Interpreter: translates & executes one high-level statement at a time; stops at first error.
- Linker: merges object modules (incl. libraries) into single executable.
Testing & Debugging
- Testing: systematic execution to verify software meets requirements and is defect-free.
- Debugging: locate, analyse, fix defects uncovered during testing or execution.
Error Categories
- Syntax: rule violations caught at compile/interpret time (e.g., missing parenthesis).
- Logical: flawed algorithm produces wrong result without crashing; detected via thorough testing.
- Runtime: illegal operation during execution (e.g., division by 0); often handled with exceptions.
- Non-executed notes explaining intent, logic, or tricky code; enhance readability & maintenance.
• C/C++ single-line: // comment
• C/C++ multi-line: /* comment block */