Review problems 3#
Activity 58 (AdultCorpulenceIndex)
Corpulence index is a measure of leanness:
\( \mathrm{CI} = \frac{\mathrm{mass}}{\mathrm{height}^3} \)
Write a program that calculates corpulence index (CI) for adults and output the corresponding category.
Requirements:
use constant variables for the CI category ranges, e.g.,
const int underWeightMax = 11.you must define a function called
ci()for calculating the CI.CI must be rounded to two digits after the decimal dot when printed on the console
use first an
if-elsestatementif your programs works, then comment it out and solve the problem with a
switchstatement
Enter mass in kg
80
Enter height in m
1.70
Adults corpulence index of 16.28 means: overweight
Hint
Section Creating functions
For rounding, see section Math expressions
Section if-else Syntax
Section Switch
you can also use comparison operators in case statements, e.g.,
case < underweightMax
Activity 59 (ChocolateMachineLeasing)
You work at a company that manufactures machines for chocolate and confectionary production. In recent years the machines become very complex so your company is transitioning to a leasing model, where your company does not only sell but also provide maintenance that includes software updates to the machines. You are asked to write a tool that calculates example scenarios according to the costs below:
Example run:
Select machine
0. Tempering machine
1. Aeration machine
2. Enrober
1
Enter downtime in hours
-1
Downtime must be a non-negative integer. Try again.
2
Enter leasing time in months
10
Total cost: 74800 EUR
Base lease fee
tempering machine: 5000 EUR/month
aeration machine: 7500 EUR/month
enrober: 6200 EUR/month
Downtime penalty
if a machine is down for more than 1h in a month, then the customer receives 100 EUR/hour compensation for each downtime hour.
The compensation cannot be more than the total base lease fee.
Long-term discounts
more than 12 months: 5%
more than 24 months: 10%
Requirements:
your program contains the function with the following signature:
decimal LeasingCost(int machineId, decimal downtimeHours, decimal leasingTimeMonths)
Example outputs:
LeasingCost(0, 0, 1); LeasingCost(2, 0, 1); LeasingCost(2, 1, 1); LeasingCost(2, 2, 1); LeasingCost(2, 0, 2); LeasingCost(2, 200, 2); LeasingCost(2, 0, 20); LeasingCost(2, 0, 30);
Output:
5000 6200 6200 6000 12400 0 95000.00 135000.0
Hint
Section Creating functions
Section List
Section while statement
Section while statement
Review: Activity 32.
Activity 60 (OOPBasedTodoApp)
Let’s implement a simple OOP-based To-do app. It must have the following classes and methods:
classDiagram
class TodoItem {
+string action
+bool done
}
class TodoList {
+List~TodoItem~ Items
+Add(TodoItem item)
+getTodos() List~TodoItem~
+MarkActionDone(string action)
}
TodoList o-- TodoItem
Use the following code to test your app:
var tl = new TodoList();
tl.Add(new TodoItem { action = "Grocery", done = false });
tl.Add(new TodoItem { action = "Gym", done = false });
tl.MarkActionDone("Gym");
foreach (var todo in tl.getTodos()) Console.WriteLine(todo.action);
// Should output "Grocery"
// optional:
Console.WriteLine(tl);
// Should output "Grocery"
Hint
Section Creating functions
Section Class diagram
Section Printable classes