CARIBBEAN EXAMINATIONS COUNCIL
CAPE COMPUTER SCIENCE INTERNAL ASSSESMENT
Candidate Names: Christopher Ebanks, David Grant, Mykal Lee
Candidate Numbers: 100128, 100128, 100128
Centre: Wolmer’s Boys’ School
School Centre Number: 100128
Territory: Jamaica
Name of Teacher: Mr. Blackwood & Ms. Williams-Maxwell
Year of Examination: 2025
1
TABLE OF CONTENTS
Introduction…………………………………………………………………………………...3
Program Design………………………………………………………………………………4
Coding of Program……………………………………………………………………………8
Program Testing ……………………………………………………………………………..13
2
INTRODUCTION
Health and fitness are two topics which people are slowly becoming more interested in. In order to track their
progress, many people tend to learn how to manage their Body Mass Index (BMI) – a metric that relays the
weight of an individual to that considered healthy based on their age, gender and height-- and daily calorie
needs so they can achieve their desired weight/body. This Internal Assessment (IA) focuses on developing a
program to calculate an individual’s BMI and resultantly determine the recommended calorie intake for their
fitness goals using data they provide.
Problem Definition
People often struggle with calculating their BMI or determining the number of calories they need to maintain,
gain or lose weight. The process is confusing when done manually as it relies on complicated formulas.
Therein, a program can be developed to make this aspect of health and fitness more accessible and beginner-
friendly by accepting user data such as their weight, height, age, gender and activity level and compiling
personalized recommendations based on their target, such as their weight category, the number of calories their
body uses on a daily basis, the number of calories they need to achieve their weight goals and other health
recommendations.
Thus, the functional aspects of this program include accepting the user’s name, weight, height, age, gender and
activity level to output their BMR and BMI which are all stored to file. The non-functional aspects of this
program include outputting the weight category of the user and health recommendations based on their BMI and
creating an admin key that grants authorized users access to the file.
3
PROGRAM DESIGN
In order to create a testable mockup for the algorithm, a pseudocode was created to explore the parameters of
the program. The file management was also discussed.
Pseudocode
DEFINE CONSTANTS:
MAX_ANS_LEN = 4
MAX_NAME_LEN = 50
TRUE_KEY = 654321
DEFINE STRUCTURE User:
Name[MAX_NAME_LEN] as STRING
Gender as CHAR
Age as INTEGER
Weight as FLOAT
Height as FLOAT
BMI as FLOAT
BMR as FLOAT
Category[20] as STRING
FUNCTION is_admin() RETURNS BOOLEAN:
DECLARE answer[MAX_ANS_LEN] as STRING
PRINT "Are you an admin? Please enter 'Yes' or 'No':"
READ answer
RETURN answer == "Yes"
FUNCTION verify_admin() RETURNS BOOLEAN:
DECLARE key as INTEGER
PRINT "Enter six-digit admin access key:"
READ key
RETURN key == TRUE_KEY
PROCEDURE display_user_info():
OPEN FILE "[Link]" FOR READING AS fptr
IF fptr IS NULL THEN
PRINT "Error opening file."
RETURN
END IF
DECLARE Name[MAX_NAME_LEN] as STRING
DECLARE Gender as CHAR
DECLARE Age as INTEGER
DECLARE BMI as FLOAT
DECLARE Category[20] as STRING
DECLARE BMR as FLOAT
WHILE READ fptr INTO (Name, Gender, Age, BMI, Category, BMR)
4
PROGRAM DESIGN
PRINT Name, Gender, Age, BMI, Category, BMR
END WHILE
CLOSE FILE fptr
PROCEDURE get_user_input(REFERENCE user AS User):
PRINT "Please enter your name:"
READ [Link]
PRINT "Please enter your gender (M/F):"
READ [Link]
PRINT "Please enter your age:"
READ [Link]
PRINT "Please enter your weight in kilograms:"
READ [Link]
PRINT "Please enter your height in meters:"
READ [Link]
FUNCTION calculate_BMI(weight AS FLOAT, height AS FLOAT) RETURNS FLOAT:
RETURN weight / (height * height)
PROCEDURE determine_BMI_category(BMI AS FLOAT, REFERENCE category AS STRING):
IF BMI < 18.5 THEN
category = "Underweight"
ELSE IF BMI <= 24.9 THEN
category = "Normal weight"
ELSE IF BMI <= 29.9 THEN
category = "Overweight"
ELSE
category = "Obese"
END IF
FUNCTION calculate_BMR(Gender AS CHAR, weight AS FLOAT, height AS FLOAT, age AS INTEGER,
activityLevel AS INTEGER) RETURNS FLOAT:
DECLARE BMR as FLOAT
IF Gender == 'M' THEN
BMR = (10.0 * weight) + (6.25 * (height * 100)) - (5.0 * age) + 5.0
ELSE
BMR = (10.0 * weight) + (6.25 * (height * 100)) - (5.0 * age) - 161.0
END IF
PRINT "Rate your daily activity level (1-5):"
REPEAT
READ activityLevel
IF activityLevel < 1 OR activityLevel > 5 THEN
5
PROGRAM DESIGN
PRINT "Invalid input. Please enter a number between 1 and 5:"
END IF
UNTIL activityLevel >= 1 AND activityLevel <= 5
SWITCH activityLevel:
CASE 1: BMR = BMR * 1.2
CASE 2: BMR = BMR * 1.375
CASE 3: BMR = BMR * 1.55
CASE 4: BMR = BMR * 1.725
CASE 5: BMR = BMR * 1.9
RETURN BMR
PROCEDURE write_user_info(user AS User):
OPEN FILE "[Link]" FOR APPENDING AS fptr
IF fptr IS NULL THEN
PRINT "Error opening file."
RETURN
END IF
WRITE [Link], [Link], [Link], [Link], [Link], [Link] TO fptr
CLOSE FILE fptr
BEGIN MAIN PROGRAM:
IF is_admin() THEN
IF verify_admin() THEN
display_user_info()
ELSE
PRINT "Incorrect key. Access denied."
END IF
ELSE
DECLARE user AS User
DECLARE conti[MAX_ANS_LEN] AS STRING
OPEN FILE "[Link]" FOR APPENDING AS fptr
IF fptr IS NULL THEN
PRINT "Error opening file."
EXIT PROGRAM
END IF
CLOSE FILE fptr
REPEAT
CALL get_user_input(user)
[Link] = calculate_BMI([Link], [Link])
CALL determine_BMI_category([Link], [Link])
[Link] = calculate_BMR([Link], [Link], [Link], [Link], 0)
CALL write_user_info(user)
6
PROGRAM DESIGN
PRINT "Are you adding another user? (Yes/No):"
READ conti
UNTIL conti != "Yes"
END IF
END PROGRAM
File Management
Once a user enters their data into the program, they are asked to input their data, it is processed and promptly
added to the file for review.
Input
o User’s name
o User’s gender
o User’s age
o User’s BMI
o User’s BMI Category
o User’s BMR
Process
o System checks if file exists
o If file does not exists, it is created
o If an error occurs, an error is displayed
o If file exists or is created, the user’s name, gender, BMI, BMI category and BMR are added to it
Output:
o An output to the user is needed here (print what will be added to the file)
7
Coding of Program
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX_ANS_LEN 4
#define MAX_NAME_LEN 50
#define TRUE_KEY 654321
typedef struct {
char Name[MAX_NAME_LEN];
char Gender;
int age;
float weight;
float height;
float BMI;
float BMR;
char category[20];
} User;
// Function prototypes
int is_admin();
int verify_admin();
void display_user_info();
void get_user_input(User *user);
float calculate_BMI(float weight, float height);
void determine_BMI_category(float BMI, char *category);
float calculate_BMR(char Gender, float weight, float height, int age, int activityLevel);
void show_calculations(float BMR, char *category, float BMI, char *Name);
float recommendation_info(float BMI);
void write_user_info(User user);
int main() { // Admin check
if (is_admin()) {
if (verify_admin()) {
display_user_info();
} else {
printf("Incorrect key. Access denied.\n");
}
} else {
User user;
char conti[MAX_ANS_LEN];
FILE *fptr = fopen("[Link]", "a"); //\File declaration
if (fptr == NULL) {
printf("Error opening file.\n");
return 1;
}
8
Coding of Program
fclose(fptr);
do {
get_user_input(&user); //User input function
[Link] = calculate_BMI([Link], [Link]); //BMI calc
determine_BMI_category([Link], [Link]); //BMI category determine
[Link] = calculate_BMR([Link], [Link], [Link], [Link], 0);
write_user_info(user);//Further BMI calc
show_calculations([Link], [Link],[Link], [Link]);
recommendation_info([Link]);
printf("\nAre you adding another user to the file? (Yes/No): ");
scanf("%3s", conti);
} while (strcmp(conti, "yes") == 0);
return 0;
}
int is_admin() {
char answer[MAX_ANS_LEN];
printf("Are you an admin? Please enter 'Yes' or 'No': ");
scanf("%3s", answer);
return strcmp(answer, "Yes") == 0;
int verify_admin() {
int key;
printf("Enter six-digit admin access key: ");
scanf("%d", &key);
return key == TRUE_KEY;
}
void display_user_info() {
FILE *fptr = fopen("[Link]", "r");
if (fptr == NULL) {
printf("Error opening file.\n");
return;
}
char Name[MAX_NAME_LEN], Gender, category[20];
int age;
float BMI, BMR;
while (fscanf(fptr, "%49s %c %d %f %19s %f", Name, &Gender, &age, &BMI, category, &BMR) == 6) {
printf("%s\t%c\t%d\t%.2f\t%s\t%.2f\n", Name, Gender, age, BMI, category, BMR);
9
Coding of Program
}
fclose(fptr);
}
void get_user_input(User *user) {
printf("Please enter your first name: ");
scanf("%49s", user->Name);
printf("\nPlease enter your gender using either 'M' for male OR 'F' for female: ");
scanf(" %c", &user->Gender);
printf("\nPlease enter your age: ");
scanf("%d", &user->age);
printf("\nPlease enter your weight in kilograms: ");
scanf("%f", &user->weight);
printf("\nPlease enter your height in meters: ");
scanf("%f", &user->height);
}
float calculate_BMI(float weight, float height) { //Calculate BMI Function Declaration
return weight / (height * height);
}
void determine_BMI_category(float BMI, char *category) { //String for Category Function Declaration
if (BMI < 18.5) {
strcpy(category, "Underweight");
} else if (BMI <= 24.9) {
strcpy(category, "Normal weight");
} else if (BMI <= 29.9) {
strcpy(category, "Overweight");
} else {
strcpy(category, "Obese");
}
}
float calculate_BMR(char Gender, float weight, float height, int age, int activityLevel) {
float BMR;
if (Gender == 'M') {
BMR = (10.0 * weight) + (6.25 * (height * 100.0)) - (5.0 * age) + 5.0;
} else {
BMR = (10.0 * weight) + (6.25 * (height * 100.0)) - (5.0 * age) - 161.0;
}
printf("\nPlease rate how active you are on a daily basis between the numbers 1 to 5");
10
Coding of Program
printf("\n1-> Sedentary (little or no exercise)\n2->Lightly active (light exercise/sports 1-3 days a week)\n3-
>Moderately active (moderate exercise/sports 3-5 days a week)\n4->Very active (hard exercise/sports 6-7 days
a week)\n5->Super active (very hard exercise or physical job)\n");
do {
scanf("%d", &activityLevel);
if (activityLevel <= 1 && activityLevel >= 5) {
printf("Invalid input. Please enter a number between 1 and 5: ");
}
} while (activityLevel < 1 && activityLevel > 5);
switch (activityLevel) {
case 1: BMR *= 1.2; break;
case 2: BMR *= 1.375; break;
case 3: BMR *= 1.55; break;
case 4: BMR *= 1.725; break;
case 5: BMR *= 1.9; break;
}
return BMR;
}
void show_calculations(float BMR, char *category, float BMI, char *Name) {
printf("\n%s, your BMI is: %.1f", Name, BMI);
printf("\nYour recommended calorie intake is %.0f", BMR);
printf("\nYou are considered to be %s", category);
}
float recommendation_info(float BMI){
if (BMI < 18.5) {
printf("\nHealthy recommendations include: eating smaller meals more frequently throughout\n the day,
incorporating high-calorie, nutrient-dense foods like nuts,\n avocado, full-fat dairy, lean protein, and whole
grains, adding healthy\nfats to meals, engaging in strength training exercises to build muscle, \nand consulting a
healthcare professional to develop a personalized plan \nto gain weight safely.");
} else if (BMI <= 24.9) {
printf("\nHealth recommendations include: maintaining a balanced diet rich in fruits\n,vegetables, whole
grains, lean protein, limiting added sugar and saturated fat, \nstaying hydrated, engaging in regular moderate-
intensity physical \nactivity like brisk walking for at least 150 minutes per week, and \nincorporating muscle-
strengthening exercises at least twice a week, \nall while monitoring your body mass index (BMI) to stay within
the healthy range of 18.5 - 24.9.");
} else if (BMI <= 29.9) {
printf("\nHealth recommendations include: adopting a balanced, reduced-calorie diet \nrich in fruits,
vegetables, and whole grains, increasing physical activity with\n moderate-intensity exercise like walking or
swimming for at least 150 \nminutes per week, managing portion sizes, limiting sugary drinks, \ngetting enough
sleep, and consulting a healthcare professional to develop \na personalized plan.");
} else {
11
Coding of Program
printf("\nDiet:\n\tEat more fruits, vegetables, whole grains, beans, lentils, and soy\n\tLimit salt, added sugar,
and unhealthy fats\n\tChoose heart-healthy oils like olive, canola, and nut oils\n\tAvoid sugar-sweetened
beverages\n\tEat smaller portions\n\tEat more slowly and mindfully\n\nExercise: \n\tGet 150 to 300 minutes
(2.5 to 5 hours) of physical activity per week\n\tTry activities like walking, jogging, swimming, or tennis. \n\
nLifestyle Set realistic weight loss goals, Avoid situations where you might overeat, Involve friends and family
in your weight loss efforts, Monitor your progress, and Limit screen time.");
}
return 0;
}
void write_user_info(User user) {
FILE *fptr = fopen("[Link]", "a");
if (fptr == NULL) {
printf("Error opening file.\n");
return;
}
fprintf(fptr, "%s\t%c\t%d\t%.2f\t%s\t%.2f\n", [Link], [Link], [Link], [Link], [Link],
[Link]);
fclose(fptr);
}
12
Program Testing
Case 1 (Underweight):
Input
Name: Phoebe
Gender:F
Age: 23
Weight: 50kg
Height: 1.7m
Activity Level: 3
Output:
Case 2(Normal Weight)
Input
Name: David
Gender: M
Age: 19
Weight:77kg
Height: 1.9m
Activity Level: 4
Output:
Case 3(Overweight)
Input:
Name: Corey
Gender: M
Age: 32
Weight: 85kg
Height: 1.8m
Activity Level: 2
Output:
Case4(Obese)
Input
Name: Karen
Gender: F
Age: 43
Weight: 92kg
Height: 1.5m
Activity Level: 1
Output:
13