Summer 2024 - CS301P - 1

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

Assignment No.

01
Total Marks: 20
SEMESTER Summer 2024
Due Date: 26-August, 2024
CS301P- Data Structures (Practical)

Instructions
Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (zero marks) if:
o The assignment is submitted after the due date.
o The submitted code does NOT compile.
o The submitted assignment is other than .CPP file.
o The submitted assignment does NOT open or file is corrupted.
o The assignment is copied (from other student or ditto copy from handouts or internet).

Uploading instructions
For clarity and simplicity, you are required to Upload/Submit only ONE .cpp file.

Note: Use ONLY Dev-C++ IDE.

Objective
The objective of this assignment is

o To make you familiar of Programming with Linked List Data Structure.

For any query about the assignment, contact at [email protected]

GOOD LUCK
Scenario:

You are tasked with determining the topper of a class by managing a linked list that stores the names and marks
of 5 students. Each student’s name and marks are hardcoded into the linked list. The goal is to identify the student
with the highest marks (the topper). This process involves iterating through the list to compare the marks of each
student and find the one with the maximum score.

Key Components:

1. Student Class:
o Description: Represents individual students in the class. Each student object contains the student's
name and their total marks.
o Methods: Provides methods to set and get the student's name and marks.

2. Node Class:
o Description: Represents each node in the linked list. Each node contains a Student object and a
pointer to the next node in the list.

3. List Class:
o Description: Manages the linked list of nodes, handling the addition of students and finding the
topper.
o
Functions of the List Class:

a) Adding Students:

 add() Function: (Must add below values)


o This function adds a new student to the linked list.
o The student data is hardcoded into the program:
o "Ali" with 85 marks
o "Bilal" with 92 marks
o "Raza" with 78 marks
o "Asad" with 88 marks
o "Ahmad" with 95 marks
o Each student is inserted as a node in the linked list, and the list automatically updates to maintain
the sequence.

b) Finding the Topper:

 findTopper() Function:

o This function traverses the entire linked list to identify the student with the highest marks.
o The function compares each student's marks as it iterates through the list and keeps track of the
highest marks found.
o In this case, "Ahmad" with 95 marks is identified as the topper.
Sample Output: (Do not ask for input otherwise you will get 0 marks)

An output screenshot is given at the end of this file for your complete understanding and reference.

Note: You must follow the following program structure for naming and to build the program. Also, while
displaying output STUDENT OWN VUID (Replace Student List with your ID) should also be displayed as given
in Complete Sample Output Screenshot. Otherwise, you will get ZERO marks.

Program Structure:

Class: Student
Attributes:
1. string name
2. int marks
Constructor:
1. Student()
Functions:
1. getName()
2. setName(string name)
3. getMarks()
4. setMarks(int marks)

Class: Node
Attributes:
1. Student object
2. Node* nextNode
Constructor:
1. Node()
Functions:
1. get()
2. set(Student object)
3. getNext()
4. setNext(Node* nextNode)

Class: List
Attributes:
1. Node* headNode
2. Node* currentNode
3. int size
Constructor:
1. List()
Destructor:
1. ~List() (Not implemented, but can be added if needed)
Functions:
1. add(Student addObject)
2. findTopper()
3. displayStudents()
4. next()
5. get()

Default Function: main()


Operations:
1. Creates instances of Student.
2. Adds students to the List using the add() function.
3. Displays all students using the displayStudents() function.
4. Finds and displays the topper using the findTopper() function.

Lectures Covered: This assignment covers Lab # 1. (First three lectures of CS301).
Deadline: Your assignment must be uploaded/submitted at or before, 26 August 2024.

You might also like