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

FAST Programming Guide

The document is a comprehensive guide on programming fundamentals tailored for CS and Cyber Security students, covering essential concepts in C++ and Python, including data types, control structures, functions, and object-oriented programming. It also emphasizes problem-solving techniques and pseudocode, alongside debugging tips. The guide aims to equip students with foundational programming skills necessary for their studies and future careers.

Uploaded by

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

FAST Programming Guide

The document is a comprehensive guide on programming fundamentals tailored for CS and Cyber Security students, covering essential concepts in C++ and Python, including data types, control structures, functions, and object-oriented programming. It also emphasizes problem-solving techniques and pseudocode, alongside debugging tips. The guide aims to equip students with foundational programming skills necessary for their studies and future careers.

Uploaded by

samjhoteam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

FAST UNIVERSITY

Programming Fundamentals Guide


Essential Programming Concepts for CS & Cyber Security Students
Covering: C++ Basics | OOP | Python | Problem Solving | Pseudocode | Debugging
Chapter 1: Introduction to Programming
Programming is the process of designing and writing instructions that a computer can
execute to solve problems. A program is a sequence of instructions written in a
programming language.

1.1 Types of Programming Languages


Generation Type Examples Characteristics
1GL Machine Language Binary (0s and 1s) CPU executes directly, very
fast
2GL Assembly MASM, NASM Uses mnemonics, low-level
Language
3GL High-Level C, C++, Java, Python Human-readable, portable
Language
4GL Very High-Level SQL, MATLAB Domain-specific, abstracted
5GL AI/Logic Prolog, LISP Used in AI, constraint-based
Languages

1.2 Compiled vs Interpreted Languages


Feature Compiled (e.g., C++) Interpreted (e.g., Python)
Execution Converts entire code to machine Executes line by line at runtime
code first
Speed Faster execution Slower (interpreted at runtime)
Error Detection Errors caught before running Errors found during execution
Output Produces an .exe or binary file No standalone binary produced
Examples C, C++, Java (bytecode) Python, JavaScript, Ruby
Chapter 2: C++ Programming Fundamentals
C++ is the primary language taught at FAST for introductory courses. A solid
understanding is expected from incoming students.

2.1 Basic Program Structure


Every C++ program follows this basic structure:
#include <iostream>
using namespace std;

int main() {
// Your code goes here
cout << "Hello, World!" << endl;
return 0;
}

2.2 Data Types in C++


Data Type Size Range / Description Example
int 4 bytes -2,147,483,648 to 2,147,483,647 int age = 20;
float 4 bytes ~7 decimal digits precision float pi = 3.14;
double 8 bytes ~15 decimal digits precision double x = 3.14159;
char 1 byte Single character (ASCII 0-127) char grade = 'A';
bool 1 byte true (1) or false (0) bool pass = true;
string Variable Sequence of characters string name = "Ali";
long long 8 bytes Very large integers long long big = 1e18;

2.3 Operators in C++


Arithmetic Operators: + (add), - (subtract), * (multiply), / (divide), % (modulus)
Comparison Operators: == (equal), != (not equal), > , < , >= , <=
Logical Operators: && (AND), || (OR), ! (NOT)
Assignment Operators: =, +=, -=, *=, /=, %=
Increment/Decrement: ++ (increment by 1), -- (decrement by 1)
Chapter 3: Control Structures
Control structures determine the flow of execution in a program. They are the backbone
of any algorithm.

3.1 Conditional Statements


if-else Statement:
if (condition) {
// executes if condition is TRUE
} else if (another_condition) {
// executes if another_condition is TRUE
} else {
// executes if all conditions are FALSE
}

switch Statement — used for multiple fixed values:


switch (variable) {
case 1: cout << "One"; break;
case 2: cout << "Two"; break;
default: cout << "Other";
}

3.2 Loops
Loop Type Syntax / Use Case When to Use
for loop for(init; condition; update) Known number of
iterations
while loop while(condition) { ... } Unknown iterations,
check first
do-while loop do { ... } while(condition); Execute at least
once

Example — Printing 1 to 10 using for loop:


for (int i = 1; i <= 10; i++) {
cout << i << " ";
}

Loop Control: break exits the loop immediately; continue skips to the next iteration.
Chapter 4: Functions & Recursion
4.1 Functions in C++
A function is a named block of code that performs a specific task and can be called
multiple times.
// Function declaration (prototype)
int add(int a, int b);

// Function definition
int add(int a, int b) {
return a + b;
}

// Function call
int result = add(5, 3); // result = 8

Function Components:
• Return type: Data type of the value returned (void if nothing returned)
• Function name: Identifier used to call the function
• Parameters: Input values passed into the function
• Return statement: Sends result back to the calling code

4.2 Pass by Value vs Pass by Reference


Aspect Pass by Value Pass by Reference
What is passed A copy of the variable The actual memory address
Effect on original Original NOT changed Original CAN be changed
Syntax (C++) void func(int x) void func(int &x)
Memory Extra memory used No extra memory
Use case When original must be protected When you want to modify original

4.3 Recursion
Recursion is when a function calls itself. Every recursive function must have a base
case to stop.
int factorial(int n) {
if (n == 0 || n == 1) // Base case
return 1;
return n * factorial(n - 1); // Recursive call
}
// factorial(5) = 5 × 4 × 3 × 2 × 1 = 120

Famous Recursive Problems: Fibonacci series, Tower of Hanoi, Binary Search, Tree
Traversal
Chapter 5: Arrays and Strings
5.1 Arrays in C++
Declaration and initialization:
int numbers[5] = {10, 20, 30, 40, 50};
cout << numbers[0]; // Output: 10 (0-indexed)

Common array operations:


1. Traversal: Loop through all elements
2. Search: Find a specific element (linear or binary)
3. Sorting: Arrange elements in order
4. Insertion: Add an element at a position
5. Deletion: Remove an element and shift remaining

5.2 Multidimensional Arrays


int matrix[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
cout << matrix[1][2]; // Output: 6 (row 1, col 2)

5.3 String Operations


Strings in C++ can use character arrays or the string class:
#include <string>
string s = "Hello World";
cout << [Link](); // 11
cout << [Link](0, 5); // "Hello"
cout << [Link]("World"); // 6 (starting index)
s = s + " FAST"; // Concatenation
Chapter 6: Object-Oriented Programming (OOP)
OOP is a programming paradigm that organizes software around objects (data +
behavior) rather than functions and logic. FAST places heavy emphasis on OOP.

6.1 Four Pillars of OOP


Pillar Definition C++ Mechanism
Encapsulation Wrapping data and methods into a Classes with
single unit (class) private/public access
Abstraction Hiding internal details, showing only Abstract classes,
essential features interfaces
Inheritance A class inherits properties from another class Child : public Parent
class
Polymorphism One interface, multiple implementations Function overloading,
virtual functions

6.2 Classes and Objects


class Student {
private:
string name; // Data member
int rollNo;

public:
// Constructor
Student(string n, int r) { name = n; rollNo = r; }

// Member function
void display() {
cout << "Name: " << name << ", Roll: " << rollNo;
}
};

// Creating object
Student s1("Ali", 101);
[Link](); // Output: Name: Ali, Roll: 101

6.3 Inheritance Types in C++


• Single Inheritance: One child inherits from one parent
• Multiple Inheritance: One child inherits from multiple parents
• Multilevel Inheritance: Child → Parent → Grandparent chain
• Hierarchical Inheritance: Multiple children from one parent
• Hybrid Inheritance: Combination of above types
Chapter 7: Python Programming Basics
Python is increasingly used in AI, Data Science, and scripting. Understanding Python
basics gives you an advantage in your FAST CS journey.

7.1 Python vs C++ Key Differences


Feature Python C++
Typing Dynamic (no type declaration) Static (must declare types)
Semicolons Not required Required at end of statements
Indentation Mandatory (defines blocks) Optional (uses {} for blocks)
Speed Slower (interpreted) Faster (compiled)
Memory Automatic (garbage collected) Manual (new/delete)
Management
Main Use AI, scripting, data science Systems, games, performance
apps

7.2 Python Syntax Examples


Variables (no type declaration needed):
name = "FAST"
age = 20
gpa = 3.85
is_admitted = True

Lists (like dynamic arrays):


marks = [85, 90, 78, 92, 88]
[Link](95) # Add to end
print(marks[0]) # First element: 85
print(len(marks)) # Length: 6

Functions in Python:
def greet(name):
return "Hello, " + name

print(greet("Ali")) # Output: Hello, Ali


7.3 Python Data Structures
• List [ ]: Ordered, mutable, allows duplicates — [1, 2, 3]
• Tuple ( ): Ordered, immutable — (1, 2, 3)
• Set { }: Unordered, no duplicates — {1, 2, 3}
• Dictionary { key: value }: Key-value pairs — {'name': 'Ali', 'age': 20}
Chapter 8: Problem Solving & Pseudocode
8.1 Algorithm Design Steps
6. Understand the problem — read carefully, identify inputs and outputs
7. Plan the solution — think about approach before coding
8. Write pseudocode — outline logic in plain English
9. Code the solution — translate pseudocode to actual code
10. Test the solution — check with normal, edge, and invalid cases
11. Optimize — improve efficiency if needed

8.2 Pseudocode Conventions


Pseudocode is a way to describe algorithms in human-readable format before writing
code.
BEGIN
INPUT num1, num2
IF num1 > num2 THEN
OUTPUT num1, " is larger"
ELSE
OUTPUT num2, " is larger"
END IF
END

8.3 Common Programming Patterns


Pattern Description When to Use
Loop with Sum/product inside a loop Sum of array, factorial
accumulator
Flag variable Boolean tracking a condition Search, validation
Two pointers Pointers from both ends moving Palindrome check, pair sum
inward
Divide and Conquer Split problem, solve halves Binary search, merge sort
Dynamic Store subproblem results Fibonacci, knapsack
Programming
Greedy Algorithm Make best local choice each step Minimum coins, scheduling
8.4 Debugging Tips
• Read error messages carefully — they pinpoint the problem line
• Use print statements to track variable values at each step
• Test with simple inputs first before complex cases
• Check boundary conditions: empty input, single element, maximum size
• Use a debugger (step through code line by line)
• Desk-check your code: mentally trace through the logic

Programming is a skill built through daily practice. Write code every single day
and your problem-solving ability will grow exponentially!

You might also like