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

Lab 08 - Arrays and Linked List

This document provides instructions and code templates for 5 lab exercises on data structures and algorithms using C++. The exercises cover topics like calculating income tax using arrays, finding the average score and eligibility for projects using arrays, inserting elements into a linked list, counting occurrences of an element in a list, and deleting all occurrences of an element from a linked list.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Lab 08 - Arrays and Linked List

This document provides instructions and code templates for 5 lab exercises on data structures and algorithms using C++. The exercises cover topics like calculating income tax using arrays, finding the average score and eligibility for projects using arrays, inserting elements into a linked list, counting occurrences of an element in a list, and deleting all occurrences of an element from a linked list.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Department of Computer Science and Engineering

Faculty of Engineering, South Eastern University of Sri Lanka


Subject CS53003: Data Structures and Algorithms
Batch E18 Semester 5

Hands-on Lab 8 – Arrays and Linked Lists

Lab Exercise 1

Income Tax Liability

Jeff is a financial planner and, he provides various services to his clients with varying
levels of income. He wants to help families continue growing wealth while helping young
families reach their financial goals.

He calculates the income tax returns for his clients, and most of his clients have various
sources of income. To make his job easier, he needs an application to identify the income
tax liability for his single filer clients.

This application should get the no. of income sources and the income from each source
as user input and if the income from each source exceeds $9,950, then he/she is liable
to pay the tax for that income. Then the application should display the no. of taxable
income from various sources. Otherwise, a message should display, “Not liable to pay
income tax”.

Refer to the sample input and output for more clarifications.

Sample input statement 1:

Enter the no. of income sources:3

Enter the income from various sources:

390

9951

12000

Page 1 of 7
Sample output statement 1:

No. of taxable income(s): 2

Sample input statement 2:

Enter the no. of income sources:5

Enter the income from various sources:

9950

1290

9000

1500

2890

Sample output statement 2:

Not liable to pay income tax

Lab Exercise 2

Average Score

A new employee has joined a company. As part of Training, he/she is given a few
assignments. On completion of the assignments, each of them is scored. The score report
must be sent to the Team Lead. This report consists of the average score of the
assignments, and his eligibility for the project allocation. The new employee is eligible for
deployment to projects if his average score is equal to or above 80%. Write program
to generate the score report.

Note:

 The no. of assignments should be between 1 and 10. If it exceeds 10, display the
message: "No. of assignments must not be more than 10" and terminate the
Page 2 of 7
program.
 Average score should be float type
 Observe the highlighted output statements in the sample input and output
statements for more clarifications.

Sample input statement 1:


Enter no. of assignments:
8
Enter the scores:
23
89
89
96
81
78
88
97

Sample output statement 1:


The average score is 80.12
Eligible for projects

Sample input statement 2:

Enter no of assignments:
5
Enter the scores:20
56
34
67
78

Sample output statement 2:


The average score is 51.00
Not eligible for projects

Sample input statement 3:


Enter no of assignments:
11

Sample output statement 3:


No. of assignments must not be more than 10

Page 3 of 7
Lab Exercise 3

Ring Insertion

Assume that you have a curtain rod and many rings. Each ring has a number printed on
it. You need to insert the curtain rings into the rod one at a time. The user has to provide
you with the ring number that needs to be inserted into the rod. When you get a number
from the user, you need to insert the rings. The rings must be inserted from the left side
of the rod and after inserting all the rings, display the ring numbers in the rod one by one.

Implement this scenario using the data structure: Linked List.

Note:
 Observe the highlighted output statements in the sample input and output
statements for more clarifications.
 Do not change the code template given (CodeTemplate_Ex3.cpp). Write your
code in the provided places alone.

Sample input statement:


Enter the ring number:
56
Do you want to add another ring? Enter y/n
y
Enter the ring number:
12
Do you want to add another ring? Enter y/n
y
Enter the ring number:
90
Do you want to add another ring? Enter y/n
y
Enter the ring number:
45
Do you want to add another ring? Enter y/n
y
Enter the ring number:
89
Do you want to add another ring? Enter y/n
n

Page 4 of 7
Sample output statement:
The ring numbers in the rod are:
89 45 90 12 56

Lab Exercise 4

Count the List

Rose, a novice in programming, was practicing some programs in data structures and
algorithms. In a particular program, she is asked to write the logic in C++ to count the
number of occurrences of a given element from a list of numbers. Help Rose to perform
the task.

Check the sample input and output statements for clarifications.

Note:

 Observe the highlighted output statements in the sample input and output
statements for more clarifications.
 Do not change the code template given (CodeTemplate_Ex4.cpp). Write your
code in the provided places alone.

Sample input statement 1:

Enter the size of the list: 7

1723292

Sample output statement 1:

The list is: 1 7 2 3 2 9 2

Enter a number: 2

2 occurs 3 times.

Page 5 of 7
Sample input statement 2:

Enter the size of the list: 5

12345

Sample output statement 2:

The list is: 1 2 3 4 5

Enter a number: 6

6 occurs 0 times.

Lab Exercise 5

Delete All Occurrences

Given a singly linked list and an integer x, your task is to complete the function
deleteAllOccurrences() which deletes all occurrences of a key x present in the linked
list. The function takes one argument: an integer key x and the function need not return
anything.

Note:
 Define the 'Node' class with the below-mentioned public attributes:
An integer attribute with the name: 'data'
A reference to the next node with the name: 'next';
 Please include the statement '#include <cstdlib>' to deallocate/free the memory
using 'free()' method. Otherwise, use the 'delete' operator instead of 'free()' to
deallocate/free the memory.
 Observe the highlighted output statements in the sample input and output
statements for more clarifications.
 Do not change the code template given (CodeTemplate_Ex5.cpp). Write your
code in the provided places alone.

Page 6 of 7
Input:
The first line of input contains an integer N denoting the no. of elements of the linked list.
The next line is N values of the linked list.
The third line of the input is the value (integer x) to be deleted.

Output:
The elements in the list after deleting all the occurrence of the given value.

Sample input statement:


5
22144

Enter the element to be deleted: 4

Sample output statement:


The list after deletion: 2 2 1

Page 7 of 7

You might also like