Answered step by step
Verified Expert Solution
Link Copied!

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)
1. 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 user-defined data type file_object has two lists: file_object.writers that records who has the authorization to write the content of the file and file_object.readers that records who has authorization to only read the content. When a new file_object is created by a team member with create(new_file, 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 create_new_file(new_file).(LO 8.1,8.2,8.4)
################################### ############################################################################
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 built-in 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 depth-first traversal, where all the descendants of a node are explored before moving to the next sibling.
class TreeNode:
def __init__(self, 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 __init__(self):
self.writers =[] # List of nodes with write permission
self.readers =[] # List of nodes with read permission
def create_new_file(new_file, node):
# Set permissions for writers
new_file.writers.append(node)
if node.parent:
new_file.writers.append(node.parent)
# Set permissions for readers
for child in node.children:
new_file.readers.append(child)
def set_permissions_correctly(tree):
# Traverse the tree and set permissions for new files
def traverse(node):
node.file = FileObject() # Create a new file object for the node
create_new_file(node.file, node) # Set permissions for the file
for child in node.children:
traverse(child)
# Start traversal from the root
traverse(tree)
def print_permissions(node):
# Print permissions for a file
def print_organization_chart(node, level=0):
if node:
# Print node data and permissions
# Define the organizational structure
root = TreeNode("CEO")
manager1= TreeNode("Manager 1")
manager2= TreeNode("Manager 2")
developer1= TreeNode("Developer 1")
developer2= TreeNode("Developer 2")
root.children =[manager1, manager2]
manager1.children =[developer1]
manager2.children =[developer2]
# Set parent references
manager1.parent = root
manager2.parent = root
developer1.parent = manager1
developer2.parent = manager2
# Set permissions correctly
set_permissions_correctly(root)
# Print organization chart with permissions
print("Organization Chart with Permissions:")
print_organization_chart(root)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

=+3. Prove Theorem 2.4 .5 .

Answered: 1 week ago