Question: convert this python to c class Task: def __init__(self, name, priority, burst_time): self.task_name = name self.task_priority = priority self.task_burst_time = burst_time # sorting function for
convert this python to c

class Task:
def __init__(self, name, priority, burst_time): self.task_name = name self.task_priority = priority self.task_burst_time = burst_time
# sorting function for task_list according to burst time as in SJF def sort_fun(task): return task.task_burst_time
input_file_path = input("Please enter the path of the input file.") output_file_path = input("Please enter the path of the output file.")
try: input_file = open(input_file_path, "r") # opens the input file in read mode except IOError: print("Error! Invalid input file path provided.") exit(0)
output_file = open(output_file_path, "w") # opens the output file in write mode
task_list = [] # a list that stores all tasks for each_entry in input_file: name, priority, burst_time = each_entry.split(", ")
# construct an object of class Task and append to the task_list task_list.append(Task(name, int(priority), int(burst_time)))
task_list.sort(key=sort_fun) # sort task_list according to burst time
task_start_time = 0 # stores the starting time for the task for each_task in task_list: output_file.write(each_task.task_name + ", " + str(task_start_time) + ", " + str(each_task.task_burst_time) + " ") task_start_time = task_start_time + each_task.task_burst_time
1 # SJF (non premptive) 2 3 # task object will store the task attributes 4 class Task: 5 6 def _init__(self, name, priority, burst_time) : 7 self.task_name = name 8 self.task_priority = priority 9 self.task_burst_time = burst_time 10 11 12 # sorting function for task_list according to burst time as in SJF 13 def sort_fun (task) : 14 return task.task_burst_time 15 16 input_file_path = input ("Please enter the path of the input file.") 17 output_file_path = input ("Please enter the path of the output file.") 18 19 try: input_file = open (input_file_path, "r") # opens the input file in read mode 21 except IOError: 22 print("Error! Invalid input file path provided.") 23 exit(0) 24 25 output_file = open (output_file_path, "w") # opens the output file in write mode 20 C 27 28 29 30 31 32 33 34 35 36 37 38 39 an task_list = ua list that stores all tasks for each_entry in input_file: name, priority, burst_time = each_entry.split(", ") + construct an object of class Task and append to the task_list task_list.append(Task (name, int (priority), int(burst_time))) task_list.sort (key=sort_fun) + sort task_list according to burst time task_start_time=0 stores the starting time for the task for each_task in task_list: output_file.write(each_task.task_name + ", + str (task_start_time) task_start_time = task_start_time + each_task.task_burst_time str(each_task.task_burst_time) + " ") 1 # SJF (non premptive) 2 3 # task object will store the task attributes 4 class Task: 5 6 def _init__(self, name, priority, burst_time) : 7 self.task_name = name 8 self.task_priority = priority 9 self.task_burst_time = burst_time 10 11 12 # sorting function for task_list according to burst time as in SJF 13 def sort_fun (task) : 14 return task.task_burst_time 15 16 input_file_path = input ("Please enter the path of the input file.") 17 output_file_path = input ("Please enter the path of the output file.") 18 19 try: input_file = open (input_file_path, "r") # opens the input file in read mode 21 except IOError: 22 print("Error! Invalid input file path provided.") 23 exit(0) 24 25 output_file = open (output_file_path, "w") # opens the output file in write mode 20 C 27 28 29 30 31 32 33 34 35 36 37 38 39 an task_list = ua list that stores all tasks for each_entry in input_file: name, priority, burst_time = each_entry.split(", ") + construct an object of class Task and append to the task_list task_list.append(Task (name, int (priority), int(burst_time))) task_list.sort (key=sort_fun) + sort task_list according to burst time task_start_time=0 stores the starting time for the task for each_task in task_list: output_file.write(each_task.task_name + ", + str (task_start_time) task_start_time = task_start_time + each_task.task_burst_time str(each_task.task_burst_time) + " ")
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
