Computer Programming and Data Structures

Programming Fundamentals in C++

Introduction to Programming Concepts

  • Codes: Refers to words or elements within programming that have specific meanings.

    • Structure: There exists a foundational order in which coding works; some words are reserved in programming languages.

  • Compiler: A tool that serves multiple functions to ensure code is executable:

    1. Spell-checks coded words for syntax errors.

    • Example: Using print(value) instead of Print(value) results in an error due to case sensitivity (the programming environment recognizes letters as case-sensitive).

    • Missing parentheses can also lead to errors (e.g., print 22 is incorrect).

    1. Linker: Connects various components of a program together.

    2. Runs/tests the code to check for any errors. If errors occur, it retries until correction.

    • Logical Error: Arises from issues within the way the algorithm functions, not detected by the compiler, which means the programmer must identify these through testing rather than syntax checks.

Variables

  • Variable: A naming convention for an unknown value, which can be assigned a value.

  • Importance of variables:

    • Naming conventions exist, where variables should not include special characters or spaces (similar to file naming rules).

    • Variable naming rules include:

    • Cannot start with a digit,

    • Must be alphanumeric,

    • Limited use of underscore (_),

    • Cannot exceed typical alphanumeric size limitations.

    • Identifiers: Names used to identify data, must be meaningful.

Algorithms and Problem Solving

  • Algorithm: Step-by-step methodology for solving a problem.

    • Compare to a recipe; ordered instructions dictate the process.

    1. Understand the Question.

    2. Determine how to proceed (method of solving).

    3. Try the method; if successful, proceed, if not, return to step 2 to reassess the approach.

  • Example Problem: To solve for x in 3x = 9, divide by 3 on both sides leading to x = 3.

  • Flowchart: A visual representation to illustrate how a program operates.

Data Types

  • Types of Data and Declarations: Different keywords are used to declare various data types, which are reserved and cannot be redefined. Example types include:

    • Int: Represents integers (e.g., int num = 25;).

    • Double: Represents decimals (e.g., double num2 = 2.5;).

    • Float: Used for floating-point arithmetic (extremely large or small numbers, e.g., float avo= 6.0e23;).

    • Char: A single character (e.g., 'a').

    • String: A sequence of characters (e.g., `