0% found this document useful (0 votes)
9 views

bai2

Code java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

bai2

Code java
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <list>
#include <string>

using namespace std;

struct SinhVien {
int id;
string ten;
};

class Queue {
private:
list<SinhVien> data;

public:
void enqueue(SinhVien sv) {
data.push_back(sv);
}

void dequeue() {
if (isEmpty()) {
cout << "Hàng d?i tr?ng!" << endl;
return;
}
data.pop_front();
}

bool isEmpty() {
return data.empty();
}

void printQueue() {
if (isEmpty()) {
cout << "Hàng d?i tr?ng!" << endl;
return;
}

// Use traditional 'for' loop for C++98 compatibility


for (list<SinhVien>::iterator it = data.begin(); it != data.end(); ++it) {
cout << "ID: " << it->id << ", Tên: " << it->ten << endl;
}
}
};

int main() {
Queue queue;
int choice, n, id;
string ten;

do {
cout << "\nMenu:" << endl;
cout << "1. Thêm sinh viên" << endl;
cout << "2. Xóa sinh viên" << endl;
cout << "3. In danh sách sinh viên" << endl;
cout << "4. Thoát" << endl;
cout << "Ch?n ch?c nang: ";
cin >> choice;
switch (choice) {
case 1:
cout << "Nh?p s? lu?ng sinh viên mu?n thêm: ";
cin >> n;
for (int i = 0; i < n; ++i) {
cout << "Nh?p ID sinh viên th? " << i + 1 << ": ";
cin >> id;
cout << "Nh?p tên sinh viên th? " << i + 1 << ": ";
cin >> ten;
SinhVien sv = {id, ten};
queue.enqueue(sv);
}
break;
case 2:
queue.dequeue();
break;
case 3:
queue.printQueue();
break;
case 4:
break;
default:
cout << "L?a ch?n không h?p l?!" << endl;
}
} while (choice != 4);

return 0;
}

You might also like