Laiba Babar (E-4) Computer Portfolio
Laiba Babar (E-4) Computer Portfolio
STUDENTNameNAME
: Talha: Nadeem
LAIBA BABAR
CLASS : E-4
COMPUTER SCIENCE
PRACTICALPORTFOLIO
Certificate
has carried out the necessary practical work as prescribed by the Aga
year 2024-2025
Incharge:
________________
Sir. Irfan Abdullah
Lecturer Computer Science
INDEX
XII AKUEB Computer Science Practicals
Practical Description Sign
No.
Write a C++ program to swap two numbers without using the
Practical 1 third variable.
Write a C++ program which takes input from user and shows
Practical 2 whether a number is positive, negative or zero.
Write a program which takes input for 3 numbers and find the
Practical 3 greatest among them.
Objective:
Write a C++ program to swap two numbers without using the
third variable.
Source code:
#include <iostream>
using namespace std;
int main()
{
int a, b;
cout<<"Enter the first number: ";
cin>>a;
cout<<"Enter the second number: ";
cin>>b;
cout<<"Before swapping: a = "<<a<<" and b = "<<b<<endl;
a=a+b; b=a-
b; a=a-b;
cout<<"After swapping: a = "<<a<<" and b = "<<b<<endl;
return 0;
}
Output:
Practical 2
Objective:
Write a C++ program which takes input from user and shows whether
a number is positive, negative or zero.
Source code:
#include <iostream>
using namespace std;
int main()
{ int a;
cout<<"Enter a number: ";
cin>>a; if(a>0) cout<<"The number is
positive.";
else if(a<0) cout<<"The number is
negative.";
else cout<<"The number is zero.";
return 0;
}
Output:
3
Practical
Objective:
Write a program which takes input for 3 numbers and find the
greatest among them.
Source code:
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cout<<"Enter the first number: ";
cin>>a;
cout<<"Enter the second number: ";
cin>>b;
cout<<"Enter the third number: ";
cin>>c;
Output:
Practical 4
Objective:
Source code:
#include <iostream>
using namespace std;
int main()
{ int a;
cout<<"Enter your marks out of 100: ";
cin>>a; if(a>=80)
cout<<"Grade: A";
else if(a>=70)
cout<<"Grade: B";
else if(a>=60)
cout<<"Grade: C";
else if(a>=50)
cout<<"Grade: D";
else if(a>=40)
cout<<"Grade: E";
else cout<<"Grade: F";
return 0;
}
Output:
Practical 5
Objective:
Source code:
#include <iostream>case 'A': using
case 'E':
namespace std; int main()case
'I': case 'O':
{case 'U':
char ch;cout<<"The letter is a vowel.";
cout<<"Enter a letter: ";break;
cin>>ch;default:
switch (ch)cout<<"The letter is a consonant.";
{break;
}
case 'a':return 0;
case 'e':} case 'i': case
'o': case 'u':
Output:
Practical 6
Objective:
Write a C++ program to calculate the sum of the first 10 positive odd
numbers.
Source code:
#include <iostream>
using namespace std;
int main(){
int num;
for(int i = 1 ; i < 20; i+=2)
{ num+=i; } cout<< "The sum of first 10 positive odd numbers is:"<<
num<< endl; return 0;
}
Output:
Source code:
#include <iostream>
using namespace std;
int main()
{ int n, result=1; cout<<"Enter
a number: "; cin>>n;
Practical 7
Objective:
for(int i=n;i>0;i--)
result=result*i;
cout<<"Factorial of "<<n<<" is: "<<result<<endl;
getchar(); return 0;
}
Output:
**********
**********
**********
* * * * * * * * * * Source code:
Objective:
}
return 0;
}
Output:
Source code:
#include <iostream> using namespace
std; int main() { for(int i=1; i<=7;
i++) { for(int j=1; j<=i; j++) { cout
<< j;
} cout <<
endl;
Practical 9
Objective:
} return
0;
}
Output:
Practical 10
Objective:
*
***
*****
*******
*********
Source code:
#include <iostream>
using namespace std;
Output:
Practical 11
Objective:
*
**
***
****
*****
Source code:
#include <iostream>
using namespace std;
int main() { for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= (5-i); j++) { cout
<< " ";
}
for (int j=1;j<=i;j++){
cout << "* ";
} cout <<
endl;
} return
0;
}
Practical 12
Objective:
Output:
Source code:
#include <iostream> using namespace std; int
main() { int n; cout << "Enter the number of
elements: "; cin >> n;
int arr[n], i, sum = 0, highest, lowest;
cout << "Enter the elements: ";
for (i = 0; i < n; i++) {
cin >> arr[i]; if
(i == 0) {
highest = arr[i];
lowest = arr[i];
}
if (arr[i] > highest) {
highest = arr[i];
}
if (arr[i] < lowest) {
lowest = arr[i];
}
sum += arr[i];
}
Practical 13
Objective:
cout << "Highest value: " << highest << endl; cout
<< "Lowest value: " << lowest << endl; cout <<
"Average value: " << (float)sum / n << endl; return
0;
}
Write a program to make a signup interference which takes user
name, password, retype-password as an input and compare the
password and re-enter password of user for sign up, using
strings library.
Source code:
#include <iostream>
#include <string.h>
using namespace std;
int main()
{ char username[20], password[20], repassword[20];
cout << "Enter your username: ";
cin>>username;
cout << "Enter your password: ";
cin>>password;
cout << "Re-enter your password: ";
cin>>repassword;
if(strcmp(password, repassword) == 0)
{ cout << "Your account has been created successfully." <<
endl; }
els
e
{ cout << "Your password and re-entered password do not
Practical 14
Objective:
match." <<
endl; }
return 0;
}
Write a program to add two matrices of order up to 4×4 using a
two dimensional array and show the ordered output in third matrix.
Source code:
#include <iostream>
using namespace std;
int main()
{ int rows,cols;
cout<<"Enter the number of rows of both matrices: ";
cin>>rows;
cout<<"Enter the number of columns of both matrices: ";
cin>>cols;
Objective:
}
}
Practical
Objective:
15
Source code:
#include <iostream> using namespace
std; float cylinder_volume(float r,
float h)
{
return 3.14 * r * r * h;
}
float sphere_volume(float r)
{
return 4.0 / 3.0 * 3.14 * r * r * r;
}
float cube_volume(float s)
{
return s * s * s;
} int
main()
{ int choice; cout << "Enter the choice of shape (1-cylinder, 2-sphere,
3-cube):
"; cin>>choice;
switch
(choice)
{ case
1:
float radius, height;
cout << "Enter the radius and height of the cylinder: ";
cin >> radius >> height;
cout << "The volume of the cylinder is: " <<
cylinder_volume(radius, height) << endl;
break;
case 2:
cout << "Enter the radius of the sphere: ";
cin >> radius;
cout << "The volume of the sphere is: " <<
sphere_volume(radius) << endl;
break;
case 3:
float s;
cout << "Enter the side length of the cube: ";
cin >> s;
cout << "The volume of the cube is: " << cube_volume(s) <<
endl; break;
Practical
Objective:
Output:
16
Source code:
#include <iostream>
using namespace std;
int n;
float average(float* arr)
{
float sum = 0; for(int
i=0; i<n; i++)
{ sum += arr[i];
}
return sum/n;
} int
main()
{ cout<<"Enter total numbers to calculate average of: ";
cin>>n; float arr[n];
cout << "Enter the numbers: ";
for(int i=0; i<n; i++)
cin>>arr[i];
cout << "The average of the numbers is " << average(arr) << endl;
return 0;
}
Output:
Practical
Objective:
17
Source code:
#include <iostream>
using namespace std;
int isprime(int n)
{
int flag = 0;
for(int i=2;i<=n/2;i++)
{ if (n%i==0){
flag = 1;
break;
}
}
if (flag == 0)
{
cout<<n<<" is a prime number.";
}
else{
cout<<n<<" is not a prime number.";
}
return 0;
} int
main()
{ int n;
cout<<"Enter a number: ";
cin>>n;
isprime(n);
return 0;
}
Output:
Practical
Objective:
18
Source code:
#include <iostream>
using namespace std;
int main()
{ int arr[5]={8,1,6,10,15};
int* ptr = arr; for(int
i=0;i<=5;i++)
{ cout<<"Address of arr["<<i<<"]: "<<ptr<<endl;
cout<<"Value of arr["<<i<<"]: "<<*ptr<<endl;
ptr++;
} return
0;
}
Output: