AJMAN UNIVERSITY
COLLEGE OF ENGINEERING AND IT
DEPARTMENT OF _Biomedical_______ ENGINEERING
LAB REPORT (12)
Course: Computer Programming
Academic Year: 2022 – 2023
Semester: 2022-2
Name: Fares Heiba
ID:202210114
Submitted to: Engr. Warda Khalid
Submission Date: _____________________
Computer Programming – Practical session
1. Define a one-dimensional array (size 10) using for loop(s). The program should:
a. Have a predefined array
b. Display the numbers in FIFO and LIFO patterns
#include<iostream>
using namespace std;
void main()
{
int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
cout << " Numbers from 10 to 1 and from 1 to 10 : " << endl;
for (int i = 0; i <= 9; i++)
{
cout << a[i] << "\t";
}
cout << endl;
for (int j = 9; j >= 0; j--)
{
cout << a[j] << "\t";
}
cout << endl;
system("pause");
}
2. Define a two-dimensional array (size 4 x 4) using nested for loops. The program
should:
a. Have a predefined array
b. Display the result in the 4x4 format
c. Also display the transpose (4x4 format)
#include<iostream>
using namespace std;
void main()
{
int a[4][4] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 3; j++)
{
cout << a[i][j] << "\t";
}
cout << endl;
}
cout << endl;
cout << endl;
{
for (int i = 0; i <= 3; i++)
{
for (int j = 0; j <= 3; j++)
{
cout << a[j][i] << "\t";
}
cout << endl;
}
}
system("pause");
}
3. Write a C++ program that defines an empty array of size 10 and asks the user to input
marks scored by ten students. The program should show the top three scores achieved
by students.
#include<iostream>
using namespace std;
void main()
{
int a[10], m1 = 0, m2 = 0, m3 = 0;
for (int i = 0; i < 10; i++)
{
cout << "Enter score of student number[" << i << "]" << endl;
cin >> a[i];
}
for (int i = 0; i < 10; i++)
{
if (a[i] > m1)
{
m1 = a[i];
}
for (int i = 0; i < 10; i++)
{
if (a[i] > m2 && m1 > a[i])
{
m2 = a[i];
}
}
for (int i = 0; i < 10; i++)
{
if (a[i] > m3 && m2 > a[i])
{
m3 = a[i];
}
}
cout << "Top 1 student mark :" << m1 << endl;
cout << "Top 2 student mark : " << m2 << endl;
cout << "Top 3 student mark : " << m3 << endl;
system("pause");
}
4. Write a C++ program that defines an empty array of size 4x4 and accepts sixteen
numbers from the user. Display the numbers as rows and columns. Also, display the
transpose of the obtained matrix.
#include<iostream>
using namespace std;
void main()
{
int a[4][4];
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cout << "Enter [" << i << "][" << j << "]" << endl;
cin >> a[i][j];
}
}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cout << a[i][j] << "\t";
}
cout << endl;
}
cout << "************************" << endl;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cout << a[j][i] << "\t";
}
cout << endl;
}
system("pause");
}