0% found this document useful (0 votes)
2 views5 pages

C++ Notes Day 04

The document provides notes on C++ programming concepts including pattern printing, functions, classes, objects, arrays, 2D arrays, and strings. Key topics include the use of loops for pattern printing, the structure and usage of functions, and the definition of classes and objects. It also covers array types and string operations, highlighting syntax and examples for each concept.

Uploaded by

nikhilandjpn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

C++ Notes Day 04

The document provides notes on C++ programming concepts including pattern printing, functions, classes, objects, arrays, 2D arrays, and strings. Key topics include the use of loops for pattern printing, the structure and usage of functions, and the definition of classes and objects. It also covers array types and string operations, highlighting syntax and examples for each concept.

Uploaded by

nikhilandjpn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

C++ Notes

1. Pattern Printing

- Pattern printing is the process of printing patterns using loops (for, while) and conditional

statements.

- Patterns can be of different types:

- 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.

- Conditional statements may be used to determine the value to be printed.


2. Functions

- A function is a block of reusable code designed to perform a specific task.

- Functions improve modularity, reusability, and readability.

Parts of a Function:

1. Declaration (Prototype):

- Specifies the function's name, return type, and parameters.

- It tells the compiler that a function exists.

- Syntax:

return_type function_name(parameter_list);

Example:

int add(int a, int b);

2. Definition:

- Contains the actual implementation of the function.

- Syntax:

return_type function_name(parameter_list) {

// Function body

return value;

Example:

int add(int a, int b) {

return a + b;

3. Calling a Function:

- A function is called to execute its code.


- Syntax:

function_name(argument_list);

Example:

int result = add(5, 3);

3. Class

- A class is a user-defined data type that acts as a blueprint for objects.

- It contains:

- Attributes (data members): Variables to store data.

- Methods (member functions): Functions to operate on data members.

Syntax:

class ClassName {

public:

// Public data members and member functions

private:

// Private data members and member functions

};

Example:

class Car {

public:

string brand;

void display() {

cout << "Brand: " << brand << endl;

};
4. Object

- An object is an instance of a class.

- It is created to access the attributes and methods of the class.

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.

- Arrays are indexed starting from 0.

Syntax:

data_type array_name[size];

Example:

int arr[5] = {1, 2, 3, 4, 5};

Key Points:

- Fixed size.

- Access elements using index: arr[0].

6. 2D Array

- A 2D array is an array of arrays, representing data in rows and columns.


Syntax:

data_type array_name[rows][columns];

Example:

int matrix[3][3] = {

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

};

Key Points:

- Access elements using two indices: matrix[row][column].

7. String

- A string is a sequence of characters.

- In C++, strings can be implemented using:

1. Character Arrays:

char str[10] = "Hello";

2. String Class (std::string):

#include <string>

string s = "Hello";

String Operations (String Class):

- Concatenation: s1 + s2

- Length: s.length()

- Substring: s.substr(start, length)

You might also like