Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For each problem below, provide a link to your replit code for submittal. The Printout should loke like the following: Complete the following problems below:
For each problem below, provide a link to your replit code for submittal. The Printout should loke like the following:
Complete the following problems below: in Python
Suppose that tree T contains the organizational structure of a project, where each node represents a member of the developing team. You need to write a program that generates a list of permissions for a file. A new userdefined data type fileobject has two lists: fileobject.writers that records who has the authorization to write the content of the file and fileobject.readers that records who has authorization to only read the content. When a new fileobject is created by a team member with createnewfile, node only the creator node and its parent should have write permission and all persons to whom the creator responds must have permission to read the file. Write a routine to set the permissions correctly. Suppose the new file is simply created by using createnewfilenewfileLO
################################### ############################################################################
Below are example code and example printouts expected. You will need to edit these section of the provided code:
Function to print permissions for a file
Function to print organization chart and permissions
In both the provided Python and C codes, we're not using any external libraries. However, we are using a few builtin functionalities and standard library features:
Recursion: Both languages use recursion to traverse the tree structure.
Function: We define functions to encapsulate certain actions, such as creating new file objects, setting permissions, printing permissions, and printing the organization chart.
Standard Output: Both languages use standard output std::cout in C and print in Python to display the output on the console.
Containers: Both languages utilize standard containers std::vector in C and list in Python to store child nodes, writers, and readers.
In both implementations, the traverse function recursively visits each node and its children, performing the desired action at each node. This recursive approach is characteristic of depthfirst traversal, where all the descendants of a node are explored before moving to the next sibling.
class TreeNode:
def initself data:
self.data data
self.children # List to store child nodes
self.parent None # Reference to the parent node
self.file None # File object associated with the node
class FileObject:
def initself:
self.writers # List of nodes with write permission
self.readers # List of nodes with read permission
def createnewfilenewfile, node:
# Set permissions for writers
newfile.writers.appendnode
if node.parent:
newfile.writers.appendnodeparent
# Set permissions for readers
for child in node.children:
newfile.readers.appendchild
def setpermissionscorrectlytree:
# Traverse the tree and set permissions for new files
def traversenode:
node.file FileObject # Create a new file object for the node
createnewfilenodefile, node # Set permissions for the file
for child in node.children:
traversechild
# Start traversal from the root
traversetree
def printpermissionsnode:
# Print permissions for a file
def printorganizationchartnode level:
if node:
# Print node data and permissions
# Define the organizational structure
root TreeNodeCEO
manager TreeNodeManager
manager TreeNodeManager
developer TreeNodeDeveloper
developer TreeNodeDeveloper
root.children manager manager
managerchildren developer
managerchildren developer
# Set parent references
managerparent root
managerparent root
developerparent manager
developerparent manager
# Set permissions correctly
setpermissionscorrectlyroot
# Print organization chart with permissions
printOrganization Chart with Permissions:"
printorganizationchartroot
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started