0% found this document useful (0 votes)
114 views

Lab Report 1

This lab report discusses completing 4 tasks involving arrays, including calculating student grades stored in an array, finding the maximum and minimum of user-input floating numbers, printing a histogram of user-input integers, and outputting multi-dimensional arrays. The student reflected that practicing the array concepts in the lab helped solidify their understanding and the tasks were simple to complete after reviewing arrays.

Uploaded by

Ali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
114 views

Lab Report 1

This lab report discusses completing 4 tasks involving arrays, including calculating student grades stored in an array, finding the maximum and minimum of user-input floating numbers, printing a histogram of user-input integers, and outputting multi-dimensional arrays. The student reflected that practicing the array concepts in the lab helped solidify their understanding and the tasks were simple to complete after reviewing arrays.

Uploaded by

Ali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Department of (Department Name)

Pak-Austria Fachhochschule: Institute of Applied Sciences and Technology,


Haripur, Pakistan

COMP-201L Data Structures and Algorithms Lab

Lab Report: 01

Name: Ali Farhan.


Department: Software Engineering.
Registration No.: B20F0471SE038
Semester: 3rd.
Submission Date: 3 Oct 2021.
Submitted to: Mr. Rafiullah
__________________
Instructor Signature

LAB NO. 1
Objectives:
Examining the structure, its initialization, and coding some practical programs. Examining array
including 2D, 3D and multidimensional arrays.

Tools/Software Required:
Tools required to complete the lab dev C++.

Introduction:
A structure is a collection of different data types that are grouped together under a single user-defined
struct name. It is like a class that contains various datatypes and functions. Various datatypes can be
accessed by creating a structure object. A pointer is a variable that stores an object's memory address.
Pointers are widely used in both C and C++ for three purposes: allocating new objects on the heap,
passing functions to other functions, and passing functions to other functions. to iterate through arrays or
other data structures.

Lab Tasks:
Lab Task 01: calculate grade for 10 student marks
Code
#include <iostream>
using namespace std;

int main()
{
int a[10]={80,72,93,87,90,55,66,74,59,105};
cout<<"<--------STUDENT GRADES-------->"<<endl;
for (int i = 0; i < 10; i++)
{
if (a[i]<=100 && a[i] >= 90)
{
cout << "Your grade is A "<<endl;
}
else if (a[i] < 90 && a[i]>81)
{
cout << "Your grade is B+"<<endl;
}
else if (a[i] < 82 && a[i]>71)
{
cout << "Your grade is B"<<endl;
}
else if (a[i] < 72 && a[i]>=66 )
{
cout << "Your grade is C"<<endl;
}
else if (a[i] < 66 && a[i]>59)
{
cout << "Your grade is D"<<endl;
}
else if (a[i] < 60 && a[i]>0)
{
cout << "Your grade is F"<<endl;
}
else
{
cout << "----------Invalid number cannot exceed
100!----------"<<endl;
}
}
}

Output

Lab Task 02: 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;

float max(float a[5])


{
for (int i=0; i<5; i++)
{
if (a[0] < a[i])
a[0] = a[i];
}
return a[0];
}
float min(float a[5])
{
for (int i=0; i<5; i++)
{
if (a[0] > a[i])
a[0] = a[i];
}
return a[0];
}

int main()
{
float n[5];
cout<<"<-----------Calculating maximum and minimum in array------------
>"<<endl;
cout << "Please enter 5 floating numbers: "<<endl;
for (int i=0; i<5; i++)
{
cin >> n[i];
}
max(n);
cout << "The Maximum Number is " << n[0]<<endl;
min(n);
cout << "The Minimum Number is "<< n[0]<<endl;
}

Output

Lab Task 03: Printing histogram.


Code
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int a[10];
cout<<"------------Please input below------------"<<endl;
cout << "Please Enter 10 Numbers: "<<endl;
for (int i=0; i<10; i++)
{
cin >> a[i];
}

cout << "Element" << setw(10) << "Value" << setw(15) << "Histogram" <<
endl;

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


{
cout << i << setw(12) << a[i] << setw(11) ;
for (int j=0; j<a[i]; j++)
{
cout << "*";
}
cout << endl;
}
}

Output

Lab Task 04: Programthat will print multi-subscripted array as shown below using function
printArray()..

Code
#include <iostream>
using namespace std;

void outputArr(int array[][3])


{
for (int i=0; i<2; i++)
{
for (int j=0; j<3; j++)
{
cout <<array[i][j] <<" ";
}
cout <<endl;
}
}
int main()
{
int arr1 [2][3] = {{1,2,3},{4,5,6}};
int arr2 [2][3] = {{1,2,3},{4,5,0}};
int arr3 [2][3] = {{1,2,0},{4,0,0}};

cout <<"The values by row in first array are: "<<endl;


outputArr(arr1);
cout <<"The values by row in second array are:"<<endl;
outputArr(arr2);
cout <<"The values by row in third array are:"<<endl;
outputArr(arr3);
return 0;
}

Output

Results & Observations:


The array concept was refined as it had been thought earlier in the first and second semester and I
understood concept behind all array types. After understanding and practicing in the lab, the lab tasks
were simple to complete.

You might also like