Lab No 1
Lab No 1
Lab No 1
Submitted by:
Name: Muhammad Suleman
Reg# B20F0404EE026
Submitted to:
Name: Rafi Ullah
Designation: LAB Engineer
Date:
October 01, 2021
LAB NO 1
C++ Review
OBJECTIVE:
• To Review the basic concepts of C++.
• To Review Arrays, how to declare, initialize and access 2D and 3D arrays Implement Arrays in C++.
APPARATUS:
The apparatus we used in this lab includes
DEVC++
Many compilers like IDE are present but we used DEVC++ it is efficient and easy to use.
INTRODUCTION:
This lab is about the basic concepts of C++. That includes datatypes and their categories.
It is about the operators (binary and unary) that they act as assignment and iteration operators.
It also tells the basics of relational, equality, logical operators and that how they used.
It covers the conditional statements includes if else statements and their applicability.
With exception to it also switch statement on expressions is t be reviewed. Loops that include
for, do, do while is also mentioned. And their difference, loop termination, condition and where
to use has been discussed in this lab.
Functions implementation and how to call them has been reviewed.
Arrays implementation that includes how to declare, initialize and access elements of array is
reviewed.
How element is stored in index, and with introduction in loop in arrays , iterations in loops of
array elements.
Then two dimension arrays implementation, declaration, initialization has been reviewed by
example of rows and column.
LAB TASK 1:
You’re given with marks of 10 students in Mathematics, write a program to determine
the grade of each student.
CODE:
#include <iostream>
using namespace std;
int main() {
int score[10]={80, 72, 93, 87, 90, 55, 66, 74, 69, 56},grade;
for (int i=0;i<10;i++)
{
if (score[i]>=90) {
OUTPUT:
LAB TASK 2:
Write a program to ask user to enter 5 floating numbers and find the maximum and minimum of all by
calling min() and max() functions.
CODE:
#include<iostream>
using namespace std;
OUTPUT:
LAB TASK 3:
3. Write a program that shows following output
CODE:
#include <iostream>
using namespace std;
#include <iomanip>
using std::setw;
int main ()
{ char x;
int n[ 10 ];
cout<<"Please enter 10 numbers:"<<endl;
for ( int i = 0; i < 10; i++ )
{
cin>>n[i];
n[ i ] = i + 1;
}
cout << "Element" << setw( 13 ) << "Value" << setw( 13 )<< "Histogram"<<endl;
for ( int j = 0; j < 10; j++ ) {
}
for( int k = 0; k < 10; k++)
{ cout << setw( 7 )<< k << setw( 13 ) << n[ k ]<<setw(13) ;
for(int l = 0; l <= k; l++)
{ cout<<"*";
}
cout<<endl;
}
return 0;
}
OUTPUT:
TASK NO 4:
Write a program that will print multi-subscripted array as shown below using function printArray()
CODE:
#include<iostream>
using namespace std;
void printarr(int a[][3],int b[][3],int c[][3]){
cout<<"Values in array1 by row are"<<endl;
for ( int i = 0; i < 2; i++ ){
for ( int j = 0; j < 3; j++ ) {
cout << a[i][j]<<"\t";}
cout<<"\n";
}
OUTPUT: