Networking Fundamentals 1. Networking Definition Connecting two or more computing devices to share resources (data, hardware) and exchange information. 2. Distributed Computing A system where components located on networked computers communicate and coordinate their actions by passing messages. Goal: achieve a common task. 3. LAN vs. WAN Feature LAN (Local Area Network) WAN (Wide Area Network) Scope Small geographical area (e.g., office, home) Large geographical area (e.g., cities, countries) Speed Higher Lower (comparatively) Ownership Private Private or Public (ISP) Technology Ethernet, Wi-Fi DSL, Fiber, Satellite 4. Client/Server Network A network architecture where clients (end-user devices) request services or resources from servers (powerful computers providing resources). 5. Centralized Computing All processing, data storage, and management occur on a single, powerful central computer. Terminals connect to this central machine. 6. Applications of Networking Resource Sharing: Printers, files, internet connection. Communication: Email, instant messaging, video conferencing. Data Sharing: Databases, shared documents. E-commerce: Online shopping, banking. Entertainment: Online gaming, streaming. 27. Protocol A set of rules governing the exchange of data between devices in a network. Examples: TCP/IP, HTTP, FTP. C++ Programming Basics 10. Data Types in C++ Primary (Built-in): int : Integers (e.g., $5, -10$). char : Single characters (e.g., $'A', 'z'$). float : Single-precision floating-point numbers (e.g., $3.14f, -0.5f$). double : Double-precision floating-point numbers (e.g., $3.14159, 0.001$). bool : Boolean values ($true, false$). void : Absence of type. Derived: Arrays, Pointers, References. User-Defined: Structures, Unions, Classes, Enums. 11. Integer and Real Constants Integer Constant: A fixed whole number without a fractional part. Decimal: $123, -456$ Octal (prefix $0$): $012$ (decimal $10$) Hexadecimal (prefix $0x$): $0xA$ (decimal $10$) Real Constant (Floating-point): A fixed number with a fractional part. Standard: $3.14, -0.001$ Exponential: $2.5e-3$ (means $2.5 \times 10^{-3}$) 12. Define Variable A named memory location used to store data. Its value can change during program execution. 13. Variable Declaration Specifying the data type and name of a variable before its first use. int age; float price; char grade; Initialization (optional): int count = 10; double pi = 3.14159; 18. Keywords in C++ Reserved words that have special meaning to the compiler and cannot be used as identifiers (variable names, function names, etc.). Examples: int, float, if, else, while, for, class, public, private . 17. Structure of a C++ Program // Header files #include <iostream> // For input/output operations // Global declarations (optional) const double PI = 3.14; // main function - entry point of program int main() { // Variable declarations int number = 10; // Executable statements std::cout << "Hello, C++!" << std::endl; std::cout << "Number: " << number << std::endl; // Return statement return 0; // Indicates successful execution } 16. Insertion and Extraction Operators Insertion Operator ( << ): Used with cout to send data to the standard output stream (e.g., console). std::cout << "Value: " << 10; Extraction Operator ( >> ): Used with cin to read data from the standard input stream (e.g., keyboard) into a variable. int x; std::cin >> x; Operators and Control Structures 15. Operators and Types Operator: A symbol that performs an operation on one or more operands. Types: Arithmetic: $+, -, *, /, \%, ++, --$ Relational: $==, !=, >, <, >=, <=$ Logical: $&& (AND), || (OR), ! (NOT)$ Bitwise: $&, |, ^, \sim, <<, >>$ Assignment: $=, +=, -=, *=, /=, \%=$ Conditional (Ternary): $? :$ 14. Increment and Decrement Operators Increment ( ++ ): Increases the value of an operand by 1. Prefix: ++a (increments, then uses value) Postfix: a++ (uses value, then increments) int x = 5; int y = ++x; // x is 6, y is 6 int z = x++; // x is 7, z is 6 Decrement ( -- ): Decreases the value of an operand by 1. Prefix: --a Postfix: a-- 9. Control Structure Statements that alter the normal sequential flow of execution in a program. Types: Sequence: Statements executed one after another. Selection (Decision): if, if-else, switch . Iteration (Looping): for, while, do-while . 7. If and If-Else Statement if statement: Executes a block of code if a condition is true. if (condition) { // code to execute if condition is true } Example: int score = 85; if (score > 70) { std::cout << "Pass" << std::endl; } if-else statement: Executes one block if condition is true, another if false. if (condition) { // code if true } else { // code if false } Example: int age = 16; if (age >= 18) { std::cout << "Eligible to vote" << std::endl; } else { std::cout << "Not eligible to vote" << std::endl; } 8. Switch Statement Allows a variable to be tested for equality against a list of values (cases). switch (expression) { case value1: // code block 1 break; case value2: // code block 2 break; // ... default: // code block if no match } 28. Break and Continue Statement break : Terminates the innermost loop ( for, while, do-while ) or switch statement and transfers control to the statement immediately following the loop/switch. continue : Skips the rest of the current iteration of the innermost loop and proceeds to the next iteration. 26. Scope Resolution Operator ( :: ) Used to define a function outside a class or to access a global variable when there is a local variable with the same name. int count = 10; // Global variable void func() { int count = 5; // Local variable std::cout << "Local count: " << count << std::endl; std::cout << "Global count: " << ::count << std::endl; } // Class method definition outside class class MyClass { public: void display(); }; void MyClass::display() { // ... } Algorithm and Flowchart 25. Characteristics of Algorithm Unambiguous: Each step must be clear and have only one meaning. Input: Zero or more well-defined inputs. Output: One or more well-defined outputs. Finiteness: Must terminate after a finite number of steps. Feasibility: Must be able to be executed with available resources. Independence: Steps should be independent of any programming language. 19. Algorithm for Swapping Two Numbers START Read two numbers, say $A$ and $B$. Declare a temporary variable, say $TEMP$. Assign $TEMP = A$. Assign $A = B$. Assign $B = TEMP$. Print $A$ and $B$. STOP 20. Algorithm to Check if a Number is Prime START Read a number, say $N$. If $N \le 1$, print "$N$ is not prime" and go to step 8. Initialize $i = 2$. While $i \times i \le N$: If $N \pmod i == 0$, print "$N$ is not prime" and go to step 8. Increment $i$ by $1$. Print "$N$ is prime". STOP 23. Define Flowchart and Symbols Flowchart: A graphical representation of an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting them with arrows. Common Symbols: $\text{Terminal (Start/End):}$ $\text{Process:}$ $\text{Input/Output:}$ $\text{Decision:}$ $\text{Flow Line:}$ 24. Flowchart for Factorial of N Numbers START Input N fact = 1, i = 1 i <= N? No Output fact STOP Yes fact = fact * i i = i + 1 Program Development and Analysis 22. Program Analysis Step Problem Definition: Clearly understand what the program needs to do. Identify inputs, outputs, and constraints. Problem Analysis: Break down the problem into smaller, manageable parts. Determine data structures, algorithms, and modules required. Design: Develop a logical plan for the solution using tools like algorithms, flowcharts, pseudocode, or UML diagrams. Coding: Translate the design into a specific programming language. Testing and Debugging: Execute the program with various inputs to find and fix errors. Documentation: Create user manuals, technical documentation, and comments within the code. Maintenance: Update and enhance the program over time to fix new bugs, improve performance, or add features. Number Systems and Operations 21. 1's Complement Subtraction $(10110)_2 - (11101)_2$ Identify the subtrahend: $(11101)_2$. Find the 1's complement of the subtrahend (flip all bits): $1's \text{ complement of } (11101)_2 \text{ is } (00010)_2$. Add the minuend to the 1's complement of the subtrahend: 10110 + 00010 ------- 11000 Since there is no end-around carry (the result is 5 bits, same as initial numbers), the result is negative. Find the 1's complement of the sum and put a negative sign. $1's \text{ complement of } (11000)_2 \text{ is } (00111)_2$. Result: $-(00111)_2$. 29. Number System Conversions a) $(111.011)_2 = (?)_{10}$ Integer part: $1 \times 2^2 + 1 \times 2^1 + 1 \times 2^0 = 4 + 2 + 1 = 7$ Fractional part: $0 \times 2^{-1} + 1 \times 2^{-2} + 1 \times 2^{-3} = 0 + 0.25 + 0.125 = 0.375$ Result: $7.375_{10}$ b) $(5971)_8 - (?)_{2}$ First, convert $(5971)_8$ to decimal (assuming $9$ is a typo, as octal digits are $0-7$. Let's assume it's $(5771)_8$ or $(5071)_8$. If it is $(5971)_8$, it's an invalid octal number, as $9$ is not an octal digit. Let's proceed with $(5771)_8$ for demonstration.) $(5771)_8 = 5 \times 8^3 + 7 \times 8^2 + 7 \times 8^1 + 1 \times 8^0$ $= 5 \times 512 + 7 \times 64 + 7 \times 8 + 1 \times 1$ $= 2560 + 448 + 56 + 1 = (3065)_{10}$ Now, convert $(3065)_{10}$ to binary: $3065 \div 2 = 1532 \text{ R } 1$ $1532 \div 2 = 766 \text{ R } 0$ $766 \div 2 = 383 \text{ R } 0$ $383 \div 2 = 191 \text{ R } 1$ $191 \div 2 = 95 \text{ R } 1$ $95 \div 2 = 47 \text{ R } 1$ $47 \div 2 = 23 \text{ R } 1$ $23 \div 2 = 11 \text{ R } 1$ $11 \div 2 = 5 \text{ R } 1$ $5 \div 2 = 2 \text{ R } 1$ $2 \div 2 = 1 \text{ R } 0$ $1 \div 2 = 0 \text{ R } 1$ Reading remainders from bottom up: $(101111111001)_2$ 30. Add Binary Numbers a) $(0011010)_2 + (111001)_2$ 0011010 (26) + 00111001 (57) --------- 1010011 (83) b) $(1010111)_2 + (1001111)_2$ 1010111 (87) + 1001111 (79) --------- 10100110 (166)