Mid-Revision
Programming Fundamental
Content:
Introduction to Variables
Programming int-Floating-Point Data
Writing the First Program Types
Your first program Input Output Streams (cout,
Input, Processing, and cin)
Output Different types of errors
The Parts of a C++ Program Arithmetic instructions
The cout Diagrams and Flow charts
The header files Operators
The using Directive Making Decisions
The # define Dangling else • Flow chart
directive(preprocessor and decision making
directives) Keywords • Identifiers •
Single line comments Constants
What is C++?
C++ is a high-level, object-oriented programming language.
Developed by Bjarne Stroustrup in 1983.
Supports both procedural and object-oriented programming.
Commonly used for:
Software development
Game development
System programming
Basic Syntax of C++
#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!";
return 0;
}
Explanation:
#include <iostream> → Input/Output header
using namespace std; → Allows use of standard names
int main() → Program starts from here
cout → Displays output
cin→ Take input from user
return 0; → Ends the program
Flowchart of a C++ Program
Algorithm
Step 1: Start
Step 2: Input length and width
Step 3: Compute area = length × width
Step 4: Display area
Step 5: End
Pseudocode
BEGIN
INPUT length, width
SET area = length * width
DISPLAY area
END
Case Sensitivity in C++
C++ is a case-sensitive programming language,which means it treats
uppercase and lowercase letters as different.
If you use different capitalization for variable names, function names,
or identifiers ,C++ considers them separate and unrelated.
number, Number, and NUMBER → are three different variables.
int Number = 10;
int number = 20;
int marks = 90;
cout << Number; // Outputs 10 cout << Marks;
cout << number; // Outputs 20
marks ≠ Marks (different capitalization)
Where Case Sensitivity Applies:
Variable names: total, Total • Total Count
Function names: print(), Print()
Class names: student, Student
Constants: PI, pi
Keywords: Note — all keywords are lowercase in C+
+
int, return, while (valid)
Int, Return, While (invalid)
Single and Double Quotes in C++
Type Symbol Used For Example
Single Charact
'' 'A', '1'
Quotes er
Double String/ "Hello",
""
Quotes Text "123"
char grade = 'A';
string name = "Zara";
Cout<<“my name is Hafiza Zarafshan”;
Control Structures
Control
Structures: Decide the flow of
execution of a program.
Types:
Sequential – Executes in order
Selection (Decision) – if, if-else, switch
Iteration (Loops) – for, while, do-while
If-Else Statement
if (condition) { int age = 18;
// true block if (age >= 18)
} else { cout << "Eligible to vote.";
// false block else
} cout << "Not eligible.";
Switch Statement
switch(choice) {
case 1: cout << "Start"; break;
case 2: cout << "Stop"; break;
default: cout << "Invalid choice";
}
if–else if–else
if (condition1) {
// Executes if condition1 is true
}
else if (condition2) {
// Executes if condition2 is true
}
else if (condition3) {
// Executes if condition3 is true
}
else {
// Executes if none of the above conditions are true
}
#include <iostream> cout << "Grade
using namespace B";
std; else if (marks >=
70)
int cout << "Grade
main() {
C";
int marks;
else if (marks >=
cout << "Enter 60)
your marks: ";
cout << "Grade
cin >> marks; D";
else
if (marks >= 90) cout << "Fail";
cout << "Grade
Good Luck