Question

In: Computer Science

I understand most of this information is more suitable to C++ but our instructor wants us...

I understand most of this information is more suitable to C++ but our instructor wants us to modify it to do it in Python. As long as you fufill the parameters the best you can in Python and works that all I want. Thank you

  1. Ask the user for the number of elements, not to exceed SORT_MAX_SIZE = 16 (put appropriate input validation)
  2. Ask the user for the type of data they will enter - Dollar or CIS22C_Dollar objects from Lab 1.
  3. Use your Dollar and CIS22C_Dollar classes from Lab 1 as-is without making any changes.
  4. Based on the input, create an appropriate array for the data to be entered.
  5. Make sure your template class is contained in one file which does not contain either the main or the sort function of step 4 below.
  6. Write a helper function called RecurMergeSort such that:
    • It is a standalone function not part of any class of Lab 1,
    • Takes in the same type of parameters as any standard MergeSort with recursion behavior, i.e.
      • void MergeSort( arr[], int size)
    • Prints out how the array looks every time a recursive step returns back to its caller,
  7. In your main, allow the user to enter data of their own choosing up to their chosen array size. There is no sample output - you are allowed to provide user interactivity as you see fit but programs will be graded for clarity of interaction.
  8. Then sort the array using your sort function of step 4. Take screenshots to be uploaded with the project.
  9. In your main, make sure that the output is being written to console as well as an output file at the same time. Do not copy and paste text from your console to create the output file.
  10. Ensure input and any other data validations as needed and provide descriptive prompts with emphasis on usability.
  11. Upload your classes from Lab 1 and new code files for Lab 2, output file and the screenshots in one zip file.

Grading:

  • 30 pts - EXE works from as explained above without needing any code change
  • 35 pts - your Sort function as per instructions (including coding style, documentation)
  • 35 pts - your main demonstrating everything clearly including (including coding style, documentation and interactivity)

Please do this in PYTHON to the best of ones ability. Just try to fufill all the requirements in PYTHON as best you can.

My lab one python code

class Dollar:
def _init_(self):
__whole = 0
__fract = 0
__name = ''


def _init_(self, whole, fract, name):
self.__whole = whole
self.__fract = fract
self.__name = name


def set_whole(self, whole):
self.__whole = whole


def set_fractional(self, fractional):
self.__fract = fractional


def set_name(self, name):
self.__name = name


def get_whole(self):
return self.__whole


def get_fractional(self):
return self.__fract


def get_name(self):
return self.__name


def _del_():
print("Destructor called!")


def add_sameCurrency(self, node):
fract = self._fract + node._fract
if fract > 99:
wholePart = fract // 100
fract = fract % 100
whole = self._whole + node._whole + wholePart
return whole, fract


# Subtraction same currency
def sub_sameCurrency(self, node):
fract = 0
whole = 0
if self._fract >= node._fract:
fract = self._fract - node._fract
else:
fract = self._fract - node._fract + 100
whole = self.__whole - 1
whole += self._whole - node._whole
return whole, fract


# Checking equality/inequality
def is_equal(self, node):
if self._name == node._name:
if self.__whole == node.whole:
if self._fract == node._fract:
return True
else:
return False
else:
return False
else:
return False


# comapring same currency
def is_greater(self, node):
if self._whole > node._whole:
return True
elif self._whole == node._whole:
if self._fract > node._fract:
return True
else:
return False

def show(self):
print('The amount is: ', self._whole, '.', self._fract, ' ', self._name)


def C2D2USD(self):
self._fract = (0.74 * self._fract)
self._whole = (0.74 * self._whole)
if self.__fract > 99:
self._fract = self._fract % 10
self._whole += self._fract // 100
self.__name = 'USD'
return self


# 1000 fract = 1 whole
# 1 USD = 1.36 C2D
# 1 C2D = 0.74 USD
class CIS22C:
def _init_(self):
__whole = 0
__fract = 0
__name = ''


def _init_(self, whole, fract, name):
self.__whole = whole
self.__fract = fract
self.__name = name


# Setters and Getters
def set_whole(self, whole):
self.__whole = whole


def set_fractional(self, fractional):
self.__fract = fractional


def set_name(self, name):
self.__name = name


def get_whole(self):
return self.__whole


def get_fractional(self):
return self.__fract


def get_name(self):
return self.__name


# Destructor
def _del_():
print("Destructor called!")


# Adding same currency
def add_sameCurrency(self, node):
fract = self._fract + node._fract
if fract > 99:
wholePart = fract // 1000
fract = fract % 1000
whole = self._whole + node._whole + wholePart
return whole, fract


# Subtraction same currency
def sub_sameCurrency(self, node):
fract = 0
whole = 0
if self._fract >= node._fract:
fract = self._fract - node._fract
else:
fract = self._fract - node._fract + 1000
whole = self.__whole - 1
whole += self._whole - node._whole
return whole, fract


# Checking equality/inequality
def is_equal(self, node):
if self._name == node._name:
if self.__whole == node.whole:
if self._fract == node._fract:
return True
else:
return False
else:
return False
else:
return False


# comapring same currency
def is_greater(self, node):
if self._whole > node._whole:
return True
elif self._whole == node._whole:
if self._fract > node._fract:
return True
else:
return False


def show(self):
print('The amount is: ', self._whole, '.', self.fract, ' ', self._name)


def USD2C2D(self):
self._fract = 1.36 * self.fract
self._whole = 1.36 * self._whole
if self.__fract > 999:
self._fract = self._fract % 100
self._whole += self._fract // 1000
self.__name = 'C2D'
return self


class Wallet:


def _init_(self):
array = [0, 0]
dol = Dollar(0, 0, 'USD')
array[0] = dol
c2d = CIS22C(0, 0, 'C2D')
array[1] = c2d
def _init_(self, whole, fract, name):
array = [0, 0]
if name == 'USD':
dol = Dollar(whole, fract, name)
array[0] = dol
else:
c2d = CIS22C(whole, fract, name)
array[1] = c2d


def _del_(self):
print('The object is deleted!')


def addUSD(self, node):
self[0] = self[0].add_sameCurrency(node)


def addC2D(self, node):
self[1] = self[1].add_sameCurrency(node)


def subUSD(self, node):
self[0] = self[0].sub_sameCurrency(node)


def subC2D(self, node):
self[1] = self[1].sub_sameCurrency(node)


def compareUSD(self, node):
if not self[0].is_equal(node):
if self[0].is_greater(node):
print("Greater")
else:
print("smaller")
else:
print('Equal')


def compareC2D(self, node):
if not self[1].is_equal(node):
if self[1].is_greater(node):
print("Greater")
else:
print("smaller")
else:
print('Equal')

Solutions

Expert Solution

SOLUTION :

CONSIDERING THE CONDITIONS AND PARAMETERS AND REQUIREMENTS FROM THE QUESTION

HERE CODE:

# function is used to check whether a given number or not using iteration

def isPrime(n):
if n <= 1:
return False
for i in range(2, n):
if n % i == 0:
return False;
return True
  
# function is used to check whether a given list has all prime numbers or not using iteration

def check_list_prime_iteration(arr,le):
count=0
for i in arr:
if(isPrime(i)):
count=count+1
if(count==le):
return True
else:
return False

# function is used to check whether a given list has all prime numbers or not using recusrion

def check_list_prime_recursion(arr,le):
count=0
for i in arr:
if(isPrime_Rec(i)):
count=count+1
if(count==le):
return True
else:
return False

# function is used to check whether a given number or not using recusrion

def isPrime_Rec(n, i = 2):
if (n <= 2):
return True if(n == 2) else False
if (n % i == 0):
return False
if (i * i > n):
return True
return isPrime_Rec(n, i + 1)

# List to store values
l=[]
i=1
# input taking
n=int(input("Enter size of an Array"))
while(i<=n):
input_value=int(input("Enter number"))
if(input_value>=1 and input_value<=99):
l.append(input_value)
else:
print("please enter valid input between 1 and 99")
i=i-1
i=i+1
# Final list after validation
print("Array List",l)

if check_list_prime_iteration(l,len(l)):
print("Prime Array using iteration")
else:
print("Not a Prime Array using iteration")
  
if check_list_prime_recursion(l,len(l)):
print("Prime Array using recursion")
else:
print("Not a Prime Array using recursion")

OUTPUT :

NOTE: PLEASE UPVOTE ITS VERY MUCH NECESSARY FOR ME A LOT. PLEASE......


Related Solutions

A psychology instructor wants to find out a suitable predictor of the Final examination marks of...
A psychology instructor wants to find out a suitable predictor of the Final examination marks of his students. He thinks that the Assignment marks or the Mid-term test marks can be used for this purpose. However he is not sure which of those is more suitable. The following table shows the Assignment marks (out of 20), Mid-term test marks (out of 20) and the Final examination marks (out of 40) of 5 randomly selected students of his psychology class last...
A fitness instructor wants to understand the relationship between her heart rate during a workout and...
A fitness instructor wants to understand the relationship between her heart rate during a workout and the calories burned per minute during the workout. She recorded these two measurements over the course of several workouts. StatCrunch was used to create the output below: For any numeric responses, round your answers to four decimal places. Use the regression equation to provide a point estimate for a workout when the average heart rate is 150 beats per minute: y = The fitness...
The past can offer us an opportunity to understand and fine tune our understanding of the...
The past can offer us an opportunity to understand and fine tune our understanding of the present and future. Using either the text book or other readings.     Discuss the key factors that led to the Great Recession of 2007.     Explain why these key factors are important to future financial market.     Provide an example of how the Great Recession has shaped today’s financial market.
A STAT 200 instructor wants to know if more than half of online students use the...
A STAT 200 instructor wants to know if more than half of online students use the eTextbook.  Conduct a randomization test given that 80 students in a random sample of 120 use the eTextbook. A. Determine what type of test you need to conduct and write the hypotheses. B. Construct a randomization distribution under the assumption that the null hypothesis is true. Take at least 5000 resamples. C. Use the randomization distribution to find the p-value. D. Decide if you should...
A local instructor wants you to write a c++ program using arrays to calculate the average...
A local instructor wants you to write a c++ program using arrays to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60 or above...
In order to better understand one of the most important buffer systems in our body (the...
In order to better understand one of the most important buffer systems in our body (the carbonic acid buffer system), you are titrating 0.100 L of 0.100 M carbonic acid (shown below) with 0.500 M NaOH. What will the pH be when 23.0 mL of NaOH have been added? Please give your answer to three decimal places. pka 1: 6.05 pka2: 10.64
In class, I claimed that most people who can understand the details of football can understand...
In class, I claimed that most people who can understand the details of football can understand rocket science. Many people are interested in football, and few people are interested in rocket science. However, very few people interested in football actually have a career as a professional football player. Likewise, few people have careers as rocket scientists. Yet why are so many more people are interested in football than rocket science? I claimed that the reasons concerned the way that football...
Whether in our personal lives or in business, most of us are probably familiar with the...
Whether in our personal lives or in business, most of us are probably familiar with the concept of a budget. From an operational perspective, it is essentially the forecast of how much funds are expected to be received in a given time period and how much in payments are estimated to be expended. The net result is earnings or profit. As part of the “master” budget process, budgets are set not only for operational objectives – e.g., an income statement...
What is an efficient estimator? I understand it to be a sample size that has more...
What is an efficient estimator? I understand it to be a sample size that has more results in a smaller space. So overall its more accurate?
I have trouble when solving this problem. I don't understand "There are more than half of...
I have trouble when solving this problem. I don't understand "There are more than half of the Final scores " could refer to which? Please help me in solving this. Test the hypothesis that there are more than half of the Final scores that are 5 or below, at the significance level of 5%. Final Scores 9.2 4.8 6.6 5.8 3.4 5 5.8 3.4 2.2
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT