Lab 08 - Arrays and Linked List
Lab 08 - Arrays and Linked List
Lab Exercise 1
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”.
390
9951
12000
Page 1 of 7
Sample output statement 1:
9950
1290
9000
1500
2890
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.
Enter no of assignments:
5
Enter the scores:20
56
34
67
78
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.
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.
Page 4 of 7
Sample output statement:
The ring numbers in the rod are:
89 45 90 12 56
Lab Exercise 4
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.
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.
1723292
Enter a number: 2
2 occurs 3 times.
Page 5 of 7
Sample input statement 2:
12345
Enter a number: 6
6 occurs 0 times.
Lab Exercise 5
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.
Page 7 of 7