classdef Process properties pid burst_time priority waiting_time turnaround_time end methods function obj = Process(pid, burst_time, priority) obj.pid = pid; obj.burst_time = burst_time; obj.priority = priority; obj.waiting_time = 0; obj.turnaround_time = 0; end end end classdef ListClass methods function insert_node_MQAPS(obj, process) % Insert process into the list % Implementation omitted for brevity end function delete_node_MQAPS(obj, process) % Delete process from the list % Implementation omitted for brevity end function [process, arrival_time] = select_process_from_queue_MQAPS(obj) % Select process from the queue based on priority and execution history % Implementation omitted for brevity end function time_quantum = time_quantum_MQAPS(obj, process) % Compute time quantum for the process % Implementation omitted for brevity end function execute_process_MQAPS(obj, process, time_quantum) % Execute process for specified time quantum % Implementation omitted for brevity end function [waiting_time, turnaround_time] = return_time_MQAPS(obj, process) % Calculate waiting and turnaround time % Implementation omitted for brevity end end end classdef MQAPS_Simulator properties list_class total_waiting_time total_turnaround_time total_processes context_switch_count end methods function obj = MQAPS_Simulator() obj.list_class = ListClass(); obj.total_waiting_time = 0; obj.total_turnaround_time = 0; obj.total_processes = 0; obj.context_switch_count = 0; end function simulate(obj) % Simulate MQAPS system while true [process, ~] = obj.list_class.select_process_from_queue_MQAPS(); if isempty(process) break; end time_quantum = obj.list_class.time_quantum_MQAPS(process); obj.list_class.execute_process_MQAPS(process, time_quantum); [waiting_time, turnaround_time] = obj.list_class.return_time_MQAPS(process); obj.total_waiting_time = obj.total_waiting_time + waiting_time; obj.total_turnaround_time = obj.total_turnaround_time + turnaround_time; obj.total_processes = obj.total_processes + 1; obj.list_class.delete_node_MQAPS(process); obj.context_switch_count = obj.context_switch_count + 1; end end function [avg_waiting_time, avg_turnaround_time] = calculate_averages(obj) % Calculate average waiting and turnaround time avg_waiting_time = obj.total_waiting_time / obj.total_processes; avg_turnaround_time = obj.total_turnaround_time / obj.total_processes; end function context_switch_count = get_context_switch_count(obj) % Get the total number of context switches context_switch_count = obj.context_switch_count; end end end % Example usage: simulator = MQAPS_Simulator(); % Insert processes into the list_class % Implementation omitted for brevity simulator.simulate(); [avg_waiting_time, avg_turnaround_time] = simulator.calculate_averages(); disp(['Average Waiting Time: ', num2str(avg_waiting_time)]); disp(['Average Turnaround Time: ', num2str(avg_turnaround_time)]); disp(['Context Switch Count: ', num2str(simulator.get_context_switch_count())]);