Compro Application Test

Share Embed Donate


Short Description

Compro Application Test...

Description

Maharishi University of Manageme Management nt Fairfield, Iowa, USA

Computer Professionals Program Master of Science in Computer Science Cooperative Program

Applicant Information Form Nget Mony logged on Applicant ID: 204870 This exam and all related materials are private copyrighted material and the intellectual i ntellectual property of M.U.M. and are provided solely for individual use on this admissions pre-test. They are not to be copied or further distributed without written permission from M.U.M. The purpose of this short test is to assess your ability to solve elementary programming problems in a language of your choice. Write your solutions in Java if you are familiar with that language; otherwise use one of these languages: C, C++, or C#. If you do not have access to a compiler for your language, write your answers in a text editor such as notepad and mention in a comment that you did not use a compiler. For each of the problems below, write the simplest, clearest solution you can, in the form of a short program. Answer as much as you can for a problem, even if you do not have the complete answer. If you are using C or C++ and the function you are writing requires an array parameter then you will also have to have a parameter that is the length of the array. This is not necessary in C# or Java since an array is an object in those languages and has a length method that returns the length of the array. You do not need to do any I/O, i.e., you can hard-code your input data and do not have to write writ e out anything to the console. Keep it simple! We are primarily interested in what you write in the body of the function. However, please be sure that your solution will work for all valid input data. The clock is ticking now, so you don't have time to ask for clarifications on any of the questions. If  something is not clear to you, resolve it yourself and state in a comment in the program what was unclear and how you resolved it. When you have finished an answer, copy and paste it into the text box associated with the question and click the submit button to save it i t in our database. If you change an answer and submit it again, the previous version of the answer will be overwritten with the new version.

1. A non-empty array a of length n is called an array of all possiblities if possiblities if it contains all numbers between 0 and a.length-1 inclusive. Write a method named isAllPossibilities  that accepts an integer array and returns isAllPossibilities that 1 if the array is an array of all possiblities, otherwise it returns 0. If you are programming in Java or C#, the function signature is int isAllPossibilities(int[ ] a) If you are programming in C or C++, the function signature is int isAllPossibilities(int a[ ], int len) where len is the number of elements in the array Examples if the the input input arra array y is retu return rn {1, 2, 0, 3}

1

{3, 2, 1, 0}

1

{1, 2, 4, 3}

0 (because 0 not included and 4 is too big)

{0, 2, 3}

0 (because 1 is not included)

{0}

1

{}

0

Copy and paste your answer here and click the "Submit answer" button

public static void main(String[] args) { isAllPossibilities(new int[]{1, 2, isAllPossibilities(new int[]{3, 2, isAllPossibilities(new int[]{1, 2, isAllPossibilities(new int[]{0, 2, isAllPossibilities(new int[]{0}); isAllPossibilities(new int[]{}); }

0, 3}); 1, 0}); 4, 3}); 3});

static int isAllPossibilities(int[] a) { if (a.length == 0) { return 0; } Submit answer to question 1

You should see a confirmation popup after hitting the submit button above. If you do not see a confirmation popup, please email your answer.

2. An array is called layered  if its elements are in ascending order and each element appears two or more times. For example, {1, 1, 2, 2, 2, 3, 3} is layered but {1, 2, 2, 2, 3, 3} and {3, 3, 1, 1, 1, 2, 2} are not. Write a method named isLayered that accepts an integer array and returns 1 if the array is layered, otherwise it returns 0. If you are programming in Java or C#, the function signature is int isLayered(int[ ] a) If you are programming in C or C++, the function signature is int isLayered(int a[ ], int len) where len is the number of elements in the array Examples: if the input array is return {1, 1, 2, 2, 2, 3, 3}

1

{3, 3, 3, 3, 3, 3, 3}

1

{1, 2, 2, 2, 3, 3}

0 (because there is only one occurence of the value 1)

{2, 2, 2, 3, 3, 1, 1}

0 (because values are not in ascending order)

{2}

0

{}

0

Copy and paste your answer here and click the "Submit answer" button

 

for (int i=0; i= previousNumber) { numOfAppear += 1; } else if (a[i] < previousNumber) { numOfAppear = 0; } previousNumber = a[i]; Submit answer to question 2

You should see a confirmation popup after hitting the submit button above. If you do not see a confirmation

popup, please email your answer.

3. A palindrome is a word or phase that reads the same backwards or forwards. Write a function named isPalindrome that returns true or false if the input array is a palindrome. If you are programming in Java or C#, the function signature is boolean isPalindrome(char [] arr) If you are programming in C or C++, the function signature is bool isPalindrome(char a[ ], int len) where len is the number of elements in the array. Examples: if the input array is

output is

{'t', 'o', 'p', 's', 'p', 'o', 't'}

true

{'t','o','t','o'}

false

{'d','o','t','s','e','e','s','t','o','d'} true {}

false

{'a'}

true

{4, 0, 9}

false

the char string "ipreferpi"

true

{0, 1, 0}

true

Copy and paste your answer here and click the "Submit answer" button

public static void main(String[] args) { isPalindrome(new char[]{'t', 'o', 'p', 's', 'p', 'o', 't'}); isPalindrome(new char[]{'t','o','t','o'}); isPalindrome(new char[]{'d','o','t','s','e','e','s','t','o','d'}); isPalindrome(new char[]{ }); isPalindrome(new char[]{'a'}); isPalindrome(new char[]{4, 0, 9});   isPalindrome("ipreferpi".toCharArray()); isPalindrome(new char[]{0, 1, 0}); } static boolean isPalindrome(char[] arr) { if (arr.length == 0) Submit answer to question 3

You should see a confirmation popup after hitting the submit button above. If you do not see a confirmation popup, please email your answer. Once you have completed all three answers and submitted them individually, you can safely close your browser.

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF