Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. Help understanding Functions

Hi, I'm doing an assignment and i am VERY confused.

I have read my notes, watched youtube vids and used my books but i still feel like i have a gap in my Knowledge somehow.

Here are my instructions
HERE ARE MY INSTRUCTIONS

What started out as a little “baking on the side” for Della has now become a full-time venture. She has recently opened Della’s Delectable Delights, a bakery and café selling pastries and other baked goods. However, she needs some assistance in managing the numerous orders she gets on a daily basis.
She wishes you to design a system which will help her to manage orders for her specialty items: Not-so-salt Bread, Jam Jump-ups and Coconut Cravers.
At the end of each day, Della wants to enter the orders (in no particular sequence) which have come in for the following day. Each of the three specialty items need to be dealt with differently and your system must be able to handle the requirements.
1) Not-so-salt Bread: Often, customers can’t wait to get their hands on their Not-so-salt Bread and call to enquire if their order would be ready for early collection. Therefore, once Brenda has completed a Not-so-salt Bread order, she places the customer ID on the Bread Completion List. Della is then able to search the list for the ID of the enquiring customer. You may assume there are a maximum of 20 separate customer orders for Not-so-salt Bread; Binary Search is required – assume list is in descending order.
2) Jam Jump-ups: Janine and Jerry handle all of the orders for Jam Jump-ups. Any orders which are over 25 are handled by Janine; all others are handled by Jerry. The system will be required to separate and allocate the orders to the appropriate baker. Once all of the orders have been allocated, the sorted list for each baker should be displayed along with a total number of Jam Jump-ups for each baker. You may assume there are a maximum of 10 separate customer orders for Jam Jump-ups; Selection Sort is required – assume ascending order.
3) Coconut Cravers: Colin and Connie are the most competitive Coconut Craver creators you will ever come across. There is always a challenge to see who will make the most Coconut Cravers and be Coconut Craver Champion at the end of each day. Therefore, the list of orders should be printed for them with the largest first so that whoever completes their current order first, may pull the next largest. You may assume there are a maximum of 15 separate customer orders for Coconut Cravers; Bubble Sort is required.
INSTRUCTIONS
1. Create a single algorithm to handle the requirements.
2. You must define and use at least two functions.

_____

Okay so basically, I have to follow the instructions, but I CANNOT USE GLOBAL VARIABLES. So doesn't that mean that my ENTIRE program will have to be a complilation of functions?

Here is my Psuedocode (Part of it)

___

Begin Algorithm
¬Function PopulateArray ()
Declare variable I as integer
Declare constant NSSbSize=20
Declare Array CustomerID to hold 20 Integer Values
Declare Integer Array NSSBorder of size NSSbSize
I=0
For I=0 to NSSbSize-1
Display “Please enter the ID of the Customer”
Input NSSBOrder[i]
End Function
Display “Is this Customers [CustomerID[i]] order complete? (Yes/No) ”
Input Choice
Declare variable Choice as string
If Choice=”yes” THEN
CustomerID[i] =BCList[ i]
EndIf
End Function
// Defining binary search function
Function BinarySearch (BCList[i], CustomerID[i],NSSBsize)
BEGIN
Declare min, max, mid, search key as Integer
“Please enter the ID of the Customer whose order you are checking on.”
Input CustomerID
Searchkey:=0
Min:=0
Max:=NSSBsize-1
WHILE max >= min DO
Mid:=(min+max) div2
IF BCList[mid] = searchkeyTHEN
Display “ This Order is ready.”
Stop?
ELSE IF searchKey < BCList [mid] THEN
Max:=mid-1
Else
Min:=Mid+1
EndIf
Endwhile
Display “This order is not ready.”
Endfucntion
//Defining swap function
Function Swap ( JenOrder[i], JenOrder[J] )
Begin

Temp= JenOrder[i]
JenOrder[i]=JenOrder[minI]
JenOrder[minI]=temp
EndFunction

¬¬¬¬¬ // Define Selection sort function
Function SelectionSort (JJUsize, JenOrder[i] bring in a counter?)
Begin
Declare MinI, J as data type integer
MinI=0
J=0
FOR i=0 to JJUSize-1 DO
FOR J=i + 1 to arraySize-1 DO
IF (JenOrder[j] < JenOrder[MinI]
MinI=J
IF (minIndex !=i) THEN
Swap (JenOrder[MinI], JenOrder[I], )
End Function
Function BubbleSort ( )
Begin
Declare swapped as boolean. Set to true
Declare variable Index as integer
Declare variable counter as type integer
Declare passes as integer
Declare CCorder as an array holding Arraysize integer values
Constant ArraySize =15
Passes=0
Index=0
WHILE (Swapped = true) DO
Swapped=false
Passes=passes+1
FOR index=0 to <arraySize-passed DO
IF CCorder[counter] < CCorder[counter+1] THEN
Temp=CCorder[counter]
CCorder[counter]=CCorder[counter+1]
CCorder[counter+1]=temp
Swapped=true
Display CCorder[i]
Endif
Endfor
End function

Function FoodSelection
Declare variables FoodChoice as Char
Set Constant JJUsize=10
Set Constant NSSBsize=20
Set Constant CCsize=15
If choice=”1” THEN
Populate ()

BinarySearch (BCList[i], CustomerID[i])

If FoodChoice=”2” THEN
Populate( )
SelectionSort ( JenOrder[i],)
Selectionsort(JerOrder[i])

If FoodChoice=”3” THEN
PopulateArray(CCSize[i], Customer ID,CCorder )
BubbleSort ()

Else display “Invalid request”

************ AT THIS POINT I AM FINNISHED DECLARING MY VARIABLES*******

Function FoodSelection
Declare variables FoodChoice as Char
Set Constant JJUsize=10
Set Constant NSSBsize=20
Set Constant CCsize=15
If choice=”1” THEN
Populate ()

BinarySearch (BCList[i], CustomerID[i])

If FoodChoice=”2” THEN
Populate( )
SelectionSort ( JenOrder[i],)
Selectionsort(JerOrder[i])

If FoodChoice=”3” THEN
PopulateArray(CCSize[i], Customer ID,CCorder )
BubbleSort ()

Else display “Invalid request”

____________________

My Problem is that my Teacher says that functions are only supposed to do one particular task each. But myn doesn't work like that -.-

Also another Clue ihave that makes me think i'm doing it wrong is that the istructions says " You must use at least two functions" But dont i have to use functions for everything?

HELP HELP HELP

2. A few things:

First of all, we kinda have a rule around here of not doing people's homework for them, but we also want to be helpful.

Secondly, I don't see any attachments so I have no idea what you're being asked to do.

Thirdly, I have no idea what language this in (guessing ObjectiveC by the NS*), and that can have an effect.

Fourthly, even if it's pseudo code, please wrap it in a [code] block

As for general programming design, yes, a function should manipulate a set of data and return some value that the rest of your code gets to work with. Assuming this is obj-C, you need to understand variable scope.

If you declare a variable inside a loop, it isn't a global variable. Likewise if you declare a var inside a function, it isn't global. I would approach your task by perhaps using 2 or 3 functions, and inside one function, do something like this:

function a() {
// declarations
// call function b(pass, vars, in)
// return result;
}
function b(arg1, arg2, arg3) {
// do some manipulations
// return result to a()
}

3. Instructions

1. I don't expect you to do it for me. I already have it 90% down i believe.

2. i have put the instructions in my first post in dark green.

3. we have never been taught a programming language. Only General Psuedocode

4.How do i block wrap?

I am not quiet sure what you are trying to say to help me. Can you please explain.

4. This is how functions looks in real programming is what he is saying

5. Functions in programming are very similar to functions in math. I presume you have not worked with functions in math either otherwise this would be more easily understood.

http://www.mathopenref.com/functionsprog.html

Your professor is correct that your functions should really only perform 1 task. That is the point to a function and why they are so useful in both math and programming. You can create libraries of basic functions that when used together can perform more complicated tasks. A function that performs many different tasks it not as reusable as function that performs a single basic task.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•