3. Programming Language and Its Applications
Computer Engineering - Nec (Nepal Engineering Council)
Chapters
- 1. Concept of Basic Electrical and Electronics Engineering
- 2. Digital Logic and Microprocessor (AExE02)
- 3. Programming Language and Its Applications
- 4. Computer Organization and Embedded System (ACtE04)
- 5. Concept of Computer Network and Network Security System (ACtE05)
- 6. Theory of Computation and Computer Graphics (ACtE06)
- 7. Data Structures and Algorithm, Database System, and Operating System (ACtE07)
- 8. Software Engineering and Information System (ACtE08)
- 9. Artificial Intelligence, Data Science, and Internet of Things (ACtE09)
- 10. Project Management and Innovation (ACtE10)
3. Programming Language and Its Applications (ACtE03)
3.1 Introduction to C Programming
C Tokens
- Definition: The smallest individual units in a C program.
- Types:
- Keywords:
int
,return
,if
,else
, etc. - Identifiers: Variable and function names.
- Constants: Numeric or character values (
10
,'A'
,3.14
). - Strings:
"Hello, World!"
- Operators:
+
,-
,*
,/
,==
, etc. - Special Symbols:
{}
,()
,[]
,,
,;
, etc.
- Keywords:
Operators
- Arithmetic:
+
,-
,*
,/
,%
- Relational:
==
,!=
,>
,<
,>=
,<=
- Logical:
&&
,||
,!
- Bitwise:
&
,|
,^
,~
,<<
,>>
- Assignment:
=
,+=
,-=
,*=
,/=
,%=
- Increment/Decrement:
++
,--
- Ternary:
condition ? value1 : value2
Formatted and Unformatted Input/Output
- Formatted I/O: Uses
printf()
andscanf()
. - Unformatted I/O: Uses
getchar()
,putchar()
,gets()
,puts()
.
Control Statements
- Conditional Statements:
if
,if-else
,switch-case
- Looping Statements:
for
,while
,do-while
User-defined Functions
- Functions help in modular programming.
Recursive Functions
- Functions that call themselves.
Arrays
- 1-D Array:
- 2-D Array:
- Multi-Dimensional Array: Arrays with more than two dimensions.
String Manipulations
- String Declaration:
- String Functions (
string.h
):
3.2 Pointers, Structure, and Data Files in C Programming
Pointer Arithmetic
- A pointer stores the address of a variable.
Pointer and Array
- A pointer can traverse an array.
Passing Pointer to Function
- Used for efficient memory handling.
Structure vs Union
- Structure: Stores different data types.
- Union: Shares memory for all variables.
File Handling in C
- Opening a File:
- Reading from File:
- Writing to File:
- Closing File:
3.3 C++ Language Constructs with Objects and Classes
Namespace
- Avoids name conflicts.
Function Overloading
- Multiple functions with the same name but different parameters.
Classes and Objects
- Defining a Class:
- Creating an Object:
Constructor and Destructor
- Constructor: Initializes an object.
- Destructor: Cleans up resources.
3.4 Features of Object-Oriented Programming
- Operator Overloading:
- Inheritance:
3.5 Pure Virtual Function and File Handling
Virtual Function & Dynamic Binding
- Enables runtime polymorphism.
File Handling in C++
- Opening File:
- Reading File:
3.6 Generic Programming and Exception Handling
Function Template
- Creates generic functions.
Class Template
- Allows generic data types.
Exception Handling
- Basic Syntax: