# G170 Computational Mathematics Assignment-City, University of London

Instructions to students: All questions are compulsory.

Dictionaries are not permitted.

## TASK: G170 Computational Mathematics Assignment

Question 1.

(a) Goldilocks is shopping for a new bed in the January sales. She is 1.60m tall and is rather particular about what bed would be just right for her.

Supposed that we have named two cells in the spreadsheet Bed length and Goldilocks height. Write down the command line expression using Excel built-in functions that would return the phrase “Too small.” if the bed is less than 1.60m. It should return “Too big.” if the bed is 1.80m or longer. In all other cases it should return the phrase “This bed is just right and it has ” and this should be followed by the amount of extra space, which in turn should be followed by “meters space”. So, for example, if their calculation gave 0.1 meters, then the function should all-together return“This bed is just right and it has 0.1 meters space” [8 marks]

(b)In Fairy tale Kingdom, there is soon to be an election of a new Prime Minister. The Animal Party is currently thinking about asking Mr Wolf to stand for them against Miss Muffet However, while they think he is right for the job they worry about the fact that he is typically seen as “big and bad”. They wonder if educating the public could lead voters to think that he is actually just “misunderstood” and so vote for him. So they plan to take a look at small sample groups of 10 at a time.

Assume that the data is entered in A1:C10. In the first column are the numbers 1-10 denoting the participants in the group. In the second column is the reaction of the participant based on their existing knowledge. There are only two types of response and they are “big and bad” or “misunderstood”. In the third column are the replies after being re-educated and again only “big and bad” or “misunderstood” are entered.

Write a user defined program called voters that takes in the entries of A1:C10 as input. The program, voters, should count how many people initially said “big and bad” and count how many later said “misunderstood”. If more than half of those who initially said “big and bad” change to “misunderstood” then it should return the phrase “The strategy can work.”. If not then it needs to return “Back to the drawing board.”. You should define variable types of the input and output of the function, as well as of any other variables you may use in your program. [17 marks]

### ORDER This G170 Computational Mathematics Assignment NOW And Get Instant Discount

Question 2.

Consider the table below that contains the price in pounds for various ingredients that are used in baking cakes and that are sold at 4 different shops. Suppose that it is entered in the range A1:G5 of your Excel worksheet.

 Shop Butter Flour Eggs Sugar Vanilla Extract Cocoa Powder Smiths 1.30 1.30 1.75 2.10 1.50 2.65 Paris 1.50 None 1.60 1.90 1.30 1.75 Fast 1.00 1.42 1.60 1.90 None 1.99 Abrahams 1.50 1.00 1.00 1.88 1.50 None

For a cake you need one quantity of Butter, Flour, Eggs, and Sugar and either vanilla extract or cocoa powder. Vanilla extract is needed for a vanilla cake and cocoa powder is need for a chocolate cake. Taking care to ensure that all variables are defined, complete the following tasks:

a)Write two user defined functions called vanilla-sum and chocolate-sum that take the shop name as input. These should make use of the V lookup structure. They should add up the cost of buying one of each of the six ingredients needed to make the cake if all the ingredients are available. If one is not available it should return “Missing ingredient, perhaps try a different shop or a different type of cake.”Make sure all variables are defined.  [16 marks]

b)Write a function called cake that takes in the shop name and the desired flavor. It should check if the shop name exists, making use of the the Is Error command and V lookup. If the name exists then it should call the the correct function to give the value for the ingredients for that type of cake for that shop. If the shop name does not exist it should return the message “There is no shop with this name. Try again.”. If a flavor is entered that is not one of the two possible flavors it should return the message “Flavor is not possible”. This function should use the Select Case structure.[9 marks]

### Question 3: G170 Computational Mathematics Assignment-City, University of London

The following table contains a list of the next birthdays for a group of friends and the presents they would like:

 Amber Ruhi Frank Alex Nasima 05/11/2017 30/03/2017 10/03/2017 30/02/2017 01/06/2017 Bracelet Book Cricket Bat Sun Hat Set of Cups

Suppose we write this table in the range A1:E3 of the Excel worksheet.

a)Write a user-defined function called bithdaycalc that, given the date of a birthday, returns the number of days until that birthday. If there are no days until that birthday it should return “It is today!” rather than zero. [6 marks]

b)Write a user-defined function called birthdayname that, given to-day’s date, returns the name of the person whose birthday is next. Your function should take in as input the whole range of data in the table. Depending on your approach to the solution, you might need to make use of CDATE to ensure data is of the correct type to pass into birthdaycalc. CDATE ensures output is of type DATE.[12 marks]

c)Write a user-defined function called gift that, given the name of a person, returns the type of gift that the person would like. The function should employ the Hlookup structure and make use of IsError to return “This name is not recognized.” when the input is not one of the names shown in the table.[7 marks]

For all three functions, define the variable types of the input and output of the function, as well as of any other variables you may use in your program.

Question 4.

a)Write a user-defined function called Numbers that takes in a double precision number as a key value and another double precision number as a threshold value. The function should keep a total that should initially be set to zero. The function should multiply the key value by two and add it to the total and make a new key value that is equal to this total. It should continue to multiply the key value by two and add it to the total, creating a new key value after each time the total is altered, until the threshold value is exceeded. It should then return the number of times the key value is added to the total before the threshold value is exceeded. Use a suitable Do While loop and declare the types of all variables used.[10 marks]

b)Write a user-defined function called Characters that takes in a string. If the string is less than five characters in length then it should return “Too short.”. If the string is at least five characters in length and contains an odd number of characters it should output 3 characters of the string starting with the middle character. If the string is over five characters in length, and contains an even number of characters, then it should return three characters of the string starting with the right-hand character of the middle pair. All types of variables should be declared.[15 marks]