View on GitHub

Notes

reference notes

C++ Introduction

C++ Overview

Features:

Phases and Steps in Programming

Software development methodology(SDM):

  1. Problem specification, specifying the problem clearly and unambiguously
  2. Analysis, consists of IOFC, IO format, and Variables
  3. Design, cosists of Algorithm, Flowchart, Pseudocode, and control structures
  4. Implementation, consists of coding, IDE
  5. Testing, consists of unit testing + debugging + verification, test cases, execution, comparison
  6. Documentation, consists of comments and files

C++ Get Started

C++ Fundamentals

Basic elements

Data types

Data types

Peogramming operators

ARITHMETIC Expression:

RELATIONAL Expression:

LOGICAL Expression:

CONDITIONAL Expression:

Precedence and associativity rules

Depend on IDE. Precedence and associativity rules

Data type casting

C++ Flow Control

Control structures

Flow:

Selection/Conditional flow

Single-Alternative:

if (condition) {
    // statements
}

Double-Alternative:

if (condition) {
    // statements
} else {
    // statements
}

Multiple-Alternative:

if (condition) {
    // statements
} else if (condition) {
    // statements
} else {
    // statements
}

Repetition/Looping design

Counter controlled loop:

Sentinel controlled loop:

Repetition/Looping types

Entry-checking loop:

Exit-checking loop:

C++ Functions

Types of user-defined functions

C++ Arrays

Numeric Arrays

Passing individual array elements to functions

Similar to passing variables to functions:

void print(int x) {
    cout << x;
}

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    for (int i = 0; i < 5; i++) {
        print(arr[i]);
    }
} // prints 12345

Passing arrays to functions

Only the name of the array is passed to the function as an argument, not the entire array.

void print(int arr[], int size) {
    for (int i = 0; i < size; i++) {
        cout << arr[i];
    }
}

int main() {
    int arr[5] = {1, 2, 3, 4, 5};
    print(arr, 5); // prints 12345
}

C++ Strings

What are strings?

String input and manipulation functions

iostream:

cstring:

Passing strings to functions

Strings are passed to a function in a similar way arrays are passed to a function.

void print(string str) {
    cout << str;
}

int main() {
    string str = "Hello";
    print(str); // prints Hello
}