Lab Report 02
Lab Report 02
Submitted By:
MOHAMMAD AWAIS MALIK 19-EE-057
SH. TALHA 19-EE-093
WASIF ALI 19-EE-157
ALI ASHFAQ-19-EE-179
[Section :C]
Submitted to:
Sir Jawwad Qammar
Dated:
Week 02
Solution:
Brief description (3-5 lines)
Write a C++ Program to Calculate Average of Numbers Using Arrays. This program takes n
number of element from user (where, n is specified by user), stores data in an array and
calculates the average of those numbers.
The code
#include <iostream>
using namespace std;
int main()
{
int n, i;
float num[100], sum=0.0, average;
average = sum / n;
cout << "Average = " << average;
return 0;
}
Page 1 of 13
The results (Screenshot)
Solution:
Brief description (3-5 lines)
Write C++ Program to Calculate Standard Deviation. This program calculates the standard
deviation of a individual series using arrays.
The code
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int i;
float data[10];
return 0;
}
int i;
mean = sum/10;
Page 3 of 13
Lab Task No 03:
Solution:
Brief description (3-5 lines)
Write a C++ Program to Add Two Matrix Using Multi-dimensional Arrays. In this program,
user is asked to enter the number of rows r and columns c. The value of r and c should be less
than 100 in this program. The user is asked to enter elements of two matrices (of order r*c).
Then, the program adds these two matrices, saves it in another matrix (two-dimensional
array) and displays it on the screen.
The code
Page 4 of 13
#include <iostream>
using namespace std;
int main()
{
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
cout << endl << "Enter elements of 1st matrix: " << endl;
Page 5 of 13
cout << endl;
}
return 0;
}
Solution:
Brief description (3-5 lines)
Write a C++ program to check Whether a Number can be Expressed as a Sum of Two
Prime Numbers or not using Functions.
The code
#include <iostream>
using namespace std;
Page 6 of 13
bool checkPrime(int n);
int main()
{
int n, i;
bool flag = false;
if (!flag)
cout << n << " can't be expressed as sum of two prime numbers.";
return 0;
}
Page 7 of 13
return isPrime;
}
Solution:
Brief description (3-5 lines)
Write a C++ program to generate the multiplication table of a number (entered by the user)
using Functions.
The code
#include<iostream>
using namespace std;
int main()
{
Page 8 of 13
int n=0;
table(n);
int table(int n)
{
int t=1;
return 0;
}
Page 9 of 13
Lab Task 06:
Brief description (3-5 lines)
Write a C++ program that will display the calculator menu.
The program will prompt the user to choose the operation choice (from 1 to 5). Then it asks
the user to input two integer vales for the calculation.
The code
#include <cstdlib>
#include <iostream>
#include<iomanip>
void displaymenu(){
cout<<" MENU "<<"\n";
cout<<" 1.Add"<<"\n";
cout<<" 2.Subtract"<<"\n";
cout<<" 3.Multiply"<<"\n";
cout<<" 4.Divide"<<"\n";
cout<<" 5.Modulus"<<"\n";
}
Page 10 of 13
int Add(int a,int b){
return(a+b);
}
cout<<"\nPress y or Y to continue:";
cin>>confirm;
Page 11 of 13
}while(confirm=='y'||confirm=='Y');
system("PAUSE");
return EXIT_SUCCESS;
}
THE END
Page 12 of 13