Find the minimum value in an array v

Assignment Help Programming Languages
Reference no: EM132347843

SECTION A

Answer 2 questions (out of 4).

A1

In the array V below, the maximum value is 17 and the minimum value is 4 so the range (calculated as 17-4) is 13.

index 0

1

2

3

4

5

6

7

8

9

V    10

9

17

7

12

8

5

15

4

6


a) Write a function minVal() to find the minimum value in an array V

b) Similarly write a function maxVal() to find the maximum value in an array V

c) Write a third function range1() to calculate the range of V (the difference between the max and min values) using minVal() and maxVal()

d) Write a function range2() that does not call the function minVal() or maxVal() or any other functions written by you, but calculates the same result as range1().

e) Choose which version of range calculation you prefer and state one reason why.

A2

In a certain game played with cards, a player is dealt a hand of 7 cards.

Each card has a value (Ace(one), Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack(11), Queen(12) or King(13)) and each card has a Suit (Clubs(1), Diamonds(2), Hearts(3) or Spades(4)). So a card can be represented by 2 numbers (V,S). The first number V (in the range 1 to 13) represents the Value and the second number S (in the range 1 to 4) represents the Suit.

In the game it is important to know “the highest value of each Suit”.

An example of a hand of seven cards can be represented by two arrays

index

1

2

3

4

5

6

7

V

4

3

4

10

2

13

8

S

1

1

3

4

1

2

3


In this example of 7 cards, the highest value in Clubs is “Four” (i.e. S[1]=1, V[1]=4) and the highest value in Diamonds is “King” (i.e. S[6]=2, V[6]=13)..

You are required to write a program to find the highest value of each Suit.

Your program should assume the two arrays V and S exist and are already set up with the values to search. You should use this as data to discover the highest values.

The output from the program should be the four highest value cards (in this example, Four of Clubs, King of Diamonds, etc). Output “Not Found” for the value if a suit is not present in the hand.

A3

a) Trace the behaviour of the call h(), when h and V are defined as shown below.

index 0

1

2

3

4

5

V          9

8

7

4

5

1

int f(g){if(g<0)return -g; else return g;} int h(){

int i=f(V[1]-V[0]);

for(var j=2;j<6;j++){ if(f(V[j]-V[j-1])>i)

i=f(V[j]-V[j-1]);

}

return i;

}

b) Describe in a single sentence the overall effect of the function h()   

c) Rewrite the function h() changing all the identifiers to make the code more readable and understandable and add suitable comments.

A4

a) Consider the code below and write it out in a more familiar human readable form.

void p(int q,char r){for(int s=0;s<q;s++)printf("%c",r);}p(10,'+');

b) List the operators in the program above and, for each, state how many operands it has. One of the operators is a shorthand for something longer – write out the longer version.

c) Referring to the code in part a), find and write out the following:

i) all the different identifiers

ii) all the different constants

iii) a conditional (logical, boolean) expression

iv) an iterative (repetitive, loop) statement

v) the statement that is repeated by the loop

d) Write out the code from a) again, this time replacing the loop with an equivalent while loop.

SECTION B

Answer 5 questions (out of 8).

B5

A business uses a Straight Line depreciation function to calculate the value of its computer system assets over their useful life. Straight Line depreciation assumes that an item will depreciate by a set amount each year, given by the formula:

D = (P – F) / t

Where:

D = Depreciation per year

P = Purchase cost of the item F = Final value of the item

t    = Number of years the item will be in use

a) Write an expression in pseudocode (or a program in a language of your choice) in which variables P, F and t are input and the value of the item is printed each year after depreciation

b) Using the pseudocode (or program) from part a), trace the value of the item where

Purchase cost = £40,000,

Final value F = £5,000 and

the number of years of the item t = 4.

B6

Write a function factorial (n) in pseudocode (or a programming language of your choice) to calculate the factorial of n:

[Definition: factorial (n) = n * (n-1) * (n-2) ... * 2 * 1]

a) Using recursion 

b) Using iteration  

B7

a) Explain the difference between a compiler and interpreter.

b) Discuss the advantages and disadvantages between using a compiler and interpreter.

B8

a) Using an algorithm, describe the operation of a stack.

b) A stack contains the values 7, 6, 9 where 7 is the first value stored and 9 is the last. List the final values in the stack after the following operations are made:

1. Pop

2. Pop

3. Push12

4. Push16

5. Pop

6. Push 11

B9

When designing a web page to take information from a user there are various form elements available. Name FOUR different form elements, giving an example of the kind of information that each is best suited for and drawing what they look like on screen.

B10

Compare the following pairs of terms.

a) Truncation and rounding

b) Static and dynamic data structures

c) Flat file and relational databases
 
B11

a) Name the stage of the traditional software development process in which an algorithm would be created and the tasks it contains.

b) Name the stages that precede and follow the stage mentioned in a), describing the links between these three stages with reference to the algorithm.

B12

Consider the following function called findmax together with a single test case as shown below:

int findmax(int low, high){

/* specification: find the maximum value in array v between index low and index high inclusive */ int max; /* holds the maximum value found so far */

int i; /* loop counter */ max=100;

for ( i=low; i<high; i++)

if( v[i] > max )

max=v[i];

return(max);

}

test case: v[1]=55; v[2]=4; v[3]=16; low=1; high=3;

a) How would a black-box test of the function findmax be performed?

b) In what way would the error in the function findmax show up under black-box testing?

c) How would a white-box test of the function findmax be performed?

d) In what way would the error in the function findmax show up under white-box testing?

Reference no: EM132347843

Questions Cloud

How cost center accounting practices in german companies : Analyze how cost center accounting practices in German companies differ from the practices in your current or previous organization or one with which you.
Standard deviation of returns for stock : If the return on stock A in year 1 was -6 %, in year 2 was 19 %, in year 3 was 17 % and in year 4 was 13 %, what was the standard deviation of returns
Excessively optimistic and miscalibrated : Say the level of the market as measured by the Dow Jones Industrial Average is currently at 12,000. A forecaster has made a prediction of 13,300 for the level
Is the information from a known and trusted organization : Does the information come from a school or government organization? Is the information from a known and trusted organization?
Find the minimum value in an array v : BCS THE CHARTERED INSTITUTE FOR IT-BCS HIGHER EDUCATION QUALIFICATIONSBCS Level 4 Certificate in IT SOFTWARE DEVELOPMENT.
Describe potential best practice for company in given stages : Write a one page paper in which you describe a potential best practice for a company in Stage I, II, or III that is not discussed in the text.
Operating receipts-operating cash flow : Among the following different flows, which will be appropriated by both shareholders and lenders: operating receipts, operating cash flow, free cash flows?
Production costs and the corresponding drop in profits : Why can a direct link not be drawn between an increase in production costs and the corresponding drop in profits?
Capital-employed analysis of the balance sheet : When do we use a capital-employed analysis of the balance sheet? And when do we use a solvency-and-liquidity analysis of the balance sheet?

Reviews

Write a Review

Programming Languages Questions & Answers

  Design-write program to enter score repetition structure

Design and write a program that asks the user to enter five test scores using a repetition structure. The program should display the letter grade for each score and the average test score at the end of the program.

  Complete the implementation of calculator

Problem 1: Complete the implementation of Calculator.scala. Elbonia has a simple sliding scale income tax scheme. Your tax rate is determined by your income according to the following table:

  Program-visual basic to compute tips for services rendered

Write a program in Visual Basic 2010 to compute tips for services rendered. The program should request the person's occupation, the amount of the bill and the percentage tip

  Write a shuffle program to randomize the deck of cards

Write A shuffle program to randomize the deck of cards. so each player will get different cards. TRACE THIS CODE FOR AT LEAST FIVE ITERATIONS.

  Features of object oriented programming

Write a 200- to 300-word short-answer response to the following: Describe the main features of Object Oriented Programming - Encapsulation, Inheritance and Polymorphism

  Write program where dealer-s five-card hand is dealt

Write a program where the dealer's five-card hand is dealt "face down" so the player cannot see it. The program should then evaluate the dealer's hand.

  Implement an advanced scheduler

Implement an advanced scheduler that schedules processes based on their priorities. Each process has a priority, and the scheduler always picks the process with the highest priority.

  Discuss the ajax model in relation to good software design

Discuss the AJAX model in relation to good software design, and the essence of the quoted question. Will AJAX further promote the development of Web based software, or is it just another fad?

  Write a method that for a given image identifier

Write a method that, for a given image identifier, combines the text-based similarity used in 3a) with a second similarity measure based on the spatial

  Write program to asks user to enter temperatures

Write down the C++ program which asks the user to enter 12 temperatures for each month in year and store them in one-dimensional array called "temps".

  Designing system to handle donations of non-profit agency

You have been hired by worldwide non-profit agency to create a system to handle their donations.

  Designing mockup for kindergarten classroom homepage

In this assignment, designing a mockup for kindergarten teacher's classroom homepage. Create your own assets or borrow them from online image galleries

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd