#include  #include  #include  #include  #include  #include

#include #include #include #incl

#include
#include
#include
#include
#include
#include "proc.h"
#include "rq.h"

using namespace std;


// creates a vector of Queues
void load_queue(vector &queue, unsigned int num_of_queues)
{
for(int pos=0; pos queue_size)
{
queue_pos = pos;
queue_size = queues.at(pos).size();
}
}
return queue_pos; // Return smaller queue position in vector.
}



// Returns the smaller queue position in the vector.
unsigned int get_smaller_queue_pos(vector queues)
{
unsigned int queue_pos = 0; // Pos of smaller queue. Default 0.
unsigned int queue_size = queues.at(queue_pos).size(); // Its size
for(unsigned int pos = 0; pos < queues.size(); pos++)
{
if(queues.at(pos).size() < queue_size)
{
queue_pos = pos;
queue_size = queues.at(pos).size();
}
}
return queue_pos; // Return smaller queue position in vector.
}

//Searches for a PID in entire system and erases it.
bool get_pid_process(vector &queue, int id)
{
vector temp;
proc process(0,0,0);
int check;
int number=id;
int size=queue.size();

/*checks rest of queues, including ready queues and device queues*/
for(int i=0; i
0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
#include #include #include #include #include #include "proc.h" #include "rq.h" using namespace std; // creates a vector of Queues void load_queue(vector &queue, unsigned int num_of_queues) { for(int pos=0; pos { queue.push_back(rq()); } } //returns the biggest queue position in the vector unsigned int get_biggest_queue_pos(vector queues) { unsigned int queue_pos = 0; // Pos of smaller queue. Default 0. unsigned int queue_size = queues.at(queue_pos).size(); // Its size for(unsigned int pos = 0; pos < queues.size(); pos++) { if(queues.at(pos).size() > queue_size) { queue_pos = pos; queue_size = queues.at(pos).size(); } } return queue_pos; // Return smaller queue position in vector. } // Returns the smaller queue position in the vector. unsigned int get_smaller_queue_pos(vector queues) { unsigned int queue_pos = 0; // Pos of smaller queue. Default 0. unsigned int queue_size = queues.at(queue_pos).size(); // Its size for(unsigned int pos = 0; pos < queues.size(); pos++) { if(queues.at(pos).size() < queue_size) { queue_pos = pos; queue_size = queues.at(pos).size(); } } return queue_pos; // Return smaller queue position in vector. } //Searches for a PID in entire system and erases it. bool get_pid_process(vector &queue, int id) { vector temp; proc process(0,0,0); int check; int number=id; int size=queue.size(); /*checks rest of queues, including ready queues and device queues*/ for(int i=0; i { temp=queue[i].get_queue(); int size1=temp.size(); for(int j=0; j { process=temp.at(j); check=process.get_pid(); if(check==number) { cout<<"Process found in a queue and being erased..."< queue[i].remove_process(j); float cputime=process.get_burst(); float burstime=process.get_average(); cout<<"Process information:"< cout<<"PID: "< cout<<"Process killed"< return true; } } } /*Checks all CPUs in ready queues*/ for(int k=0; k { temp=queue[k].get_cpu(); process=temp.front(); check=process.get_pid(); if(check==number) { cout<<"Process found in a CPU and being erased..."< float cputime=process.get_burst(); float burstime=process.get_average(); queue[k].clear_cpu(); cout<<"Process information:"< cout<<"PID: "< cout<<"Process killed"< return true;//ends if PID is found in CPU and returns true } } return false; } int main() { cout << "Sys gen starting..."< cout<<"Please enter the amount of CPUs (between 1 and 9)"< int cpu; cin>>cpu; while(cpu<1 || cpu>9) { cout<<"Invalid value, please re-enter amount:"< cin>>cpu; } cout<<"Enter amount of PRINTERs:"< int pr; cin>>pr; cout<<"Enter amount of DISKs:"< int di; cin>>di; cout<<"Enter amount of CD/RWs:"< int cd; cin>>cd; int devices=(cpu*2)+pr+di+cd;//amount of devices(queues and CPU's) int PID=0; int PCB=0; vector RQ; //vector of ready queues vector PQ; //vector of printer queues vector DQ; //vector of disk queues vector CQ; //vector of CD/RW queues load_queue(RQ, cpu); load_queue(PQ, pr); //load printer queues to PQ vector load_queue(DQ, di); // ... load_queue(CQ, cd); // ... cout << "Running section..." < cout<<"Start inputting commands; To terminate program press E or e at any time:"< while(true) { string device;//for name of device string enter;//for input cin>>enter; int correspond=0; int smaller; char num11=enter[0];//1st position character char input=enter[1];//2nd position char char num=enter[2];//3rd position char int num1=num11 -'0';//1st position integer int n=num -'0';//3rd position int int inp=input - '0';//2nd position int int empty; /*creates a new process and puts it into emptiest Ready Queue*/ if(num11=='A') { smaller=get_smaller_queue_pos(RQ); //determines which ready queue has less processes RQ[smaller].create_process(smaller, PID, PCB); PID++; PCB++; if(RQ[smaller].get_cpu().size() == 0) { RQ[smaller].cpu(); } } /*terminates a process from a particular CPU*/ else if(input=='t') { if(num1>0 && num1<=cpu) { RQ[num1-1].terminate(); PCB--; RQ[num1-1].cpu(); } else { cout<<"Invalid entry"< } } /*Prints out a snapshot of a particular device Q or the ready queues*/ else if(num11 == 'S') { cout << "Select a queue: "< char sele; cin >> sele; switch(sele) { case 'p': if(pr==0) { cout<<"There are no printer queues created."< } else { device="Printer"; cout<<"A snapshot of your "< for(int i = 0; i < PQ.size(); i++) { cout< PQ.at(i).snapshot(device); } } break; case 'r': cout< for(int i = 0; i < RQ.size(); i++) { cout<<"Ready queue "< RQ[i].snapshot(); } break; case 'd': if(di==0) { cout<<"There are no disk queues created."< } else { device="Disk"; cout<<"A snapshot of your "< for(int i = 0; i < PQ.size(); i++) { cout< DQ.at(i).snapshot(device); } } break; case 'c': if(cd==0) { cout<<"There are no cd/rw queues created."< } else { device="Cd/rw"; cout<<"A snapshot of your "< for(int i = 0; i < PQ.size(); i++) { cout< CQ.at(i).snapshot(device);
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!
#bao gồm
#bao gồm
#bao gồm
#bao gồm
#bao gồm
#include "proc.h"
#include "rq.h" using namespace std; // tạo ra một vector của Queues trống load_queue (vector





xếp hàng, num_of_queues int unsigned)
{for (int pos = 0; pos
{Queue.push_back (RQ ());}} // trả về vị trí hàng đợi lớn nhất trong vector unsigned int get_biggest_queue_pos (vector





hàng đợi)
{unsigned int queue_pos = 0;
// Pos của hàng đợi nhỏ hơn. Mặc định 0.
unsigned int queue_size = queues.at (queue_pos) .size (); // Kích thước của nó
cho (unsigned int pos = 0; pos <queues.size (); pos ++)
{if (queues.at (pos) .size ()> queue_size) {queue_pos = pos; queue_size = queues.at (pos ) .size ();}} queue_pos trở lại; // Return vị trí hàng đợi nhỏ trong vector.} // Trả về vị trí hàng đợi nhỏ hơn trong các vector. Get_smaller_queue_pos int unsigned (vector












hàng đợi)
{unsigned int queue_pos = 0;
// Pos của hàng đợi nhỏ hơn. Mặc định 0.
unsigned int queue_size = queues.at (queue_pos) .size (); // Kích thước của nó
cho (unsigned int pos = 0; pos <queues.size (); pos ++)
{if (queues.at (pos) .size () <queue_size) {queue_pos = pos; queue_size = queues.at (pos ) .size ();}} queue_pos trở lại; // Return vị trí hàng đợi nhỏ trong vector.} // Tìm kiếm cho một PID trong toàn bộ hệ thống và xóa nó. Bool get_pid_process (vector










xếp hàng, int id) {vector

; tạm
quá trình proc (0,0,0);
int séc;
int number = id;
int size = queue.size (); / * kiểm tra phần còn lại của hàng đợi, bao gồm hàng đợi sẵn sàng và hàng đợi thiết bị * / for (int i = 0 ; tôi


{Temp = queue [i] .get_queue (); int size1 = temp.size (); for (int j = 0; j


{Quá trình = temp.at (j); kiểm tra = process.get_pid (); if (check == số) {cout << "Process tìm thấy trong hàng đợi và bị xoá hoàn toàn ..." <




xếp hàng [i] .remove_process (j);
nổi cputime = process.get_burst ();
float burstime = process.get_average ();
cout << "Xử lý thông tin:" < cout << "PID:" < cout << "Quy trình giết" <return true;}}} / * Kiểm tra tất cả các CPU trong hàng đợi sẵn sàng * / for (int k = 0; k





{
temp=queue[k].get_cpu();
process=temp.front();
check=process.get_pid();
if(check==number)
{
cout<<"Process được tìm thấy trong một CPU và bị xoá hoàn toàn ... "<nổi cputime = process.get_burst ();
float burstime = process.get_average ();
queue [k] .clear_cpu ();
cout << "Xử lý thông tin:" < cout << "PID:" < cout << "Quy trình giết" <return true; // kết thúc nếu PID được tìm thấy trong CPU và trả về true}} return false;} int main () {cout << "Sys gen bắt đầu ..." <







cout << "Hãy nhập số lượng CPU (từ 1 đến 9)" <int cpu;
cin >> cpu;
while (cpu <1 || cpu> 9)
{cout << "giá trị không hợp lệ, vui lòng nhập lại số tiền:" <
cin >>
cpu;} cout << "Nhập số tiền của máy in:" <

int pr;
cin >> pr;
cout << "Nhập số lượng đĩa:" <int di;
cin >> di;
cout << "Nhập số tiền của CD / RW:" <int cd;
cin >> cd;
int thiết bị = (cpu * 2) + pr + di + cd; // số lượng thiết bị (hàng đợi và CPU)
int PID = 0;
int PCB = 0;
vectorRQ; // vector của hàng đợi sẵn sàng
vectorPQ; // vector của hàng đợi máy in
vectorDQ; // vector của hàng đợi đĩa
vectorCQ; // vector của CD / RW hàng đợi load_queue (RQ, cpu); load_queue (PQ, pr); // hàng đợi máy in tải đến PQ vector load_queue (DQ, di); // ... Load_queue (CQ, cd); // ... Cout << "Chạy phần ..." <







cout << "Bắt đầu nhập vào các lệnh; Để chấm dứt chương trình báo chí E hoặc e bất cứ lúc nào:" <while (true)
{thiết bị string; // cho tên của thiết bị chuỗi nhập; // cho đầu vào cin >> nhập; int tương ứng = 0; int nhỏ; char num11 = nhập [0]; // 1 nhân vật vị trí char đầu vào = nhập [1]; // 2 vị trí char char num = nhập [2]; // 3 vị trí char int num1 = num11 -'0 '; // 1 vị trí số nguyên int n = num -'0'; // vị trí thứ 3 int int inp = input - '0'; // vị trí thứ 2 int int trống; / * tạo ra một quy trình mới và đặt nó vào Ready Queue vắng * / if (num11 == 'A') {nhỏ = get_smaller_queue_pos (RQ); // xác định hàng đợi sẵn sàng có các quy trình ít RQ [nhỏ] .create_process (nhỏ hơn, PID, PCB); PID ++; PCB ++; if (. RQ [nhỏ] .get_cpu () size () == 0) {RQ [nhỏ] .cpu ();}} / * kết thúc một quá trình từ một CPU cụ thể * / else if (input == 't') {if (num1> 0 && num1 <= cpu) {RQ [num1-1] .terminate ( ); PCB--; RQ [num1-1] .cpu ();} khác {cout << "entry không hợp lệ" <






































}} / * In ra một bản chụp của một thiết bị Q cụ thể hoặc các hàng đợi sẵn sàng * / else if (num11 == 'S') {cout << "Chọn một hàng đợi:" <




char SELE;
cin >> SELE;
switch (SELE)
{case 'p': if (pr == 0) {cout << "Không có hàng đợi máy in tạo ra." <



}
Khác
{device = "Máy in"; cout << "Một ảnh chụp của bạn" <

for (int i = 0; i <PQ.size (); i ++)
{cout <
PQ.at (i) .snapshot (thiết bị);}} break; case 'r': cout <




for (int i = 0; i <RQ.size (); i ++)
{cout << "hàng đợi Ready" <
RQ [i] .snapshot
();}
break;
case 'd':
if (di == 0)
{cout << ". Không có hàng đợi đĩa tạo" <
}
Khác
{device = "Disk"; cout << "Một ảnh chụp của bạn" <

for (int i = 0; i <PQ.size (); i ++)
{cout <
DQ.at (i) .snapshot (thiết bị);}} break; case 'c': if (cd == 0) {cout << ". Không có cd / hàng đợi rw tạo" <






}
Khác
{device = "Cd / rw"; cout << "Một ảnh chụp của bạn" <

for (int i = 0; i <PQ.size (); i ++)
{cout <
CQ.at (i) .snapshot (thiết bị);
đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2025 I Love Translation. All reserved.

E-mail: