C++ Notes Day 04
C++ Notes Day 04
1. Pattern Printing
- Pattern printing is the process of printing patterns using loops (for, while) and conditional
statements.
- Star Patterns:
**
***
****
- Number Patterns:
12
123
1234
- Alphanumeric Patterns:
AB
ABC
ABCD
- Key Concepts:
- Nested loops are used where the outer loop manages rows, and the inner loop manages
columns.
Parts of a Function:
1. Declaration (Prototype):
- Syntax:
return_type function_name(parameter_list);
Example:
2. Definition:
- Syntax:
return_type function_name(parameter_list) {
// Function body
return value;
Example:
return a + b;
3. Calling a Function:
function_name(argument_list);
Example:
3. Class
- It contains:
Syntax:
class ClassName {
public:
private:
};
Example:
class Car {
public:
string brand;
void display() {
};
4. Object
Syntax:
ClassName objectName;
Example:
Car myCar;
myCar.brand = "Toyota";
myCar.display();
5. Array
- An array is a collection of elements of the same data type stored in contiguous memory locations.
Syntax:
data_type array_name[size];
Example:
Key Points:
- Fixed size.
6. 2D Array
data_type array_name[rows][columns];
Example:
int matrix[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
Key Points:
7. String
1. Character Arrays:
#include <string>
string s = "Hello";
- Concatenation: s1 + s2
- Length: s.length()