-
Notifications
You must be signed in to change notification settings - Fork 0
/
studentReg.cpp
59 lines (44 loc) · 1.25 KB
/
studentReg.cpp
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
//student coming one by one on cash counter we need to calculate the dues and deposit the cash
//balance amt input krana h
//paid amount
#include <iostream>
#include <queue>
using namespace std;
class Student {
public:
string name;
int dues;
Student(string name, int dues) {
this->name = name;
this->dues = dues;
}
};
class Cashier {
public:
queue<Student> studentQueue;
int totalCashCollected;
Cashier() {
totalCashCollected = 0;
}
void addStudent(string name, int dues) {
studentQueue.push(Student(name, dues));
}
void serveStudents() {
while (!studentQueue.empty()) {
Student student = studentQueue.front();
studentQueue.pop();
cout << "Student " << student.name << " needs to pay $" << student.dues << "." << endl;
cout << "Student " << student.name << " paid $" << student.dues << "." << endl;
totalCashCollected += student.dues;
}
cout << "Total cash collected: $" << totalCashCollected << endl;
}
};
int main() {
Cashier cashier;
cashier.addStudent("Alice", 10);
cashier.addStudent("Bob", 15);
cashier.addStudent("Charlie", 20);
cashier.serveStudents();
return 0;
}