0% found this document useful (0 votes)
25 views31 pages

Laiba Babar (E-4) Computer Portfolio

idk portfolio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views31 pages

Laiba Babar (E-4) Computer Portfolio

idk portfolio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Student

STUDENTNameNAME
: Talha: Nadeem
LAIBA BABAR

CLASS : E-4

COMPUTER SCIENCE

PRACTICALPORTFOLIO

XII HSSC 2024-2025


AGA KHAN HIGHER SECONDARY SCHOOL,
Karachi

Computer Science Practicals XII

Certificate

It is certified that Mr./Ms. Laiba Babar of XII Computer Science


Talha Nadeem

has carried out the necessary practical work as prescribed by the Aga

Khan University Examination Board (AKUEB) for the

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.

Write a program which takes marks as an input and calculates


Practical 4 the grades of students based on marks.

Write a program in C++ and show whether the input character


Practical 5 is vowel or consonant using switch case.

Write a C++ program to calculate the sum of the first 10 positive


Practical 6 odd numbers.

Write the program to print the factorial of an input number.


Practical 7

Practical 8 Generate the following pattern by using nested For loop.


**********
**********
**********
**********
Practical 9 Print the following format using nested for loop.
1
12
123
1234
12345
123456
1234567
Practical 10 Print the following output by using nested for loop.
*
***
*****
*******
*********
Practical 1

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;

if(a>b && a>c) cout<<a<<" is the largest


number.";
else if(b>a && b>c) cout<<b<<" is the
largest number.";
else cout<<c<<" is the largest number.";
return 0;
}

Output:
Practical 4

Objective:

Write a program which takes marks as an input and calculates the


grades of students based on marks.

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:

Write a program in C++ and show whether the input character is


vowel or consonant using switch case.

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:

Write the program to print the factorial of an input number.

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:

Generate the following pattern by using nested For loop.

**********
**********
**********
* * * * * * * * * * Source code:

#include <iostream> using


namespace std; int main(){ int
rows=4; int columns=10;
for(int i = 0 ; i <= rows; i++)
{
for(int j = 0; j <= columns; j++)
{
cout<< " * ";
} cout <<
endl;
Practical 8

Objective:

}
return 0;
}

Output:

Print the following format using nested for loop.


1
12
123
1234
12345
123456
1234567

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:

Print the following output by using nested for loop.

*
***
*****
*******
*********

Source code:
#include <iostream>
using namespace std;

int main(){ for(int i=1; i<=5; i++) {


for(int j=1; j<=2*i-1; j++) { cout
<< '*';
} cout <<
endl;
} return
0;
}

Output:
Practical 11

Objective:

Print the following output by using nested for loop.

*
**
***
****
*****

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:

Write a C++ program which stores numeric values in a


onedimensional array using for loop and finds the highest, lowest
and average values.

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;

int a[rows][cols], b[rows][cols], c[rows][cols]; cout


<< "Enter the elements of first matrix: " << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{ cin >> a[i][j];
}
}
cout << "Enter the elements of second matrix: " << endl;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{ cin >> b[i][j];
Practical 15

Objective:

}
}
Practical

Objective:

for (int i = 0; i < rows; i++)


{
for (int j = 0; j < cols; j++)
{ c[i][j] = a[i][j] + b[i][j];
}
}
cout << "The result of addition of two matrices is: " << endl;
for (int i = 0; i < rows; i++)
{ cout<<"|";
for (int j = 0; j < cols; j++)
{
cout << c[i][j] << " ";
} cout <<
"|";
cout<<endl;
} return 0;
}

15

Write a program involving use of user defined function to calculate


volume of cylinder, sphere and cube.

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:

default: cout << "Invalid choice!" <<


endl;
break;
} return
0;
}

Output:

16

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>
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

Write a program involving a user defined function to check whether


the input number is a prime number or not.

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

Write a program involving a user defined function to check whether


the input number is a prime number or not.

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:

You might also like