Lab 1
Lab 1
“ SHEHZAIB ”
S2024332016
Revised Previous Concept
SESSION: Fall-2024
SEMESTER: 3rd
Revised Previous Concept
C++ Introduction
Variables
Data Types
Basic I/O
Type Conversion
Operators
Comments
Flow Control
switch Statement
if...else
while Loop
do...while Loop
for Loop
break
continue
Functions
Default Functions
Parametrize Functions
Return Type Functions
Parametrize and Return Type Functions
Arrays
Array
One Dimensional Array
Two Dimensional Array
Revised Previous Concept
Arrays
Array
Revised Previous Concept
In C++, an array is a variable that can store multiple values of the same type. For example,
Suppose a class has 27 students, and we need to store all their grades. Instead of creating 27 separate
variables, we can simply create an array
Types of Array
Static Array:
Fixed-size array where the size is defined at compile time and cannot be changed at runtime.
Dynamic Array:
Flexible-size array where memory is allocated at runtime, and the size can be modified as needed.
Static Array:
Revised Previous Concept
double grade[27];
dataType arrayName[arraySize];
Task
int main(){
int size ;
cout<<"Enter Size of array = ";
cin>> size;
int arr[size];
cin>>arr[i];
}
for( i = 0 ; i< size ; i++){
sum = sum + arr[i];
}
cout << "Sum = " <<sum;
}
int main(){
int size;
cout <<"Enter size of array = " ;
cin>>size;
int arr[size];
int i;
cout <<"Enter Elements of array = ";
for(i = 0 ; i<size ; i++){
cin>> arr[i];
}
int max = arr[0];
for ( i= 0 ; i< size ; i++){
if (arr[i]> max){
max = arr[i];
}
}
if (arr[i]< min){
min = arr[i];
}
}
cout <<" MIN = " << min ;
}
4. Array Reversal:
Create an array of characters to store a word. Write a program that reverses the word in
the array and then prints the reversed word.
#include<iostream>
using namespace std;
int main(){
int size ;
cout <<"Enter size of WORD= ";
cin>> size ;
char arr[size];
}
for (int i = size ; i>= 0 ; i--){
}
Revised Previous Concept
int size ;
cout <<"Enter size of arra = " ;
cin>> size ;
int arr[size ] ;
cout << "Enter Numbers = ";
if (arr[i]%2== 0){
7: Print 2D array
Revised Previous Concept
#include <iostream>
using namespace std ;
int main(){
int rows , cols;
int arr[rows][cols];
cout << "Enter Elements = " ;
for (int i = 0 ; i<rows ; i++){
for (int j = 0 ; j<cols ; j++){
#include <iostream>
using namespace std;
int main() {
int students = 3;
Revised Previous Concept
int subjects = 5;
int marks[students][subjects];
int sum = 0;
for (int i = 0; i < students; i++) {
return 0;
}