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

DSA Lab Report 2

The document is a lab report on data structures and algorithms submitted by a student. It discusses arrays in C++, including declaring and initializing arrays. It also details two tasks - writing a program to multiply 3x3 matrices and showing the code and output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

DSA Lab Report 2

The document is a lab report on data structures and algorithms submitted by a student. It discusses arrays in C++, including declaring and initializing arrays. It also details two tasks - writing a program to multiply 3x3 matrices and showing the code and output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

NATIONAL UNIVERSITY OF TECHNOLOGY

COMPUTER ENGINEERING DEPARTMENT

LAB REPORT NO 2

DATA STRUCTURE AND ALGORITHM

CEN 2019

Submitted By: MUDASSIR HUSSAIN

NUTECH ID: F22604036

Submitted To: Engr. Rafi-Ul-Zaman

Date of Submission: 20-03-2024


`

OBJECTIVE:
• To understand how to declare, initialize and access arrays
• To Implement Arrays in C++

Arrays

Arrays are like structures in that they both group a number of items into a larger unit. But
while a structure usually groups items of different types, an array groups items of the same
type. More importantly, the items in a structure are accessed by name, while those in an
array are accessed by an index number.

Using an index number to specify an item allows easy access to a large number of items.
Arrays exist in almost every computer language. Arrays in C++ are similar to those in other
languages, and identical to those in C. The use of arrays may allow us to simplify our
processing. We can use arrays to help read and analyze repetitive data with a minimum of
coding. An array and a loop can make the program smaller.

It is learned that Arrays contain a number of data items of the same type. This type can be a
simple data type, a structure, or a class. The items in an array are called elements In C++, an
array is a variable that can store multiple values of the same type. For example, suppose a
class has 27 students, and we need to store the grades of all of them. Instead of creating 27
separate variables, we can simply create an array: double grade[27];

Declaring Arrays

To declare an array in C++, the programmer specifies the type of the elements and the
number of elements required by an array as follows:

1. type arrayName [ arraySize ];

This is called a single-dimension array. The arraySize must be an integer constant greater

than zero and type can be any valid C++ data type. For example, to declare a 10element

array called balance of type double, use this statement:

2. double balance[10];

2
`

Lab Tasks:

Task 1:

1. Write a program to multiply 3x3 matrix.

Code

3
`

Console

4
`

Code

5
`

Console

Conclusion:

The first program demonstrates the creation and management of a student database using
C++ structures. It provides functionalities for adding students, displaying information for a
specific student, and calculating the average GPA of all students. The program incorporates
error handling to ensure valid user input and prevent unexpected behavior.

The second program showcases matrix multiplication in C++. It defines a function to multiply two
3x3 matrices and stores the result in a separate matrix. The program allows the user to enter the
elements of both matrices and displays the resulting product matrix.

You might also like