Question: CODE IN C++ and Python 1. Translate this piece of Python code into C++ code: #!/usr/bin/python3 from process import Process from process_table import ProcessTable import

CODE IN C++ and Python

1. Translate this piece of Python code into C++ code:

#!/usr/bin/python3

from process import Process from process_table import ProcessTable

import json import sys

def main():

# This program should accept a single command line argument, which is the # name of the input file to use. # $ execute.py # # Check that the argument has been provided by the caller; if no argument is # given, print an error message and exit. if len(sys.argv)<2: print('error ! no argument is given') return -1 file input # read the into 'input' dict (above) see https:>

table_size = 100 # The table_size defaults to 100 if it's not provided in the input

# Handle the options element in the input. # This entry will look like this: # "options" : { # "table_size" : 3 # } # # If options.table_size is found, set the table_size to its value if "options" in input.keys(): if "table_size" in input['options'].keys(): table_size = input['options']['table_size']

# Allocate a process table using the given table size table = ProcessTable(table_size) print(table_size)

# The actions list looks like this:

# "actions" : # [{ # "action" : "add_process", # "process_name": "process1" # }, # { # "action" : "add_process", # "process_name": "process2" # }, # { # "action": "remove_process", # "process_id" : 1 # }]

# Iterate the set of actions # # For each action found, perform the requested action and print the entire # process table, followed by a blank line. # # So for the brief set of actions shown above, the output should look # like this: # # {"process_id":1,"process_name":"process1"}

# {"process_id":1,"process_name":"process1"} # {"process_id":2,"process_name":"process2"}

# {"process_id":2,"process_name":"process2"}

for action in : # Iterate all actions if : # The action is "add_process" # Add the new Process to the process table. if not table.add(action['process_name']): print('Error at adding process !') return -1 # If the add is not successful, print an error # message and exit elif : # The action is "remove_process" # Find the process ID to be removed # Call table.remove() with that process ID # If the process can not be removed, print an error message # and exit. if not table.remove(action['process_id']): print('Error at removing process !') return -1

# After executing each action, print the # process table, followed by a blank line return 0

if __name__ == "__main__": main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!