-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab#08__Farhanulhaq.cpp
More file actions
78 lines (74 loc) · 1.6 KB
/
Copy pathLab#08__Farhanulhaq.cpp
File metadata and controls
78 lines (74 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <string>
using namespace std;
class Student {
private:
int regno;
string name;
float cgpa;
public:
Student():regno(0),name(""),cgpa(0.0) {}
void input()
{
cout << "Enter Registration No: ";
cin >> regno;
cout << "Enter Name: ";
cin.ignore();
getline(cin,name);
cout << "Enter CGPA: ";
cin >> cgpa;
}
void output() const {
cout<<"Registration No: "<<regno<<",Name: " <<name<<",CGPA: "<<cgpa<<endl;
}
};
class Stack
{
private:
Student* arr;
int top;
int size;
public:
Stack(int n):size(n),top(-1) {
arr=new Student[size];
}
~Stack()
{
delete[] arr;
}
void push() {
if (top >= size - 1) {
cout << "Stack Overflow!" << endl;
return;
}
Student s;
s.input();
arr[++top] = s;
}
void pop() {
if (top < 0) {
cout << "Stack Underflow!" << endl;
return;
}
arr[top--].output();
}
};
int main()
{
int n;
cout<<"Enter the size of the stack: ";
cin>>n;
Stack stack(n);
int choice;
do {
cout<<"1.Push Student\n2.Pop Student\n3. Exit\nEnter choice: ";
cin>>choice;
switch (choice) {
case 1: stack.push(); break;
case 2: stack.pop(); break;
case 3: cout<<"Exiting..."<<endl;break;
default: cout<<"Invalid choice!" << endl;
}
} while (choice !=3);
return 0;
}