Assignment 1
Assignment 1
Course: CC-213 + Data Structures and Algorithms Instructor: Dr. Saad Ahmad Khan
Assignment: 1st Date: 18th July, 2024 Submission Date: 24th July, 2024
Class: BSCS + BSIT (M) Semester: 4th Total Marks: 15
Name: Roll Number:
Submission Guidelines:
1. Make a .cpp file and name it according to your roll number, i.e., BXX22YYY.cpp. Here, XX is defined
as CS or IT and YYY is defined as your roll number. For example: BCS22001.cpp
2. Create an email and attach the cpp file with it. The subject of the email must be your roll number.
3. Now, BCS students will send it to [email protected] and BIT students will send to
[email protected].
Question:
Today, you will implement the Stack class as a template class and verify it using a user-defined class
Student.
public:
Stack() {…} //constructor to initialize all the required data members
Stack(int size) {…} //constructor to initialize all the required data members
bool push (S element) {…} //add the element S in the stack and if stack is full,
then add 5 new locations to it
S top () {…} //return the top of the stack without removing it from stack
S pop () {…} //return the top of the stack and also remove it from stack.
If stack is empty return default object
int totalElements () {…} //return the total number of elements from the stack
void display() {…} //display all the elements of the stack from bottom to top
~Stack() {…} //delete the allocated memory from heap
};
class Student {
private:
string name;
string rollNo;
int semester;
double cgpa;
public:
Student(){
name = "-";
rollNo = "-";
semester = -1;
cgpa = -1.0;
}
Student(string name, string rollNo, int semester, double cgpa) {
this->name = name;
this->rollNo = rollNo;
University of the Punjab, Gujranwala Campus
Department of Information Technology, Spring 2022
this->semester = semester;
this->cgpa = cgpa;
}
void display() {
cout << "Name: " << name << ", Roll Number: " << rollNo << ", CGPA: " << cgpa
<< ", Current Semester: " << semester << endl;
}
};
Stack<Student> s(2);