Professional Documents
Culture Documents
C++ Test Notes Lesson 1
C++ Test Notes Lesson 1
C++ Test Notes Lesson 1
INTRODUCTION TO OOPS
2 MARKS QUESTION/ANSWERS:
ਪ੍ਰਕਿਰਿਆਵਾਂ ਜਾਂ ਫੰ ਕਸ਼ਨਾਂ ਨੂੰ ਲਿਖਣ ਬਾਰੇ ਹੈ ਜੋ ਡੇਟਾ 'ਤੇ ਸੰ ਚਾਲਨ ਕਰਦੇ ਹਨ, ਜਦੋਂ ਕਿ
• OOP C++ ਕੋਡ ਨੂੰ DRY "ਆਪਣੇ ਆਪ ਨੂੰ ਨਾ ਦੁਹਰਾਓ" ਰੱ ਖਣ ਵਿੱ ਚ ਮਦਦ ਕਰਦਾ ਹੈ, ਅਤੇ
ਕੋਡ ਨੂੰ ਬਣਾਈ ਰੱ ਖਣ, ਸੋਧਣ ਅਤੇ ਡੀਬੱ ਗ ਕਰਨਾ ਆਸਾਨ ਬਣਾਉਂਦਾ ਹੈ।
• OOP ਘੱ ਟ ਕੋਡ ਅਤੇ ਘੱ ਟ ਵਿਕਾਸ ਸਮੇਂ ਦੇ ਨਾਲ ਪੂਰੀ ਮੁੜ ਵਰਤੋਂ ਯੋਗ ਐਪਲੀਕੇਸ਼ਨ ਬਣਾਉਣਾ
ਸੰ ਭਵ ਬਣਾਉਂਦਾ ਹੈ
C++ gives programmers a high level of control over system resources and
memory.
The language was updated 4 major times in 2011, 2014, 2017, and 2020 to C+
+11, C++14, C++17, C++20.
C++ ਨੂੰ Bjarne Stroustrup ਦੁਆਰਾ C ਭਾਸ਼ਾ ਦੇ ਐਕਸਟੈਂਸ਼ਨ ਵਜੋਂ ਵਿਕਸਤ ਕੀਤਾ ਗਿਆ ਸੀ।
C++ ਪ੍ਰੋਗਰਾਮਰਾਂ ਨੂੰ ਸਿਸਟਮ ਸਰੋਤਾਂ ਅਤੇ ਮੈਮੋਰੀ ਉੱਤੇ ਉੱਚ ਪੱ ਧਰ ਦਾ ਨਿਯੰ ਤਰਣ ਦਿੰ ਦਾ ਹੈ।
ਭਾਸ਼ਾ ਨੂੰ 2011, 2014, 2017, ਅਤੇ 2020 ਵਿੱ ਚ C++11, C++14, C++17, C++20 ਵਿੱ ਚ 4 ਮੁੱ ਖ
ਵਾਰ ਅੱ ਪਡੇਟ ਕੀਤਾ ਗਿਆ ਸੀ।
C++ is portable and can be used to develop applications that can be adapted to
multiple platforms.
ANS: C++ ਦੁਨੀਆ ਦੀਆਂ ਸਭ ਤੋਂ ਪ੍ਰਸਿੱ ਧ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਭਾਸ਼ਾਵਾਂ ਵਿੱ ਚੋਂ ਇੱ ਕ ਹੈ।
C++ ਅੱ ਜ ਦੇ ਓਪਰੇਟਿੰ ਗ ਸਿਸਟਮਾਂ, ਗ੍ਰਾਫਿਕਲ ਯੂਜ਼ਰ ਇੰ ਟਰਫੇਸ, ਅਤੇ ਏਮਬੈਡਡ ਸਿਸਟਮਾਂ ਵਿੱ ਚ
ਪਾਇਆ ਜਾ ਸਕਦਾ ਹੈ।
C++ ਪੋਰਟੇਬਲ ਹੈ ਅਤੇ ਇਸਦੀ ਵਰਤੋਂ ਉਹਨਾਂ ਐਪਲੀਕੇਸ਼ਨਾਂ ਨੂੰ ਵਿਕਸਤ ਕਰਨ ਲਈ ਕੀਤੀ ਜਾ
ਸਕਦੀ ਹੈ ਜਿਨ੍ਹਾਂ ਨੂੰ ਕਈ ਪਲੇਟਫਾਰਮਾਂ ਲਈ ਅਨੁਕੂਲ ਬਣਾਇਆ ਜਾ ਸਕਦਾ ਹੈ।
ਜਿਵੇਂ ਕਿ C++ C, C# ਅਤੇ Java ਦੇ ਨੇ ੜੇ ਹੈ, ਇਹ ਪ੍ਰੋਗਰਾਮਰਾਂ ਲਈ C++ ਜਾਂ ਇਸਦੇ ਉਲਟ
ਬਦਲਣਾ ਆਸਾਨ ਬਣਾਉਂਦਾ ਹੈ।
ANS:
C C++
Virtual and friend functions are not Virtual and friend functions are
supported by C. supported by C++.
C
C++ provides new operator for
provides malloc() and calloc() functio
memory allocation and delete
ns for dynamic memory allocation,
operator for memory de-allocation.
and free() for memory de-allocation.
scanf() and printf() functions are cin and cout are used
used for input/output in C. for input/output in C++.
Named initializers may appear out of Named initializers must match the
order data layout of the struct
Meta-programming: templates
Meta-programming: macros +
(macros are still supported but
_Generic()
discouraged)
C ਨੂੰ ਡੇਨਿਸ ਰਿਚੀ ਦੁਆਰਾ ਸਾਲ 1969 ਅਤੇ C++ ਨੂੰ 1979 ਵਿੱ ਚ ਬਜਾਰਨ ਸਟ੍ਰੌਸਟ੍ਰਪ
1973 ਦੇ ਵਿਚਕਾਰ AT&T ਬੈੱਲ ਲੈਬਜ਼ ਵਿੱ ਚ ਦੁਆਰਾ ਵਿਕਸਤ ਕੀਤਾ ਗਿਆ ਸੀ।
ਵਿਕਸਤ ਕੀਤਾ ਗਿਆ ਸੀ।
C ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਭਾਸ਼ਾ ਵਿੱ ਚ ਕੋਈ ਸਖਤ । C++ ਵਿੱ ਚ ਸਖਤ ਕਿਸਮ ਦੀ ਜਾਂਚ ਕੀਤੀ
ਕਿਸਮ ਦੀ ਜਾਂਚ ਨਹੀਂ ਹੈ ਗਈ।
ਚਾਹੀਦੇ ਹਨ
ਪਰਿਭਾਸ਼ਿਤ ਵਿਵਹਾਰ ਹੈ (ਬਹੁਤ ਖਾਸ
ਸਥਿਤੀਆਂ ਨੂੰ ਛੱ ਡ ਕੇ)
ANS:
Both the languages have a similar syntax.
Code structure of both the languages are same.
The compilation of both the languages is similar.
They share the same basic syntax. Nearly all of C’s operators and keywords
are also present in C++ and do the same thing.
C++ has a slightly extended grammar than C, but the basic grammar is the
same.
Basic memory model of both is very close to the hardware.
Same notions of stack, heap, file-scope and static variables are present in
both the languages.
• ਉਹ ਇੱ ਕੋ ਜਿਹੇ ਮੂਲ ਸੰ ਟੈਕਸ ਨੂੰ ਸਾਂਝਾ ਕਰਦੇ ਹਨ। C ਦੇ ਲਗਭਗ ਸਾਰੇ ਆਪਰੇਟਰ ਅਤੇ
ਕੀਵਰਡ ਵੀ C++ ਵਿੱ ਚ ਮੌਜੂਦ ਹਨ ਅਤੇ ਉਹੀ ਕੰ ਮ ਕਰਦੇ ਹਨ।
• C++ ਦਾ C ਨਾਲੋਂ ਥੋੜ੍ਹਾ ਜਿਹਾ ਵਿਸਤ੍ਰਿਤ ਵਿਆਕਰਣ ਹੈ, ਪਰ ਮੂਲ ਵਿਆਕਰਣ ਉਹੀ ਹੈ।
• ਸਟੈਕ, ਹੀਪ, ਫਾਈਲ-ਸਕੋਪ ਅਤੇ ਸਟੈਟਿਕ ਵੇਰੀਏਬਲਾਂ ਦੀਆਂ ਇੱ ਕੋ ਜਿਹੀਆਂ ਧਾਰਨਾਵਾਂ ਦੋਵਾਂ
ਭਾਸ਼ਾਵਾਂ ਵਿੱ ਚ ਮੌਜੂਦ ਹਨ।
class
Fruit
int main() {
cout << "Hello World!";
return 0;
}
Explaination:
Line 1: #include <iostream> is a header file library that lets us work with input
and output objects, such as cout (used in line 5). Header files add functionality
to C++ programs.
Line 2: using namespace std means that we can use names for objects and
variables from the standard library.
Don't worry if you don't understand how #include <iostream> and using
namespace std works. Just think of it as something that (almost) always
appears in your program.
Line 3: A blank line. C++ ignores white space. But we use it to make the code
more readable.
Line 4: Another thing that always appear in a C++ program, is int main(). This is
called a function. Any code inside its curly brackets {} will be executed.
Note: The body of int main() could also been written as:
int main () { cout << "Hello World! "; return 0; }
Remember: The compiler ignores white spaces. However, multiple lines makes
the code more readable.
ਅਤੇ ਆਉਟਪੁੱ ਟ ਵਸਤੂਆਂ, ਜਿਵੇਂ ਕਿ cout (ਲਾਈਨ 5 ਵਿੱ ਚ ਵਰਤੀ ਜਾਂਦੀ ਹੈ) ਨਾਲ ਕੰ ਮ
ਕਰਨ ਦਿੰ ਦੀ ਹੈ। ਹੈਡਰ ਫਾਈਲਾਂ C++ ਪ੍ਰੋਗਰਾਮਾਂ ਵਿੱ ਚ ਕਾਰਜਸ਼ੀਲਤਾ ਜੋੜਦੀਆਂ ਹਨ।
ਲਾਈਨ 2: ਨੇ ਮਸਪੇਸ std ਦੀ ਵਰਤੋਂ ਕਰਨ ਦਾ ਮਤਲਬ ਹੈ ਕਿ ਅਸੀਂ ਸਟੈਂਡਰਡ ਲਾਇਬ੍ਰੇਰੀ ਤੋਂ
namespace std ਦੀ ਵਰਤੋਂ ਕਰਨਾ ਕਿਵੇਂ ਕੰ ਮ ਕਰਦਾ ਹੈ। ਬਸ ਇਸ ਨੂੰ ਕੁਝ ਅਜਿਹਾ ਸਮਝੋ
ਲਾਈਨ 4: ਇੱ ਕ ਹੋਰ ਚੀਜ਼ ਜੋ ਹਮੇਸ਼ਾ ਇੱ ਕ C++ ਪ੍ਰੋਗਰਾਮ ਵਿੱ ਚ ਦਿਖਾਈ ਦਿੰ ਦੀ ਹੈ, int
main() ਹੈ। ਇਸ ਨੂੰ ਫੰ ਕਸ਼ਨ ਕਿਹਾ ਜਾਂਦਾ ਹੈ। ਇਸਦੇ ਕਰਲੀ ਬਰੈਕਟਾਂ ਦੇ ਅੰ ਦਰ ਕੋਈ ਵੀ
ਨਾਲ ਆਉਟਪੁੱ ਟ/ਪ੍ਰਿੰ ਟ ਟੈਕਸਟ ਲਈ ਵਰਤੀ ਜਾਂਦੀ ਹੈ। ਸਾਡੇ ਉਦਾਹਰਣ ਵਿੱ ਚ ਇਹ "ਹੈਲੋ
ਯਾਦ ਰੱ ਖੋ: ਕੰ ਪਾਈਲਰ ਵਾਈਟ ਸਪੇਸ ਨੂੰ ਨਜ਼ਰਅੰ ਦਾਜ਼ ਕਰਦਾ ਹੈ। ਹਾਲਾਂਕਿ, ਕਈ ਲਾਈਨਾਂ
ANS: Comments can be used to explain C++ code, and to make it more
readable. It can also be used to prevent execution when testing alternative
code. Comments can be singled-lined or multi-lined
1. Single-line Comments
Any text between // and the end of the line is ignored by the compiler (will not
be executed).
This example uses a single-line comment before a line of code:
Example
// This is a comment
cout << "Hello World!";
Example
cout << "Hello World!"; // This is a comment
Example
/* The code below will print the words Hello World!
to the screen, and it is amazing */
cout << "Hello World!";
ANS: ਟਿੱ ਪਣੀਆਂ ਦੀ ਵਰਤੋਂ C++ ਕੋਡ ਦੀ ਵਿਆਖਿਆ ਕਰਨ ਅਤੇ ਇਸਨੂੰ ਹੋਰ ਪੜ੍ਹਨਯੋਗ
ਬਣਾਉਣ ਲਈ ਕੀਤੀ ਜਾ ਸਕਦੀ ਹੈ। ਵਿਕਲਪਕ ਕੋਡ ਦੀ ਜਾਂਚ ਕਰਦੇ ਸਮੇਂ ਇਸਦੀ ਵਰਤੋਂ
ਐਗਜ਼ੀਕਿਊਸ਼ਨ ਨੂੰ ਰੋਕਣ ਲਈ ਵੀ ਕੀਤੀ ਜਾ ਸਕਦੀ ਹੈ। ਟਿੱ ਪਣੀਆਂ ਸਿੰ ਗਲ-ਲਾਈਨਡ ਜਾਂ
ਮਲਟੀ-ਲਾਈਨਡ ਹੋ ਸਕਦੀਆਂ ਹਨ
ਸਿੰ ਗਲ-ਲਾਈਨ ਟਿੱ ਪਣੀਆਂ ਦੋ ਫਾਰਵਰਡ ਸਲੈਸ਼ਾਂ (//) ਨਾਲ ਸ਼ੁਰੂ ਹੁੰ ਦੀਆਂ ਹਨ।
ਕਰਦੀ ਹੈ:
ਉਦਾਹਰਨ
// ਇਹ ਇੱ ਕ ਟਿੱ ਪਣੀ ਹੈ
ਕਰਦੀ ਹੈ:
ਉਦਾਹਰਨ
_____________________________________________
ਮਲਟੀ-ਲਾਈਨ ਟਿੱ ਪਣੀਆਂ /* ਨਾਲ ਸ਼ੁਰੂ ਹੁੰ ਦੀਆਂ ਹਨ ਅਤੇ */ ਨਾਲ ਖਤਮ ਹੁੰ ਦੀਆਂ ਹਨ।
ਉਦਾਹਰਨ
In C++, there are different types of variables (defined with different keywords),
for example:
int - stores integers (whole numbers), without decimals, such as 123 or -
123
double - stores floating point numbers, with decimals, such as 19.99 or -
19.99
char - stores single characters, such as 'a' or 'B'. Char values are
surrounded by single quotes
string - stores text, such as "Hello World". String values are surrounded
by double quotes
bool - stores values with two states: true or false
ANS: ਵੇਰੀਏਬਲ ਡੇਟਾ ਮੁੱ ਲਾਂ ਨੂੰ ਸਟੋਰ ਕਰਨ ਲਈ ਕੰ ਟੇਨਰ ਹੁੰ ਦੇ ਹਨ।
C++ ਵਿੱ ਚ, ਵੱ ਖ-ਵੱ ਖ ਕਿਸਮਾਂ ਦੇ ਵੇਰੀਏਬਲ ਹਨ (ਵੱ ਖ-ਵੱ ਖ ਕੀਵਰਡਸ ਨਾਲ ਪਰਿਭਾਸ਼ਿਤ),
ਉਦਾਹਰਨ ਲਈ:
• int - ਦਸ਼ਮਲਵ ਤੋਂ ਬਿਨਾਂ ਪੂਰਨ ਅੰ ਕ (ਪੂਰੀਆਂ ਸੰ ਖਿਆਵਾਂ) ਸਟੋਰ ਕਰਦਾ ਹੈ, ਜਿਵੇਂ ਕਿ 123 ਜਾਂ
-123
• ਡਬਲ - ਫਲੋਟਿੰ ਗ ਪੁਆਇੰ ਟ ਨੰ ਬਰ ਸਟੋਰ ਕਰਦਾ ਹੈ, ਦਸ਼ਮਲਵ ਦੇ ਨਾਲ, ਜਿਵੇਂ ਕਿ 19.99 ਜਾਂ
-19.99
• char - ਸਿੰ ਗਲ ਅੱ ਖਰ ਸਟੋਰ ਕਰਦਾ ਹੈ, ਜਿਵੇਂ ਕਿ 'a' ਜਾਂ 'B'। ਚਾਰ ਮੁੱ ਲ ਸਿੰ ਗਲ ਕੋਟਸ ਨਾਲ
ਘਿਰੇ ਹੋਏ ਹਨ
• ਸਤਰ - ਸਟੋਰ ਟੈਕਸਟ, ਜਿਵੇਂ ਕਿ "ਹੈਲੋ ਵਰਲਡ"। ਸਟ੍ਰਿੰ ਗ ਮੁੱ ਲ ਡਬਲ ਕੋਟਸ ਨਾਲ ਘਿਰੇ ਹੋਏ
ਹਨ
• bool - ਮੁੱ ਲਾਂ ਨੂੰ ਦੋ ਅਵਸਥਾਵਾਂ ਨਾਲ ਸਟੋਰ ਕਰਦਾ ਹੈ: ਸਹੀ ਜਾਂ ਗਲਤ
Q.11 C++ Basic Syntax ? (2 MARKS / 10 MARKS)
1. Header File
The header files contain the definition of the functions and macros we are
using in our program. They are defined on the top of the C++ program.
In line #1, we used the #include <iostream> statement to tell the compiler to
include an iostream header file library which stores the definition of the cin
and cout methods that we have used for input and output. #include is a
preprocessor directive using which we import header files.
1. ਹੈਡਰ ਫਾਈਲ
ਹੈਡਰ ਫਾਈਲਾਂ ਵਿੱ ਚ ਫੰ ਕਸ਼ਨਾਂ ਅਤੇ ਮੈਕਰੋ ਦੀ ਪਰਿਭਾਸ਼ਾ ਹੁੰ ਦੀ ਹੈ ਜੋ ਅਸੀਂ ਆਪਣੇ ਪ੍ਰੋਗਰਾਮ
ਵਿੱ ਚ ਵਰਤ ਰਹੇ ਹਾਂ। ਉਹਨਾਂ ਨੂੰ C++ ਪ੍ਰੋਗਰਾਮ ਦੇ ਸਿਖਰ 'ਤੇ ਪਰਿਭਾਸ਼ਿਤ ਕੀਤਾ ਗਿਆ ਹੈ।
ਲਾਈਨ #1 ਵਿੱ ਚ, ਅਸੀਂ ਕੰ ਪਾਈਲਰ ਨੂੰ ਇੱ ਕ iostream ਹੈਡਰ ਫਾਈਲ ਲਾਇਬ੍ਰੇਰੀ ਨੂੰ ਸ਼ਾਮਲ
ਅਤੇ cout ਵਿਧੀਆਂ ਦੀ ਪਰਿਭਾਸ਼ਾ ਨੂੰ ਸਟੋਰ ਕਰਦੀ ਹੈ ਜੋ ਅਸੀਂ ਇਨਪੁਟ ਅਤੇ ਆਉਟਪੁੱ ਟ
C++ ਵਿੱ ਚ ਇੱ ਕ ਨੇ ਮਸਪੇਸ ਦੀ ਵਰਤੋਂ ਇੱ ਕ ਸਕੋਪ ਜਾਂ ਇੱ ਕ ਖੇਤਰ ਪ੍ਰਦਾਨ ਕਰਨ ਲਈ ਕੀਤੀ
ਜਾਂਦੀ ਹੈ ਜਿੱ ਥੇ ਅਸੀਂ ਪਛਾਣਕਰਤਾਵਾਂ ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦੇ ਹਾਂ। ਇਸਦੀ ਵਰਤੋਂ ਦੋ
ਪਛਾਣਕਰਤਾਵਾਂ ਵਿਚਕਾਰ ਨਾਮ ਦੇ ਟਕਰਾਅ ਤੋਂ ਬਚਣ ਲਈ ਕੀਤੀ ਜਾਂਦੀ ਹੈ ਕਿਉਂਕਿ ਸਿਰਫ
ਵਿਲੱ ਖਣ ਨਾਮ ਪਛਾਣਕਰਤਾਵਾਂ ਵਜੋਂ ਵਰਤੇ ਜਾ ਸਕਦੇ ਹਨ।
ਸੰ ਟੈਕਸ:
3. Main Function
Functions are basic building blocks of a C++ program that contains the
instructions for performing some specific task. Apart from the instructions
present in its body, a function definition also contains information about its
return type and parameters. To know more about C++ functions, please refer
to the article Functions in C++.
In line #3, we defined the main function as int main(). The main function is
the most important part of any C++ program. The program execution always
starts from the main function. All the other functions are called from the
main function. In C++, the main function is required to return some value
indicating the execution status.
Syntax:
int main() {
... code ....
return 0;
}
3. ਮੁੱ ਖ ਫੰ ਕਸ਼ਨ
ਫੰ ਕਸ਼ਨ ਇੱ ਕ C++ ਪ੍ਰੋਗਰਾਮ ਦੇ ਬੁਨਿਆਦੀ ਬਿਲਡਿੰ ਗ ਬਲਾਕ ਹੁੰ ਦੇ ਹਨ ਜਿਸ ਵਿੱ ਚ ਕੁਝ ਖਾਸ
ਕੰ ਮ ਕਰਨ ਲਈ ਹਦਾਇਤਾਂ ਹੁੰ ਦੀਆਂ ਹਨ। ਇਸਦੇ ਸਰੀਰ ਵਿੱ ਚ ਮੌਜੂਦ ਨਿਰਦੇਸ਼ਾਂ ਤੋਂ ਇਲਾਵਾ,
ਇੱ ਕ ਫੰ ਕਸ਼ਨ ਪਰਿਭਾਸ਼ਾ ਵਿੱ ਚ ਇਸਦੇ ਵਾਪਸੀ ਦੀ ਕਿਸਮ ਅਤੇ ਮਾਪਦੰ ਡਾਂ ਬਾਰੇ ਵੀ ਜਾਣਕਾਰੀ
ਹੁੰ ਦੀ ਹੈ। C++ ਫੰ ਕਸ਼ਨਾਂ ਬਾਰੇ ਹੋਰ ਜਾਣਨ ਲਈ, ਕਿਰਪਾ ਕਰਕੇ C++ ਵਿੱ ਚ ਫੰ ਕਸ਼ਨ ਲੇਖ ਵੇਖੋ।
ਲਾਈਨ #3 ਵਿੱ ਚ, ਅਸੀਂ ਮੁੱ ਖ ਫੰ ਕਸ਼ਨ ਨੂੰ int main() ਵਜੋਂ ਪਰਿਭਾਸ਼ਿਤ ਕੀਤਾ ਹੈ। ਮੁੱ ਖ ਫੰ ਕਸ਼ਨ
ਕਿਸੇ ਵੀ C++ ਪ੍ਰੋਗਰਾਮ ਦਾ ਸਭ ਤੋਂ ਮਹੱ ਤਵਪੂਰਨ ਹਿੱ ਸਾ ਹੁੰ ਦਾ ਹੈ। ਪ੍ਰੋਗਰਾਮ ਐਗਜ਼ੀਕਿਊਸ਼ਨ
ਹਮੇਸ਼ਾ ਮੇਨ ਫੰ ਕਸ਼ਨ ਤੋਂ ਸ਼ੁਰੂ ਹੁੰ ਦਾ ਹੈ। ਬਾਕੀ ਸਾਰੇ ਫੰ ਕਸ਼ਨਾਂ ਨੂੰ ਮੇਨ ਫੰ ਕਸ਼ਨ ਤੋਂ ਬੁਲਾਇਆ
ਜਾਂਦਾ ਹੈ। C++ ਵਿੱ ਚ, ਮੁੱ ਖ ਫੰ ਕਸ਼ਨ ਨੂੰ ਐਗਜ਼ੀਕਿਊਸ਼ਨ ਸਥਿਤੀ ਨੂੰ ਦਰਸਾਉਂਦੇ ਹੋਏ ਕੁਝ ਮੁੱ ਲ
ਵਾਪਸ ਕਰਨ ਦੀ ਲੋੜ ਹੁੰ ਦੀ ਹੈ।
ਸੰ ਟੈਕਸ:
int main() {
... ਕੋਡ...
ਵਾਪਸੀ 0;
}
4. Blocks
Blocks are the group of statements that are enclosed within { } braces. They
define the scope of the identifiers and are generally used to enclose the body
of functions and control statements.
The body of the main function is from line #4 to line #9 enclosed within { }.
Syntax:
{
return 0;
}
4. ਬਲਾਕ
ਬਲਾਕ ਕਥਨਾਂ ਦਾ ਸਮੂਹ ਹੈ ਜੋ ਕਿ { } ਬਰੇਸ ਦੇ ਅੰ ਦਰ ਬੰ ਦ ਹਨ। ਉਹ ਪਛਾਣਕਰਤਾਵਾਂ ਦੇ
ਦਾਇਰੇ ਨੂੰ ਪਰਿਭਾਸ਼ਿਤ ਕਰਦੇ ਹਨ ਅਤੇ ਆਮ ਤੌਰ 'ਤੇ ਫੰ ਕਸ਼ਨਾਂ ਅਤੇ ਨਿਯੰ ਤਰਣ ਸਟੇਟਮੈਂਟਾਂ ਦੇ
ਸਰੀਰ ਨੂੰ ਨੱ ਥੀ ਕਰਨ ਲਈ ਵਰਤੇ ਜਾਂਦੇ ਹਨ।
ਮੁੱ ਖ ਫੰ ਕਸ਼ਨ ਦਾ ਮੁੱ ਖ ਭਾਗ ਲਾਈਨ #4 ਤੋਂ ਲਾਈਨ #9 ਤੱ ਕ { } ਦੇ ਅੰ ਦਰ ਬੰ ਦ ਹੈ।
ਸੰ ਟੈਕਸ:
{
// ਫੰ ਕਸ਼ਨ ਦਾ ਸਰੀਰ
ਵਾਪਸੀ 0;
}
5. Semicolons
As you may have noticed by now, each statement in the above code is
followed by a ( ; ) semicolon symbol. It is used to terminate each line of the
statement of the program. When the compiler sees this semicolon, it
terminates the operation of that line and moves to the next line.
Syntax:
any_statement ;
5. ਸੈਮੀਕੋਲਨ
ਜਿਵੇਂ ਕਿ ਤੁਸੀਂ ਹੁਣ ਤੱ ਕ ਨੋ ਟ ਕੀਤਾ ਹੋਵੇਗਾ, ਉਪਰੋਕਤ ਕੋਡ ਵਿੱ ਚ ਹਰੇਕ ਕਥਨ ਦੇ ਬਾਅਦ ਇੱ ਕ
(;) ਸੈਮੀਕੋਲਨ ਚਿੰ ਨ੍ਹ ਹੁੰ ਦਾ ਹੈ। ਇਹ ਪ੍ਰੋਗਰਾਮ ਦੇ ਸਟੇਟਮੈਂਟ ਦੀ ਹਰੇਕ ਲਾਈਨ ਨੂੰ ਖਤਮ ਕਰਨ
ਲਈ ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ। ਜਦੋਂ ਕੰ ਪਾਈਲਰ ਇਸ ਸੈਮੀਕੋਲਨ ਨੂੰ ਵੇਖਦਾ ਹੈ, ਤਾਂ ਇਹ ਉਸ ਲਾਈਨ
ਦੀ ਕਾਰਵਾਈ ਨੂੰ ਖਤਮ ਕਰ ਦਿੰ ਦਾ ਹੈ ਅਤੇ ਅਗਲੀ ਲਾਈਨ 'ਤੇ ਚਲਾ ਜਾਂਦਾ ਹੈ।
ਸੰ ਟੈਕਸ:
any_statement
6. Identifiers
We use identifiers for the naming of variables, functions, and other user-
defined data types. An identifier may consist of uppercase and lowercase
alphabetical characters, underscore, and digits. The first letter must be an
underscore or an alphabet.
Example:
int num1 = 24;
int num2 = 34;
num1 & num2 are the identifiers and int is the data type.
6. ਪਛਾਣਕਰਤਾ
ਅਸੀਂ ਵੇਰੀਏਬਲਾਂ, ਫੰ ਕਸ਼ਨਾਂ, ਅਤੇ ਹੋਰ ਉਪਭੋਗਤਾ ਦੁਆਰਾ ਪਰਿਭਾਸ਼ਿਤ ਡੇਟਾ ਕਿਸਮਾਂ ਦੇ
ਨਾਮਕਰਨ ਲਈ ਪਛਾਣਕਰਤਾਵਾਂ ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਹਾਂ। ਇੱ ਕ ਪਛਾਣਕਰਤਾ ਵਿੱ ਚ ਵੱ ਡੇ ਅਤੇ ਛੋਟੇ
ਅੱ ਖਰ ਅੱ ਖਰ, ਅੰ ਡਰਸਕੋਰ ਅਤੇ ਅੰ ਕ ਸ਼ਾਮਲ ਹੋ ਸਕਦੇ ਹਨ। ਪਹਿਲਾ ਅੱ ਖਰ ਇੱ ਕ ਅੰ ਡਰਸਕੋਰ
ਜਾਂ ਇੱ ਕ ਵਰਣਮਾਲਾ ਹੋਣਾ ਚਾਹੀਦਾ ਹੈ।
ਉਦਾਹਰਨ:
7. Keywords
In the C++ programming language, there are some reserved words that are
used for some special meaning in the C++ program. It can’t be used for
identifiers.
For example, the words int, return, and using are some keywords used in our
program. These all have some predefined meaning in the C++ language.
There are total 95 keywords in C++. These are some keywords.
int void if while for auto bool break
7. ਕੀਵਰਡਸ
C++ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਭਾਸ਼ਾ ਵਿੱ ਚ, ਕੁਝ ਰਾਖਵੇਂ ਸ਼ਬਦ ਹਨ ਜੋ C++ ਪ੍ਰੋਗਰਾਮ ਵਿੱ ਚ ਕੁਝ ਖਾਸ ਅਰਥਾਂ
ਲਈ ਵਰਤੇ ਜਾਂਦੇ ਹਨ। ਇਸਦੀ ਵਰਤੋਂ ਪਛਾਣਕਰਤਾਵਾਂ ਲਈ ਨਹੀਂ ਕੀਤੀ ਜਾ ਸਕਦੀ।
ਉਦਾਹਰਨ ਲਈ, int, return, ਅਤੇ using ਸ਼ਬਦ ਸਾਡੇ ਪ੍ਰੋਗਰਾਮ ਵਿੱ ਚ ਵਰਤੇ ਗਏ ਕੁਝ
ਕੀਵਰਡ ਹਨ। ਇਹਨਾਂ ਸਾਰਿਆਂ ਦੇ C++ ਭਾਸ਼ਾ ਵਿੱ ਚ ਕੁਝ ਪਹਿਲਾਂ ਤੋਂ ਪਰਿਭਾਸ਼ਿਤ ਅਰਥ ਹਨ।
In line #7, we have used the cout method which is the basic output method in
C++ to output the sum of two numbers in the standard output stream
(stdout).
Syntax:
cout << result << endl;
8. ਬੇਸਿਕ ਆਉਟਪੁੱ ਟ ਕਾਉਟ
ਲਾਈਨ #7 ਵਿੱ ਚ, ਅਸੀਂ ਸਟੈਂਡਰਡ ਆਉਟਪੁੱ ਟ ਸਟ੍ਰੀਮ (stdout) ਵਿੱ ਚ ਦੋ ਸੰ ਖਿਆਵਾਂ ਦੇ ਜੋੜ
ਨੂੰ ਆਊਟਪੁੱ ਟ ਕਰਨ ਲਈ C++ ਵਿੱ ਚ ਮੂਲ ਆਉਟਪੁੱ ਟ ਵਿਧੀ ਦੀ ਵਰਤੋਂ ਕੀਤੀ ਹੈ।
ਸੰ ਟੈਕਸ:
10 MARKS Q/A:
ANS: C++ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਦਾ ਮੁੱ ਖ ਉਦੇਸ਼ ਸੀ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਭਾਸ਼ਾ ਵਿੱ ਚ ਆਬਜੈਕਟ ਓਰੀਐਂਟੇਸ਼ਨ ਦੀ
ਧਾਰਨਾ ਨੂੰ ਪੇਸ਼ ਕਰਨਾ ਹੈ।
Object means a real word entity such as pen, chair, table etc. Object-Oriented
Programming is a methodology or paradigm to design a program using classes
and objects. It simplifies the software development and maintenance by
providing some concepts:
ਆਬਜੈਕਟ ਦਾ ਅਰਥ ਹੈ ਅਸਲ ਸ਼ਬਦ ਦੀ ਹਸਤੀ ਜਿਵੇਂ ਕਿ ਪੈੱਨ, ਕੁਰਸੀ, ਮੇਜ਼ ਆਦਿ।
ਆਬਜੈਕਟ-ਓਰੀਐਂਟਡ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਕਲਾਸਾਂ ਅਤੇ ਵਸਤੂਆਂ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਇੱ ਕ ਪ੍ਰੋਗਰਾਮ ਨੂੰ
ਡਿਜ਼ਾਈਨ ਕਰਨ ਲਈ ਇੱ ਕ ਵਿਧੀ ਜਾਂ ਪੈਰਾਡਾਈਮ ਹੈ। ਇਹ ਕੁਝ ਸੰ ਕਲਪਾਂ ਪ੍ਰਦਾਨ ਕਰਕੇ
ਸਾਫਟਵੇਅਰ ਵਿਕਾਸ ਅਤੇ ਰੱ ਖ-ਰਖਾਅ ਨੂੰ ਸਰਲ ਬਣਾਉਂਦਾ ਹੈ:
o Object
o Class
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation
Object
Any entity that has state and behavior is known as an object. For example:
chair, pen, table, keyboard, bike etc. It can be physical and logical.
ਵਸਤੂ
ਕੋਈ ਵੀ ਇਕਾਈ ਜਿਸਦਾ ਰਾਜ ਅਤੇ ਵਿਵਹਾਰ ਹੁੰ ਦਾ ਹੈ ਨੂੰ ਇੱ ਕ ਵਸਤੂ ਵਜੋਂ ਜਾਣਿਆ ਜਾਂਦਾ ਹੈ।
ਉਦਾਹਰਨ ਲਈ: ਕੁਰਸੀ, ਪੈੱਨ, ਮੇਜ਼, ਕੀ-ਬੋਰਡ, ਸਾਈਕਲ ਆਦਿ। ਇਹ ਭੌਤਿਕ ਅਤੇ ਤਰਕਪੂਰਨ
ਹੋ ਸਕਦਾ ਹੈ।
Class
ਕਲਾਸ
ਵਸਤੂਆਂ ਦੇ ਸੰ ਗ੍ਰਹਿ ਨੂੰ ਕਲਾਸ ਕਿਹਾ ਜਾਂਦਾ ਹੈ। ਇਹ ਇੱ ਕ ਤਰਕਸ਼ੀਲ ਹਸਤੀ ਹੈ।
When one object acquires all the properties and behaviours of parent
object i.e. known as inheritance. It provides code reusability. It is used to
achieve runtime polymorphism.
ਵਿਰਾਸਤ
ਜਦੋਂ ਇੱ ਕ ਵਸਤੂ ਮੂਲ ਵਸਤੂ ਦੀਆਂ ਸਾਰੀਆਂ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਅਤੇ ਵਿਹਾਰਾਂ ਨੂੰ ਗ੍ਰਹਿਣ ਕਰ
ਲੈਂਦੀ ਹੈ ਜਿਵੇਂ ਕਿ ਵਿਰਾਸਤ ਵਜੋਂ ਜਾਣਿਆ ਜਾਂਦਾ ਹੈ। ਇਹ ਕੋਡ ਦੀ ਮੁੜ ਵਰਤੋਂਯੋਗਤਾ
ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ। ਇਹ ਰਨਟਾਈਮ ਪੋਲੀਮੋਰਫਿਜ਼ਮ ਨੂੰ ਪ੍ਰਾਪਤ ਕਰਨ ਲਈ ਵਰਤਿਆ
ਜਾਂਦਾ ਹੈ।
2. ਸੁਪਰ ਕਲਾਸ - ਸ਼ਬਦ "ਬੇਸ ਕਲਾਸ" ਜਾਂ "ਸੁਪਰ ਕਲਾਸ" ਉਸ ਕਲਾਸ ਨੂੰ ਦਰਸਾਉਂਦਾ
ਹੈ ਜਿਸ ਤੋਂ ਉਪ-ਕਲਾਸ ਆਪਣੀਆਂ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਪ੍ਰਾਪਤ ਕਰਦਾ ਹੈ।
3. ਮੁੜ ਵਰਤੋਂਯੋਗਤਾ - ਨਤੀਜੇ ਵਜੋਂ, ਜਦੋਂ ਅਸੀਂ ਇੱ ਕ ਨਵੀਂ ਕਲਾਸ ਬਣਾਉਣਾ ਚਾਹੁੰ ਦੇ ਹਾਂ,
ਪਰ ਇੱ ਕ ਮੌਜੂਦਾ ਕਲਾਸ ਵਿੱ ਚ ਪਹਿਲਾਂ ਹੀ ਕੁਝ ਕੋਡ ਸ਼ਾਮਲ ਹੁੰ ਦਾ ਹੈ ਜਿਸਦੀ ਸਾਨੂੰ ਲੋੜ
ਹੁੰ ਦੀ ਹੈ, ਅਸੀਂ ਵਿਰਾਸਤ ਦੇ ਕਾਰਨ ਪੁਰਾਣੀ ਕਲਾਸ ਤੋਂ ਆਪਣੀ ਨਵੀਂ ਕਲਾਸ ਬਣਾ ਸਕਦੇ
ਹਾਂ। ਇਹ ਸਾਨੂੰ ਪਹਿਲਾਂ ਤੋਂ ਮੌਜੂਦ ਕਲਾਸ ਦੇ ਖੇਤਰਾਂ ਅਤੇ ਤਰੀਕਿਆਂ ਦੀ ਵਰਤੋਂ ਕਰਨ ਦੀ
ਇਜਾਜ਼ਤ ਦਿੰ ਦਾ ਹੈ।
Polymorphism
ਪੋਲੀਮੋਰਫਿਜ਼ਮ
ਜਦੋਂ ਇੱ ਕ ਕੰ ਮ ਨੂੰ ਵੱ ਖ-ਵੱ ਖ ਤਰੀਕਿਆਂ ਨਾਲ ਕੀਤਾ ਜਾਂਦਾ ਹੈ ਜਿਵੇਂ ਕਿ ਪੋਲੀਮੋਰਫਿਜ਼ਮ ਵਜੋਂ
ਜਾਣਿਆ ਜਾਂਦਾ ਹੈ। ਉਦਾਹਰਨ ਲਈ: ਗਾਹਕ ਨੂੰ ਵੱ ਖਰੇ ਢੰ ਗ ਨਾਲ ਯਕੀਨ ਦਿਵਾਉਣ ਲਈ, ਕੁਝ
ਵੱ ਖ-ਵੱ ਖ ਸਥਿਤੀਆਂ ਕਾਰਨ ਓਪਰੇਸ਼ਨ ਵੱ ਖਰੇ ਢੰ ਗ ਨਾਲ ਵਿਵਹਾਰ ਕਰ ਸਕਦਾ ਹੈ। ਓਪਰੇਸ਼ਨ
Abstraction
ਐਬਸਟਰੈਕਸ਼ਨ
ਅੰ ਦਰੂਨੀ ਵੇਰਵਿਆਂ ਨੂੰ ਲੁਕਾਉਣਾ ਅਤੇ ਕਾਰਜਕੁਸ਼ਲਤਾ ਦਿਖਾਉਣ ਨੂੰ ਐਬਸਟਰੈਕਸ਼ਨ ਵਜੋਂ
ਜਾਣਿਆ ਜਾਂਦਾ ਹੈ। ਡੇਟਾ ਐਬਸਟਰੈਕਸ਼ਨ ਸਿਰਫ ਉਹ ਜਾਣਕਾਰੀ ਨੂੰ ਬਾਹਰੀ ਸੰ ਸਾਰ ਦੇ ਸਾਹਮਣੇ
ਲਿਆਉਣ ਦੀ ਪ੍ਰਕਿਰਿਆ ਹੈ ਜੋ ਲਾਗੂ ਕਰਨ ਜਾਂ ਪਿਛੋਕੜ ਦੀ ਜਾਣਕਾਰੀ ਨੂੰ ਛੁਪਾਉਂਦੇ ਹੋਏ
ਬਿਲਕੁਲ ਜ਼ਰੂਰੀ ਹੈ। ਉਦਾਹਰਨ ਲਈ: ਫ਼ੋਨ ਕਾਲ, ਸਾਨੂੰ ਅੰ ਦਰੂਨੀ ਪ੍ਰਕਿਰਿਆ ਬਾਰੇ ਨਹੀਂ ਪਤਾ।
C++ ਵਿੱ ਚ, ਅਸੀਂ ਐਬਸਟਰੈਕਟ ਪ੍ਰਾਪਤ ਕਰਨ ਲਈ ਐਬਸਟਰੈਕਟ ਕਲਾਸ ਅਤੇ ਇੰ ਟਰਫੇਸ ਦੀ
ਵਰਤੋਂ ਕਰਦੇ ਹਾਂ
Encapsulation
Binding (or wrapping) code and data together into a single unit is known as
encapsulation. For example: capsule, it is wrapped with different medicines.
ਇਨਕੈਪਸੂਲੇਸ਼ਨ
ਬਾਈਡਿੰ ਗ (ਜਾਂ ਰੈਪਿੰ ਗ) ਕੋਡ ਅਤੇ ਡੇਟਾ ਨੂੰ ਇੱ ਕ ਸਿੰ ਗਲ ਯੂਨਿਟ ਵਿੱ ਚ ਇਕੱ ਠੇ ਕਰਨ ਨੂੰ
ਐਨਕੈਪਸੂਲੇਸ਼ਨ ਵਜੋਂ ਜਾਣਿਆ ਜਾਂਦਾ ਹੈ। ਉਦਾਹਰਨ ਲਈ: ਕੈਪਸੂਲ, ਇਸ ਨੂੰ ਵੱ ਖ-ਵੱ ਖ ਦਵਾਈਆਂ
ਨਾਲ ਲਪੇਟਿਆ ਜਾਂਦਾ ਹੈ।
ਇਨਕੈਪਸੂਲੇਸ਼ਨ ਨੂੰ ਆਮ ਤੌਰ 'ਤੇ ਇੱ ਕ ਇਕਾਈ ਵਿੱ ਚ ਜਾਣਕਾਰੀ ਅਤੇ ਡੇਟਾ ਦੇ ਸਬੰ ਧਤ
ਟੁਕੜਿਆਂ ਦੇ ਸਮੂਹ ਦੇ ਰੂਪ ਵਿੱ ਚ ਸਮਝਿਆ ਜਾਂਦਾ ਹੈ। ਐਨਕੈਪਸੂਲੇਸ਼ਨ ਡੇਟਾ ਅਤੇ ਫੰ ਕਸ਼ਨਾਂ ਨੂੰ
ਜੋੜਨ ਦੀ ਪ੍ਰਕਿਰਿਆ ਹੈ ਜੋ ਆਬਜੈਕਟ-ਓਰੀਐਂਟਡ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਵਿੱ ਚ ਇਸਦੇ ਨਾਲ ਕੰ ਮ ਕਰਦੇ
ਹਨ। ਇਨਕੈਪਸੂਲੇਸ਼ਨ ਦੇ ਇੱ ਕ ਵਿਹਾਰਕ ਦ੍ਰਿਸ਼ਟੀਕੋਣ 'ਤੇ ਇੱ ਕ ਨਜ਼ਰ ਮਾਰੋ: ਇੱ ਕ ਕੰ ਪਨੀ ਵਿੱ ਚ,
ਵਿਕਰੀ ਡਿਵੀਜ਼ਨ, ਵਿੱ ਤ ਡਿਵੀਜ਼ਨ, ਅਤੇ ਅਕਾਊਂਟਸ ਡਿਵੀਜ਼ਨ ਸਮੇਤ ਵੱ ਖ-ਵੱ ਖ ਡਿਵੀਜ਼ਨਾਂ ਹਨ।
ਸਾਰੇ ਵਿੱ ਤੀ ਲੈਣ-ਦੇਣ ਵਿੱ ਤ ਸੈਕਟਰ ਦੁਆਰਾ ਸੰ ਭਾਲੇ ਜਾਂਦੇ ਹਨ, ਜੋ ਸਾਰੇ ਵਿੱ ਤੀ ਡੇਟਾ ਦੇ ਰਿਕਾਰਡ
ਵੀ ਰੱ ਖਦਾ ਹੈ। ਇਸੇ ਤਰ੍ਹਾਂ, ਸੇਲਜ਼ ਸੈਕਸ਼ਨ ਵਿਕਰੀ ਨਾਲ ਸਬੰ ਧਤ ਸਾਰੇ ਕੰ ਮਾਂ ਦਾ ਇੰ ਚਾਰਜ ਹੁੰ ਦਾ
ਹੈ ਅਤੇ ਹਰੇਕ ਵਿਕਰੀ ਦਾ ਰਿਕਾਰਡ ਰੱ ਖਦਾ ਹੈ। ਹੁਣ, ਇੱ ਕ ਦ੍ਰਿਸ਼ ਉਦੋਂ ਵਾਪਰ ਸਕਦਾ ਹੈ ਜਦੋਂ,
ਕਿਸੇ ਕਾਰਨ ਕਰਕੇ, ਇੱ ਕ ਵਿੱ ਤੀ ਅਧਿਕਾਰੀ ਨੂੰ ਇੱ ਕ ਖਾਸ ਮਹੀਨੇ ਲਈ ਵਿਕਰੀ ਬਾਰੇ ਸਾਰੀ
ਜਾਣਕਾਰੀ ਦੀ ਲੋੜ ਹੁੰ ਦੀ ਹੈ। ਛਤਰੀ ਸ਼ਬਦ "ਸੇਲਜ਼ ਸੈਕਸ਼ਨ" ਦੇ ਤਹਿਤ, ਉਹ ਸਾਰੇ ਕਰਮਚਾਰੀ
ਜੋ ਸੇਲਜ਼ ਸੈਕਸ਼ਨ ਦੇ ਡੇਟਾ ਨੂੰ ਪ੍ਰਭਾਵਿਤ ਕਰ ਸਕਦੇ ਹਨ, ਨੂੰ ਇਕੱ ਠੇ ਗਰੁੱ ਪ ਕੀਤਾ ਗਿਆ ਹੈ।
ਡੇਟਾ ਐਬਸਟਰੈਕਸ਼ਨ ਜਾਂ ਛੁਪਾਉਣਾ ਇਨਕੈਪਸੂਲੇਸ਼ਨ ਦਾ ਇੱ ਕ ਹੋਰ ਮਾੜਾ ਪ੍ਰਭਾਵ ਹੈ। ਉਸੇ
ਤਰੀਕੇ ਨਾਲ ਜੋ ਐਨਕੈਪਸੂਲੇਸ਼ਨ ਡੇਟਾ ਨੂੰ ਲੁਕਾਉਂਦਾ ਹੈ. ਉਪਰੋਕਤ ਉਦਾਹਰਨ ਵਿੱ ਚ, ਕੋਈ ਵੀ
ਹੋਰ ਖੇਤਰ ਕਿਸੇ ਵੀ ਸੈਕਸ਼ਨ, ਜਿਵੇਂ ਕਿ ਵਿਕਰੀ, ਵਿੱ ਤ, ਜਾਂ ਖਾਤਿਆਂ ਦੇ ਕਿਸੇ ਵੀ ਡੇਟਾ ਤੱ ਕ ਪਹੁੰ ਚ
ਨਹੀਂ ਕਰ ਸਕਦਾ ਹੈ।
3. OOPs ਅਸਲ-ਸੰ ਸਾਰ ਘਟਨਾ ਨੂੰ ਵਧੇਰੇ ਪ੍ਰਭਾਵਸ਼ਾਲੀ ਢੰ ਗ ਨਾਲ ਨਕਲ ਕਰਨ ਦੀ
ਸਮਰੱ ਥਾ ਪ੍ਰਦਾਨ ਕਰਦੇ ਹਨ। ਅਸੀਂ ਅਸਲ ਸ਼ਬਦ ਸਮੱ ਸਿਆ ਦਾ ਹੱ ਲ ਪ੍ਰਦਾਨ ਕਰ ਸਕਦੇ
ਹਾਂ ਜੇਕਰ ਅਸੀਂ ਆਬਜੈਕਟ-ਓਰੀਐਂਟਡ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਭਾਸ਼ਾ ਦੀ ਵਰਤੋਂ ਕਰ ਰਹੇ ਹਾਂ
Q.3 Why do we need oops in C++?
With the use of classes and objects, object-oriented programming makes code
maintenance simple. Because inheritance allows for code reuse, the program is
simpler because you don't have to write the same code repeatedly. Data hiding
is also provided by ideas like encapsulation and abstraction.
ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਦੇ ਸ਼ੁਰੂਆਤੀ ਤਰੀਕਿਆਂ ਵਿੱ ਚ ਕਈ ਕਮੀਆਂ ਸਨ, ਨਾਲ ਹੀ ਮਾੜੀ ਕਾਰਗੁਜ਼ਾਰੀ ਵੀ।
ਪਹੁੰ ਚ ਅਸਲ-ਸੰ ਸਾਰ ਦੇ ਮੁੱ ਦਿਆਂ ਨੂੰ ਪ੍ਰਭਾਵਸ਼ਾਲੀ ਢੰ ਗ ਨਾਲ ਹੱ ਲ ਨਹੀਂ ਕਰ ਸਕੀ ਕਿਉਂਕਿ,
ਪ੍ਰਕਿਰਿਆ-ਅਧਾਰਿਤ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਦੇ ਸਮਾਨ, ਤੁਸੀਂ ਪ੍ਰੋਗਰਾਮ ਦੇ ਅੰ ਦਰ ਕੋਡ ਦੀ ਦੁਬਾਰਾ ਵਰਤੋਂ
ਨਹੀਂ ਕਰ ਸਕਦੇ, ਗਲੋਬਲ ਡਾਟਾ ਐਕਸੈਸ ਵਿੱ ਚ ਇੱ ਕ ਮੁਸ਼ਕਲ ਸੀ, ਆਦਿ।
ਕਲਾਸਾਂ ਅਤੇ ਆਬਜੈਕਟ ਦੀ ਵਰਤੋਂ ਨਾਲ, ਆਬਜੈਕਟ-ਓਰੀਐਂਟਡ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਕੋਡ ਮੇਨਟੇਨੈਂ ਸ ਨੂੰ
ਸਰਲ ਬਣਾਉਂਦੀ ਹੈ। ਕਿਉਂਕਿ ਵਿਰਾਸਤ ਕੋਡ ਦੀ ਮੁੜ ਵਰਤੋਂ ਦੀ ਆਗਿਆ ਦਿੰ ਦੀ ਹੈ, ਪ੍ਰੋਗਰਾਮ
ਸੌਖਾ ਹੈ ਕਿਉਂਕਿ ਤੁਹਾਨੂੰ ਉਹੀ ਕੋਡ ਵਾਰ-ਵਾਰ ਲਿਖਣ ਦੀ ਲੋੜ ਨਹੀਂ ਹੈ। ਇਨਕੈਪਸੂਲੇਸ਼ਨ ਅਤੇ
ਐਬਸਟਰੈਕਸ਼ਨ ਵਰਗੇ ਵਿਚਾਰਾਂ ਦੁਆਰਾ ਡਾਟਾ ਲੁਕਾਉਣਾ ਵੀ ਪ੍ਰਦਾਨ ਕੀਤਾ ਜਾਂਦਾ ਹੈ।
ANS:
1. #include <iostream.h>
2. #include<conio.h>
3. void main() {
4. clrscr();
5. cout << "Welcome to C++ Programming.";
6. getch();
7. }
void main() The main() function is the entry point of every program in C++
language. The void keyword specifies that it returns no value.
cout << "Welcome to C++ Programming." is used to print the data "Welcome
to C++ Programming." on the console.
getch() The getch() function asks for a single character. Until you press any
key, it blocks the screen.
#include <conio.h> ਵਿੱ ਚ ਕੰ ਸੋਲ ਇੰ ਪੁੱ ਟ ਆਉਟਪੁੱ ਟ ਲਾਇਬ੍ਰੇਰੀ ਫੰ ਕਸ਼ਨ ਸ਼ਾਮਲ ਹਨ।
getch() ਫੰ ਕਸ਼ਨ conio.h ਫਾਈਲ ਵਿੱ ਚ ਪਰਿਭਾਸ਼ਿਤ ਕੀਤਾ ਗਿਆ ਹੈ।
void main() main() ਫੰ ਕਸ਼ਨ C++ ਭਾਸ਼ਾ ਵਿੱ ਚ ਹਰੇਕ ਪ੍ਰੋਗਰਾਮ ਦਾ ਐਂਟਰੀ ਪੁਆਇੰ ਟ ਹੈ। void
ਕੀਵਰਡ ਦਰਸਾਉਂਦਾ ਹੈ ਕਿ ਇਹ ਕੋਈ ਮੁੱ ਲ ਨਹੀਂ ਦਿੰ ਦਾ ਹੈ।
cout << "C++ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਵਿੱ ਚ ਤੁਹਾਡਾ ਸੁਆਗਤ ਹੈ।" ਡਾਟਾ ਪ੍ਰਿੰ ਟ ਕਰਨ ਲਈ ਵਰਤਿਆ
ਜਾਂਦਾ ਹੈ "C++ ਪ੍ਰੋਗਰਾਮਿੰ ਗ ਵਿੱ ਚ ਤੁਹਾਡਾ ਸੁਆਗਤ ਹੈ।" ਕੰ ਸੋਲ 'ਤੇ.
getch() getch() ਫੰ ਕਸ਼ਨ ਇੱ ਕ ਸਿੰ ਗਲ ਅੱ ਖਰ ਲਈ ਪੁੱ ਛਦਾ ਹੈ। ਜਦੋਂ ਤੱ ਕ ਤੁਸੀਂ ਕੋਈ ਵੀ ਕੁੰ ਜੀ
ਨਹੀਂ ਦਬਾਉਂਦੇ, ਇਹ ਸਕ੍ਰੀਨ ਨੂੰ ਬਲੌ ਕ ਕਰ ਦਿੰ ਦਾ ਹੈ।
1. By menu
Now click on the compile menu then compile sub menu to compile the c++
program.
Then click on the run menu then run sub menu to run the c++ program.
2. By shortcut
Or, press ctrl+f9 keys compile and run the program directly.
ANS: C++ ਪ੍ਰੋਗਰਾਮ ਨੂੰ ਕੰ ਪਾਇਲ ਕਰਨ ਅਤੇ ਚਲਾਉਣ ਦੇ 2 ਤਰੀਕੇ ਹਨ, ਮੇਨੂ ਅਤੇ ਸ਼ਾਰਟਕੱ ਟ
ਦੁਆਰਾ।
1. ਮੀਨੂ ਦੁਆਰਾ
ਹੁਣ ਕੰ ਪਾਇਲ ਮੀਨੂ 'ਤੇ ਕਲਿੱ ਕ ਕਰੋ ਫਿਰ c++ ਪ੍ਰੋਗਰਾਮ ਨੂੰ ਕੰ ਪਾਇਲ ਕਰਨ ਲਈ ਕੰ ਪਾਇਲ ਸਬ
ਮੀਨੂ 'ਤੇ ਕਲਿੱ ਕ ਕਰੋ।
ਫਿਰ c++ ਪ੍ਰੋਗਰਾਮ ਨੂੰ ਚਲਾਉਣ ਲਈ ਰਨ ਮੀਨੂ 'ਤੇ ਕਲਿੱ ਕ ਕਰੋ ਫਿਰ ਸਬ ਮੀਨੂ ਚਲਾਓ।
2. ਸ਼ਾਰਟਕੱ ਟ ਦੁਆਰਾ
ANS: C++ I/O operation is using the stream concept. Stream is the sequence of
bytes or flow of data. It makes the performance fast.
If bytes flow from main memory to device like printer, display screen, or a
network connection, etc, this is called as output operation.
If bytes flow from device like printer, display screen, or a network connection,
etc to main memory, this is called as input operation.
ANS: C++ I/O ਆਪਰੇਸ਼ਨ ਸਟ੍ਰੀਮ ਸੰ ਕਲਪ ਦੀ ਵਰਤੋਂ ਕਰ ਰਿਹਾ ਹੈ। ਸਟ੍ਰੀਮ ਬਾਈਟਸ ਜਾਂ ਡੇਟਾ
ਦੇ ਪ੍ਰਵਾਹ ਦਾ ਕ੍ਰਮ ਹੈ। ਇਹ ਪ੍ਰਦਰਸ਼ਨ ਨੂੰ ਤੇਜ਼ ਬਣਾਉਂਦਾ ਹੈ.
ਜੇਕਰ ਬਾਈਟਸ ਮੁੱ ਖ ਮੈਮੋਰੀ ਤੋਂ ਡਿਵਾਈਸ ਜਿਵੇਂ ਪ੍ਰਿੰ ਟਰ, ਡਿਸਪਲੇ ਸਕਰੀਨ, ਜਾਂ ਇੱ ਕ ਨੈ ਟਵਰਕ
ਕਨੈ ਕਸ਼ਨ ਆਦਿ ਵਿੱ ਚ ਵਹਿੰ ਦੇ ਹਨ, ਤਾਂ ਇਸਨੂੰ ਆਉਟਪੁੱ ਟ ਓਪਰੇਸ਼ਨ ਕਿਹਾ ਜਾਂਦਾ ਹੈ।
ਜੇਕਰ ਬਾਈਟਸ ਡਿਵਾਈਸ ਜਿਵੇਂ ਕਿ ਪ੍ਰਿੰ ਟਰ, ਡਿਸਪਲੇ ਸਕਰੀਨ, ਜਾਂ ਨੈ ਟਵਰਕ ਕਨੈ ਕਸ਼ਨ ਆਦਿ
ਤੋਂ ਮੁੱ ਖ ਮੈਮੋਰੀ ਵਿੱ ਚ ਵਹਿੰ ਦੇ ਹਨ, ਤਾਂ ਇਸਨੂੰ ਇਨਪੁਟ ਆਪਰੇਸ਼ਨ ਕਿਹਾ ਜਾਂਦਾ ਹੈ।
<iostream> It is used to define the cout, cin and cerr objects, which correspond to
standard output stream, standard input stream and standard error
stream, respectively.
<iomanip> It is used to declare services useful for performing formatted I/O, such
as setprecision and setw.
Let us see the common header files used in C++ programming are:
Standard output stream (cout)
cin istream ਕਲਾਸ ਦੀ ਇੱ ਕ ਪੂਰਵ ਪਰਿਭਾਸ਼ਿਤ ਵਸਤੂ ਹੈ। ਇਹ ਸਟੈਂਡਰਡ ਇਨਪੁਟ ਡਿਵਾਈਸ
ਨਾਲ ਜੁੜਿਆ ਹੋਇਆ ਹੈ, ਜੋ ਕਿ ਆਮ ਤੌਰ 'ਤੇ ਕੀਬੋਰਡ ਹੁੰ ਦਾ ਹੈ। ਕੰ ਸੋਲ ਤੋਂ ਇਨਪੁਟ ਨੂੰ ਪੜ੍ਹਨ
ਲਈ ਸਿਨ ਦੀ ਵਰਤੋਂ ਸਟ੍ਰੀਮ ਐਕਸਟਰੈਕਸ਼ਨ ਆਪਰੇਟਰ (>>) ਦੇ ਨਾਲ ਕੀਤੀ ਜਾਂਦੀ ਹੈ।
1. #include <iostream>
2. using namespace std;
3. int main( ) {
4. int age;
5. cout << "Enter your age: ";
6. cin >> age;
7. cout << "Your age is: " << age << endl;
8. }
Q.8
Difference between procedural programming and object-oriented
programming?
13. Data hiding There is not any proper way There is a possibility of data
for data hiding. hiding.
12 ਗੁੰ ਝਲਦਾਰ . ਇਹ ਗੁੰ ਝਲਦਾਰ ਸਮੱ ਸਿਆਵਾਂ ਇਹ ਗੁੰ ਝਲਦਾਰ ਸਮੱ ਸਿਆਵਾਂ ਲਈ
ਸਮੱ ਸਿਆਵਾਂ ਲਈ ਉਚਿਤ ਨਹੀਂ ਹੈ। ਢੁਕਵਾਂ ਹੈ.
16
ਫਲੋਚਾਰਟ ਫਲੋਚਾਰਟ ਚਿੰ ਨ੍ਹ ਬਣਾਉਣ ਲਈ ਵੱ ਖ-ਵੱ ਖ ਕਿਸਮਾਂ ਦੇ ਬਕਸੇ ਵਰਤੇ ਜਾਂਦੇ ਹਨ। ਸਾਰੇ
ਵੱ ਖ-ਵੱ ਖ ਕਿਸਮਾਂ ਦੇ ਬਕਸੇ ਤੀਰ ਰੇਖਾਵਾਂ ਦੁਆਰਾ ਜੁੜੇ ਹੋਏ ਹਨ। ਨਿਯੰ ਤਰਣ ਦੇ ਪ੍ਰਵਾਹ ਨੂੰ
ਪ੍ਰਦਰਸ਼ਿਤ ਕਰਨ ਲਈ ਐਰੋ ਲਾਈਨਾਂ ਦੀ ਵਰਤੋਂ ਕੀਤੀ ਜਾਂਦੀ ਹੈ। ਆਉ ਹਰ ਇੱ ਕ ਡੱ ਬੇ ਬਾਰੇ
ਵਿਸਥਾਰ ਵਿੱ ਚ ਜਾਣੀਏ।
Symbol Representation
Symbol Name
Terminal/Terminator
Process
Decision
Symbol Representation
Symbol Name
Document
Data or Input/Output
Stored Data
Flow Arrow
Comment or Annotation
Symbol Representation
Symbol Name
Predefined process
On-page connector/reference
Off-page connector/reference