0% found this document useful (0 votes)
15 views4 pages

Lab 1

The document outlines a lab assignment for a Data Structures course at the National University of Computer & Emerging Sciences, focusing on arrays, pointers, dynamic memory allocation, and object-oriented programming. It includes specific programming tasks such as sorting and searching arrays, finding common elements, using dynamic arrays, and creating a Library Management System using classes. Students are instructed to follow coding standards, document their code, and submit their work in a specified format by the deadline.

Uploaded by

f243019
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)
15 views4 pages

Lab 1

The document outlines a lab assignment for a Data Structures course at the National University of Computer & Emerging Sciences, focusing on arrays, pointers, dynamic memory allocation, and object-oriented programming. It includes specific programming tasks such as sorting and searching arrays, finding common elements, using dynamic arrays, and creating a Library Management System using classes. Students are instructed to follow coding standards, document their code, and submit their work in a specified format by the deadline.

Uploaded by

f243019
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

​​ ​ National University​

Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

CL-2001
Data Structures
Lab # 1
Objectives:
●​ Arrays
a.​ Insertion
b.​ Searching
c.​ Sorting
●​ Pointers
●​ Pointer to Function
●​ DMA

Note: Carefully read the following instructions (Each instruction contains a weightage)

1.​ There must be a block of comments at start of every question's code by students; the block
should contain brief description about functionality of code.
2.​ Comment on every function about its functionality.
3.​ Use understandable name of variables.
4.​ Proper indentation of code is essential.
5.​ Make separate .cpp files for all tasks and use this format 23F-1234_Task1.cpp.
6.​ First think about statement problems and then write/draw your logic on copy.
7.​ After copy pencil work, code the problem statement on C++ compiler.
8.​ Make a Microsoft Word file and paste all of your C++ code with all possible screenshots of
every task output in MS word and submit .cpp file with word file.
9.​ Please submit your file in this format 23F-1234_L1.
10.​Do not submit your assignment after the deadline.
11.​Do not copy code from any source otherwise you will be penalized with negative
marks.
​​ ​ National University​

Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

Problem: 1 |

Write a program that takes 10 numbers as input, the number must be of three digits ranging
between 100 to 999 in a random order. Write a C++ program to store the numbers in array
name numArray[]. Write a function

1.​ Sort() Sort the array in an ascending order


2.​ Search() Find specific value and return it.

Problem: 2 |

Implement a function that finds common elements in two arrays. You can assume that the sets
are stored using arrays. So if array1 = {1,2,3,4,5,6,3,2} and array2 is {1,3,5,7}, then array3 should
be {1,3,5}. Note array3 should not have any duplicate elements. You have to:

●​ Think of all the functions that are required for this problem. Each function should
perform its dedicated task. So plan them out before implementing them.
●​ Main should only have a set of function calls
Problem: 3 |

Use a new keyword to make floPtr point to a dynamic array of 10 cells of type float. Write a
loop to fill floPtr with user define values. Using Print function to print values stored in floPtr.
Also store the number in text file using floPtr.
Problem: 4 |

Write a C++ program where you have two integer variables


int firstvalue = 5, secondvalue = 15;
and four pointers
int * p1, * p2, **p3, **p4;
Use p3 and p4 to store the address of p1 and p2
You have to perform the following steps
• // p1 = address of firstvalue
• // p2 = address of secondvalue
• // p3 = address of firstpointrer
• // p4 = address of secondpointer
• // value pointed by p1 = 10

Page 2
​​ ​ National University​

Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

• // value pointed by p2 = value pointed by p1


• // p1 = p2 (address of pointer is copied or not)
• // p3 =p4 (check address of pointer is copied or not)
• // value pointed by p1 = 20
• // print firstvalue, secondvalue
And comment like above after each step. Also write a function by passing pointer
primaryCheck() that returns true if sum of firstvalue and secondvalue is prime otherwise return
false.
Problem: 4 |

Write a C++ program to build a matrix that has a different number of elements in each row
(different Number of columns in each row) using a two-dimensional dynamic array.
Your program must contain two functions. One for filling the elements into your
two-dimensional array and other for printing that array or matrix.
Example:
12345
234
12345678
23
Problem: 5 |

Design a simple C++ program to simulate a Library Management System. Use Object-Oriented
Programming (OOP) principles to accomplish the following tasks:

1.​ Create a class named Book with the following private attributes.

●​ bookID (integer)
●​ title (string)
●​ author (string)
●​ isAvailable (boolean, initialized to true)

2.​ Implement the following member functions in the Book class.

●​ A parameterized constructor to initialize all attributes of the book.


●​ A displayBook() function to print the book’s details.
●​ A borrowBook() function that changes isAvailable to false if the book is
available; otherwise, display an appropriate message.

Page 3
​​ ​ National University​

Of Computer & Emerging Sciences Faisalabad-Chiniot Campus

●​ A returnBook() function that changes isAvailable to true.

3.​ Create a class named Library that contains the following.

●​ A dynamic array of Book objects.


●​ A member function addBook() to add a new book to the library.
●​ A member function searchBook() that takes a bookID as input and returns the
book’s details if it exists; otherwise, displays a message that the book is not
found.
●​ A member function displayAllBooks() that lists all the books in the library.

4.​ Write a main() function that does the following.

●​ Creates an instance of the Library class.


●​ Adds at least 5 books to the library.
●​ Allows the user to interact with the library system by borrowing, returning,
and searching for books.

Page 4

You might also like