The counter desk of a school wants to keep the people in the queue not more than 5 at one
time. Make a system in c++ which adds students to the queue based on their roll numbers. As
soon as the count reaches 5, any new person isn’t allowed to stand in the queue.
The program should display that “No new student is allowed to stand in the queue”
However, as soon as a student from the queue of 5 people is done with his registration, the
program allows one more student to stand in the queue.
#include<iostream>
#include<queue>
using namespace std;
int main(){
queue<int> registration;
cout<<"Student will go for the registration as per their roll number"<<endl;
registration.push(1);
registration.push(2);
registration.push(3);
registration.push(4);
registration.push(5);
registration.push(6);
while (!registration.empty()) {
//if(registration.)
if(registration.size()<6){
cout << ' ' << registration.front();
//registration.pop();
}else{
cout<<"wait!, student capacity increased"<<endl;
}
registration.pop();
}
return 0;
}
Comments
Leave a comment