Question

In: Computer Science

Implement the following functions in a module called arrayfunctions.py. You must use the booksite modules stdarray...

Implement the following functions in a module called arrayfunctions.py. You must use the booksite modules stdarray and stdio to implement the functions.  

print1Darray() takes a one dimensional integer array argument and prints it (field width for each element should be 5).

print2Darray() takes a two dimensional integer array argument and prints it (field width for each element should be 5 - should be printed as a m x n matrix).

add2Darrays() takes 2, two dimensional integer array arguments. You can assume the arrays are the exact same size. The function returns a new array that is the addition of the 2 arrays passed in.  

print2DarrayBoolean() takes a two dimensional boolean array argument and prints a * in place of True and a space in place of False. Include row and column numbers.  

Solutions

Expert Solution

Codes for above methods in Python3 are as follows:

def print1Darray(arr):
   for value in arr:
       print("%-5d" % value,end='')
   print("")
  
def print2Darray(arr):
   for row in arr:
       print1Darray(row)
      
def add2Darrays(a,b):
   add=[]
   for i in range(len(a)):
       temp=[]
       for j in range(len(a[0])):
           temp.append(a[i][j]+b[i][j])
       add.append(temp)
   return add
  
def print2DarrayBoolean(arr):
   for row in arr:
       for col in row:
           if(col):
               print("*",end='')
           else:
               print(" ",end='')
       print("")

print1Darray([1,2,3,4,5])
print("")
print2Darray([[1,2,3],[4,5,6]])
print("")
print2Darray(add2Darrays([[1,2,3],[4,5,6]],[[1,2,3],[4,5,6]]))
print("")
print2DarrayBoolean([[True,False,True],[True,False,True]])

Sample output

Mention in comments if any mistakes or errors are found. Thank you.


Related Solutions

You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function (merge-sorter L1) that takes list-of-integers L1 and returns all elements of L1 in sorted order. You must use a merge-sort technique that, in the recursive case, a) splits L1 into two approximately-equal-length lists, b) sorts those lists, and then c) merges the...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (forget-n L1 N) that returns the elements of L1 except for the first N. If N is negative, return all elements. If N exceeds the length of L1 return the empty list....
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem needs to use DrRacket software. Racket Language. Write a function (indices L1 X) that takes a list of elements L1 and an element X. The function returns a list of the indices in L1 that contain X. See the following examples for clarification....
You must write each of the following scheme functions. You must use only basic scheme functions,...
You must write each of the following scheme functions. You must use only basic scheme functions, do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (first-n L1 N) that returns the first N elements of L1. If N is negative, return the empty list. If N exceeds the length of L1 return all elements of L1. (first-n...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function (join-together L1 L2) that takes a sorted list (ascending) of integers L1 and a sorted list of elements L2 and returns a sorted list containing all elements of both L1 and L2. See...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function (indices L1 X) that takes a list of elements L1 and an element X. The function returns a list of the indices in L1 that contain X. See the following examples for clarificaton. (indices '(a b c a e f a) 'a')...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function named (list-replace ALIST SYM VAL) that accepts a list of elements and returns that list where all SYM's (a single symbol) have been replaced by the VAL (some scheme value). The replacement must occur even within nested lists. For example: (list-replace '(a...
USE ONLY THE BELOW FUNCTIONS AND IMPLEMENT THE MISSING PART implement the following missing functions from...
USE ONLY THE BELOW FUNCTIONS AND IMPLEMENT THE MISSING PART implement the following missing functions from the implementation: * reset * intersection * difference Set Set::intersection(Set& s){ Set r; // find intersection return r; } Set Set::difference(Set& s){ Set r; // find difference return r; } void Set::reset(int c){ // increase the capacity and clear the data } driver program int a1[] = {10,5,7,3,9}; Set s1(5); s1.insert(a1,5); s1.print("s1"); int a2[] = {2,9,6}; Set s2(3); s2.insert(a2,3); s2.print("s2"); Set s3 = s1.unionset(s2);...
Design and implement a C++ class called Module that handles information regarding your assignments for a specific module.
Design and implement a C++ class called Module that handles information regarding your assignments for a specific module. Think of all the things you would want to do with such a class and write corresponding member functions for your Module class. Your class declaration should be well-documented so that users will know how to use it.Write a main program that does the following: Declare an array of all your modules. The elements of the array must be of type Module....
The project requires you to implement 4 functions of your choice in a file called Utilities.java....
The project requires you to implement 4 functions of your choice in a file called Utilities.java. The functions may relate to statistics, graphics/animation, audio, text, or image applications. Deliverables (files that need to be submitted): 1. A word document that briefly describes the functions that were implemented and the API. 2. Utilities.java file with the 4 functions and a Test.java file that provides examples of using the functions in Utilities.java.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT