Lab Report 1
Lab Report 1
Lab Report 1
Lab Report: 01
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;
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
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;
Output
Lab Task 04: Programthat will print multi-subscripted array as shown below using function
printArray()..
Code
#include <iostream>
using namespace std;
Output