CP5639 Problem Solving and Programming-The Algorithm
functionName
[Write a one or two sentence description of what your function will do. Describe any inputs and outputs]
function functionName
Input |
Processing |
Output |
Path |
Condition |
Action |
Loop variable |
Exit condition |
Function algorithm
Answer:
- getValue(prompt): getValue function displays a prompt message to the user and requests for an input according to the options provided to him.
- check(value, v1, v2, v3, v4): check function validates the value of the parameter value with the other four parameters of v1, v2, v3 and v4.
- checkRange(value, range1, range2): checkRange function validates the value of the parameter value if it lies in between the range of range1 and range2.
- calcRDCI(gender, age, weight, height): calcRDCI function calculates and returns the value of RDCI with the help of the standard formula.
- calcPercent(value): calcPercent function calculates and returns the percent of the calorie intake of the user on the basis of the type of meal he/she had that day which is referred by the parameter value.
- calculateTemptation(): calculateTemptation function generates random number and confirms for the temptation of the user for a single day and the calorie consumed with this temptation is returned.
- advice(name, RDCI, weeklyCalorie): advice function calculates the final calorie consumption and the RDCI value at the end of the week. Once the percentage is generated, the user is told if it is normal or higher or lower than the normal level and the advice for the same is told.
- main(): main function is the calling function for all the other functions and executes the program as desired.
function getValue(prompt):
IPO
Input |
Processing |
Output |
prompt |
Display prompt Get value from user Return value to the user |
value |
Algorithm
getValue(prompt):
display prompt
get value from user
return value
function check(value, v1, v2, v3, v4):
IPO
Input |
Processing |
Output |
value v1 v2 v3 v4 |
Compare value with v1, v2, v3 and v4 |
true false |
Algorithm
check(value, v1, v2, v3, v4):
if(value is equal to v1 or v2 or v3 or v4)
return true
else
return false
Condition Action Table
Condition |
Action |
value is equal to v1 |
true is returned |
value is equal to v2 |
true is returned |
value is equal to v3 |
true is returned |
value is equal to v4 |
true is returned |
value is not equal to any of the four |
false is returned |
function checkRange(value, range1, range2):
IPO
Input |
Processing |
Output |
value range1 range2 |
value is compared if it is lies between range1 and range2 |
true false |
Algorithm
checkRange(value, range1, range2):
if(value is greater than range1 and less than range2)
return true
else
return false
Condition Action Table
Condition |
Action |
value is greater than range1 and less than range2 |
true is returned |
Value is either less than range1 or greater than range2 |
false is returned |
function calcRDCI(gender, age, weight, height):
IPO
Input |
Processing |
Output |
gender age weight height |
- |
RDCI |
Algorithm
calcRDCI(gender, age, weight, height):
initialize RDCI to 0
if(gender is 'F' or 'f'):
RDCI = 10 * weight + 6.25 * height - 5 * age - 161
else
RDCI = 10 * weight + 6.25 * height - 5 * age + 5
return RDCI
Condition Action table
Condition |
Action |
gender is ‘F’ or ‘f’ |
RDCI is calculated for female |
gender is ‘M’ or ‘m’ |
RDCI is calculated for male |
function calcPercent(value):
IPO
Input |
Processing |
Output |
value |
value of parameter value is compared |
percent |
Algorithm
calcPercent(value):
if(value is 1)
return 150
else if(value is 2)
return 120
else if(value is 3)
return 100
else
return 80
Condition Action Table
Condition |
Action |
value is 1 |
150 is returned |
value is 2 |
120 is returned |
value is 3 |
100 is returned |
value is 4 |
80 is returned |
function calculateTemptation():
IPO
Input |
Processing |
Output |
- |
random numbers are generated for temptation |
temptation |
Algorithm
calculateTemptation():
temptation = randomly generate either 0 or 1
if(temptation is 0)
return 0
else
display "It also looks like this day you’ve been tempted! Naughty..."
temptation = randomly generate number between 50 and 150
return temptation
Condition Action Table
Condition |
Action |
temptation is 0 |
Return 0 |
temptation is 1 |
Temptation calorie is generated with random number |
function advice(name, RDCI, weeklyCalorie):
IPO
Input |
Processing |
Output |
name, RDCI, weeklyCalorie |
avg calorie consumption for the week is calculated |
- |
Algorithm
advice(name, RDCI, weeklyCalorie):
ADCI = weeklyCalorie/7
avg= ADCI/RDCI * 100
if(avg is less than 90)
display name + " your daily calorie intake is lower than the recommended with" + (percent - 100) + "%. This rhythm will make you lose weight, just make sure your meals contain all nutritional value needed. It’s recommended that you do not fall under the healthy weight and that you keep a balanced lifestyle."
else if(avg is between 90 and 110)
display name + "your daily calorie intake is close to the recommended one! You have a balanced healthy lifestyle, well done!"
else
display name + "your daily calorie intake is higher than the recommended with " + (percent-100) + "%. This rhythm will make you gain weight which will lead to health concerns. It’s recommended that you either lower your calorie intake, either exercise more! Careful with those temptations!"
Condition Action Table
Condition |
Action |
avg is less than 90 |
Display advice to increase nutrition |
avg is between 90 and 110 |
Congratulate user for the good nutrition |
avg is above 110 |
Display advice to control temptations |
function main():
IPO
Input |
Processing |
Output |
- |
Calculates weekly calorie consumption |
- |
Algorithm
main():
name = getValue("Welcome to the Calorie Intake Assistant, my name
is Cal. What is your name?")
while(name is empty)
name = getValue("Don’t be shy! What is your name?")
value = getValue("Hi" + name + "! To properly assist you, we will need some personal information such as age, gender, weight and height. Do you want to continue? Enter Y for yes or N for no.")
valid = check(value, 'Y', 'y', 'N', 'n')
while(valid is false)
value = getValue("I’m sorry, I cannot understand. To properly assist you, we will need some personal information such as age, gender, weight and height. Do you want to continue? Enter Y for yes or N for no.")
valid = check(value, 'Y', 'y', 'N', n')
if(value is 'n' or 'N')
display "That’s alright, good bye " + name
EXIT from the program
gender = getValue("Great " + name + ", let’s start! What is your
gender? Enter M for male or F for female.")
valid= check(gender, 'M', 'm', 'F', 'f')
while(valid is false)
gender = getValue(" I’m sorry, I cannot understand. What is your gender? Enter M for male or F for female.")
valid= check(gender, 'M', 'm', 'F', 'f')
age = getValue("What is your age in years?")
valid = checkRange(age, 18, 99)
while(valid is false)
age = getValue("I’m sorry, I cannot understand. What is your age in years?")
valid = checkRange(age, 18, 99)
weight = getValue("What is your current weight in kg?")
valid = checkRange(weight, 40, 150)
while(valid is false)
weight = getValue("I’m sorry, I cannot understand. What is your current weight in kg?")
valid = checkRange(weight, 40, 150)
height = getValue("What is your height in cm?")
valid = checkRange(height, 80, 230)
while(valid is false)
height = getValue("I’m sorry, I cannot understand. What is your height in cm?")
valid = checkRange(height, 80, 230)
display "Thank you for the information " + name + "! Let’s see how healthy your meals were last week"
RDCI = calcRDCI(gender, age, weight, height)
intialize weeklyCalorie to 0
dayNo = 1
while(dayNo is less than and equal to 7)
value = getValue("Day " + dayNo + ": were your meals very unhealthy (1), unhealthy (2), healthy (3), or very healthy (4)? Enter the corresponding number.")
add 1 to dayNo
percentage = calcPercent(value)
calorie = (RDCI * percent)/100
temptation = findTemptation()
add calorie and temptation to weeklyCalorie
display "Thank you! I’m computing your results…"
advice(name, RDCI, weeklyCalorie)
display "Goodbye and good luck!"
Condition Action Table
Condition |
Action |
value is ‘N’ or ‘n’ |
Exit the program |
value is ‘y’ or ‘Y’ |
Calculate the weekly calorie consumption |
Loop Tables
Loop variable |
Exit conditions |
valid |
valid is true |
valid |
valid is true |
valid |
valid is true |
valid |
valid is true |
valid |
valid is true |
dayNo |
dayNo is more than 7 |
Buy CP5639 Problem Solving and Programming-The Algorithm Answers Online
Talk to our expert to get the help with CP5639 Problem Solving and Programming-The Algorithm Answers to complete your assessment on time and boost your grades now
The main aim/motive of the management assignment help services is to get connect with a greater number of students, and effectively help, and support them in getting completing their assignments the students also get find this a wonderful opportunity where they could effectively learn more about their topics, as the experts also have the best team members with them in which all the members effectively support each other to get complete their diploma assignments. They complete the assessments of the students in an appropriate manner and deliver them back to the students before the due date of the assignment so that the students could timely submit this, and can score higher marks. The experts of the assignment help services at urgenthomework.com are so much skilled, capable, talented, and experienced in their field of programming homework help writing assignments, so, for this, they can effectively write the best economics assignment help services.