Computer Science Unit 1 Internal Asessment
Computer Science Unit 1 Internal Asessment
INTERNAL ASSESSMENT
1 | Page
TABLE OF CONTENT
INTRODUCTION 3
Problem Statement 4
Pseudocode 6-8
Narrative 9
Use of File 10
2 | Page
INTRODUCTION
In this Internal Assessment, I will be creating a program that collects people’s order by
prompting the person to choose what they want to buy, and the amount they want, and
calculating the total price of what they ordered. This program can be useful as it is an
organized and quick way to give persons a food ticket and the total. Although this method
is widely used, my program can still be useful, for example, in schools that have not
utilized this method yet. A system like this may prove extremely efficient, and the code
will be written in the C programming language.
The program will prompt the user to enter the amount of money their food and drink of
choice. The program will then use the cost of each of the food items they entered, and
calculate the total cost, printing a ticket which contains the food items, The amount
purchased, the change and ticket number.
I will be creating a test plan, as well as explaining each part of the code in detail and what
it is supposed to do, with screenshot evidence of it doing so.
3 | Page
Problem Statement
The Fast-Food Ticket System aims to streamline the process of collecting customer orders by
developing a program that prompts individuals to select their desired items and specify the
quantity. The system must accurately calculate the total cost of the order based on the selected
items and quantities. The challenge lies in designing an intuitive user interface that facilitates
smooth interaction while ensuring precise computation of prices. Efficiency and accuracy are
paramount to enhance the overall customer experience and optimize operational workflows for
the fast-food establishment.
4 | Page
FUNCTIONAL REQUIREMENTS
● Prompt the user to input data about their order, the amount of each food they want
to buy, and read the information that they entered.
● Assign a ticket number randomly, whether they are the first, 20th, or 100th.
● Calculate based on the person’s order, how much the total cost will come to.
● Provide the option for users to modify their order before finalizing it, allowing
them to add, remove, or adjust quantities of selected items as needed.
Non-Functional Requirements
The program must be:
● The program must be easy to use, easy to understand, using clearly defined
instructions and reasonable feedback.
● The program must be quick and efficient, at a reasonable pace whilst using
minimal resources.
● Robust, capable of handling unexpected inputs or errors gracefully without
crashing and providing appropriate error messages to guide users in resolving
issues.
5 | Page
● Scalable, able to accommodate a growing number of users and orders without
significant degradation in performance, ensuring smooth operation as demand
increases over time.
Pseudocode
import necessary libraries
CONSTANT MAX_ITEMS = 15
CONSTANT MAX_NAME_LENGTH = 50
CONSTANT MAX_QUANTITY = 10
STRUCT MenuItem:
STRING name[MAX_NAME_LENGTH]
FLOAT price
FUNCTION main():
DECLARE menu[MAX_ITEMS]
SET menu = [
{"Hamburger", 600},
{"Cheeseburger", 650},
{"Pepperoni Pizza", 1200},
6 | Page
{"Cheese Pizza", 1100},
{"Salad", 750},
{"Shrimp Pasta", 850},
{"Pasta", 500},
{"Chicken Sandwich", 650},
{"Ham Sandwich", 800},
{"Chicken Wings Bucket", 1000},
{"Large Fries", 300},
{"Small Fries", 200},
{"Water", 150},
{"Splash", 200},
{"Soda", 250}
]
DECLARE choices[MAX_ITEMS]
SET choices = [0] * MAX_ITEMS
DECLARE money = 0
DECLARE money_input[20]
displayMenu(menu, MAX_ITEMS)
DECLARE order_item
7 | Page
WHILE TRUE DO:
PRINT "Enter the number of the item you want to order (1-" +
MAX_ITEMS + "), or 0 to finish: "
READ money_input
IF money_input is empty THEN:
PRINT "Error: Please enter a valid item number."
CONTINUE
IF NOT valid non-negative integer THEN:
PRINT "Error: Invalid input. Please enter a valid non-negative
integer."
CONTINUE
CONVERT money_input TO order_item
IF order_item < 0 OR order_item > MAX_ITEMS THEN:
PRINT "Error: Invalid item number."
CONTINUE
IF order_item == 0 THEN:
BREAK
DECLARE quantity
PRINT "Enter the quantity of item #" + order_item + " (" +
menu[order_item - 1].name + ") you would like to order (max 10): "
WHILE TRUE DO:
READ money_input
IF money_input is empty THEN:
PRINT "Error: Please enter a valid quantity."
CONTINUE
IF NOT valid non-negative integer THEN:
PRINT "Error: Invalid input. Please enter a valid non-negative
integer."
CONTINUE
CONVERT money_input TO quantity
IF quantity < 0 OR quantity > MAX_QUANTITY THEN:
PRINT "Error: Quantity must be between 0 and " +
MAX_QUANTITY + "."
8 | Page
Narrative
The program begins by prompting the customer to enter the amount of money they have. It
verifies that the input is a valid non-negative amount within the range of $150 to $920,000.
Next, it displays the menu of available food items with their respective prices. The customer
then selects items by entering the corresponding item numbers. If the input is empty or
invalid, the program prompts the customer to enter a valid item number.
After selecting items, the customer enters the quantity of each item they want to order,
with a maximum limit of 10 per item. The program ensures that the input is a valid non-
negative integer and within the specified range.
Once the order is complete, the program calculates the total cost of the order and compares
it to the amount of money the customer has. If the total cost exceeds the available funds, the
program prompts the customer to enter a new amount of money.
Finally, the program generates a random order number and saves the order details,
including the quantities of each item, the total price, the change, and the order number, to
a file named "order_details.txt". If there is an issue with opening the file, an error message
is displayed.
9 | Page
USE OF FILE
The use of the text file order_details.txt within my program is to help keep track of the orders
that the user inputs into the system, by creating a personalized ticket for them, containing the
food they ordered, the price, the money they paid, their change, their name, and their ticked #.
The data will be temporarily stored in the file because the file is opened in write mode. Many
advantages of the usage of file includes:
1. Ease of ability to open and read text files by any program that reads text, such as Word.
10 | Page
Description of file inputs and outputs
File Input:
2. User Input:
- The user is expected to enter the amount of money they have as an integer.
3. Reading Input:
- The program reads the user’s input from the standard input stream using the
`fgets` function and then converts it to an integer using `atoi`.
4. Validation:
- There is validation for the user's input to ensure it is a non-negative integer
within a specific range. The program checks for valid input, ensuring it consists
only of digits. If the input is invalid (non-integer or out of range), appropriate error
messages are displayed, and the user is prompted to re-enter the value.
File Output:
1. Opening File:
- The program attempts to open a file named “order_details.txt” in write mode. If
the file opening operation is successful, the program proceeds; otherwise, an error
message is displayed.
11 | Page
2. Writing Order Details Header:
- Upon successful file opening, the program writes the header “Order Details:” to
the file. This header indicates the beginning of the order details section.
5. Writing Change:
- The program calculates the amount of change the user will receive after making
the purchase and writes it to the file in the format “Change: $<change>”.
7. Closing File:
- Once all the necessary details are written to the file, the program closes the file
to ensure data integrity.
These detailed file input and output operations ensure proper interaction with the
user and accurate recording of order details in the output file for further reference.
Test Plan
12 | Page
This section will comprise of several tests. Which include Normal Data Tests, Erroneous
Data Test, Extreme Data Test and Incomplete Data Test.
N.B., I implemented a second input section in test data as some of the data would not show up if
the ones before are invalid. So, the second input is a correct input placed for the program to
continue. You can Skip over the second input part if you feel like. It is just for the code closure.
Normal Data
Variable Name Data Test Data Purpose Expected
Type of Data Results
MAX_ITEMS Integer 15 Represents Ensure the
Constant the program
maximum correctly
number of limits the
items in maximum
the menu. items
MAX_NAME_LENGT Integer 50 Represents Ensure the
H Constant the program
maximum handles
length of menu item
menu item names up to
name max length
MAX_QUANTITY Integer 10 Ensure the Ensure
Constant program correct limit
handles on
menu item maximum
names up item
to max quantity
length
menu Array of 1.Hamburger Represents Ensure
structures 600 menu correct
(MenuItem), 2. items and initialization
each Cheeseburge prices of menu
containing a r 650 items
character 3.Pepperoni
array(name) Pizza 1200
and a float 4. Cheese
(price). Pizza 1100
5. Salad 750
6. Shrimp
13 | Page
Pasta 850
7. Pasta 500
8. Chicken
Sandwich
650
9. Ham
Sandwich
800
10. Chicken
Wings
Bucket 1000
11. Large
Fries 300
12. Small
Fries 200
13. Water
150
14. Splash
200
15. Soda 250
choices Array of {2, 0, 1, 0, 3, Represents Program
integers 0, 2, 0, 0, 0, quantity of correctly
0, 1, 0, 1, 0} each menu records
item user's
chosen by choices
user
Money Integer $7000.00 Represents representing
the total the amount
price of of money
the user’s the user has.
order. Will later
prompt the
restaurant
and its
menu.
Total Float $6050.00 Represents Program
total price correctly
of user's calculates
order total price
based on
14 | Page
choices
Change Float $950.00 Represents Program
change correctly
given back calculates
after order change
based on
total and
money
Random_number Integer 154 Represents Program
randomly generates
generated unique
order order
number. numbers
(1-1000) within range
for each
order.
file File pointer - Represents Program
file correctly
pointer for handles file
order operations
details for order
details
Erroneous Data:
Variable Name Data Test Data Purpose of Expecte
Type Data d
Results
MAX_ITEMS Integer 15 Represents the Ensure the
Constant maximum number program
of items in the correctly
menu. limits the
maximum
15 | Page
items
MAX_NAME_LENGTH Integer 50 Represents the Ensure the
Constant maximum length program
of menu item handles
name menu item
names up
to max
length
MAX_QUANTITY Integer 10 Ensure the Ensure
Constant program handles correct
menu item names limit on
up to max length maximum
item
quantity
menu Array of 1.Hamburger Represents menu Ensure
structures 600 items and prices correct
(MenuItem) 2. initializati
, each Cheeseburger on of
containing a 650 menu
character 3.Pepperoni items
array(name) Pizza 1200
and a float 4. Cheese
(price). Pizza 1100
5. Salad 750
6. Shrimp
Pasta 850
7. Pasta 500
8. Chicken
Sandwich
650
9. Ham
Sandwich
800
10. Chicken
Wings
Bucket 1000
11. Large
Fries 300
12. Small
Fries 200
16 | Page
13. Water
150
14. Splash
200
15. Soda 250
choices Array of {16, 21, 16, Represents Represent
integers 20, 13, 15, quantity of each s the
12, 10, 1, 13, menu item chosen maximum
21, 10, 1, 11, by user number of
10} items in
the menu
Second
Input:
{2,3,4,5,2,1,3
,2,6,5,7,8,6,4,
3}
money Integer 1a20 Represents the Program
total price of the prompts
Second user’s order. user to
Input: retype
100000 correct
amount of
money
Total Float Invalid Represents total Program
price of user's handles
Second order invalid
Input: 32500 total
calculatio
n
gracefully
Change Float $67500.00 Represents Program
change given generates
back after order unique
order
numbers
within
range
Random_number Integer 428 Represents Program
randomly generates
generated order unique
17 | Page
number. (1-1000) order
for each order. numbers
within
range
file File pointer - Represents file Program
pointer for order handles
details file
operations
gracefully
Extreme Data
Variable Name Data Type Test Data Purpose of Data Expected
Results
MAX_ITEMS Integer 15 Represents the Ensure the program
Constant maximum number of correctly limits the
items in the menu. maximum items
MAX_NAME_LENGTH Integer 50 Represents the Ensure the program
Constant maximum length of handles menu item
menu item name names up to max
length
MAX_QUANTITY Integer 10 Ensure the program Ensure correct limit
Constant handles menu item on maximum item
names up to max quantity
length
menu Array of 1.Hamburger Represents menu Ensure correct
structures 600 items and prices initialization of
(MenuItem), 2. menu items
each Cheeseburger
containing a 650
18 | Page
character 3.Pepperoni
array(name) Pizza 1200
and a float 4. Cheese
(price). Pizza 1100
5. Salad 750
6. Shrimp
Pasta 850
7. Pasta 500
8. Chicken
Sandwich
650
9. Ham
Sandwich
800
10. Chicken
Wings
Bucket 1000
11. Large
Fries 300
12. Small
Fries 200
13. Water
150
14. Splash
200
15. Soda 250
choices Array of {-1, -1, -12, Represents quantity Program handles
integers 0, 13, 15, 2, of each menu item negative and over
1, -12, 21, chosen by user limit inputs
10,23, 10, 11, gracefully
-2}
Second
Input:
{1,4,2,-,7,3,-,
2,1,-,5,3,-,2,3
,}
money Integer -999 Represents total Program prompts
Second price of user's order user to retype
Input: correct amount of
19 | Page
40000 money
total Float Second Represents total Program handles
Input: price of user's order invalid total
27300.00 calculation
gracefully
Random_number Integer Second Represents randomly Program generates
Input: 839 generated order unique order
number numbers within
range
file File pointer Second Represents file Program handles
Input: - pointer for order file operations
details gracefully
Incomplete Data:
20 | Page
Test Results
Normal:
Screenshot 1
21 | Page
Screenshot 2
Screenshot 3
22 | Page
Screenshot 4
Screenshot 5
23 | Page
Erroneous:
Screenshot 7
Screenshot 8
Screenshot 9
24 | Page
Screenshot 10
Screenshot 11
25 | Page
Screenshot 12
Extreme
Screenshot 13
26 | Page
Screenshot 14
Screenshot 15
27 | Page
Screenshot 16
Screenshot 17
28 | Page
Incomplete
Screenshot 18
Screenshot 19
29 | Page
Use of Appropriate Data Structures
30 | Page
1. Struct for Menu Items:
● The MenuItem struct is defined to represent each menu item. It contains fields
for the item's name (name) and price (price).
typedef struct {
char name[MAX_NAME_LENGTH];
float price;
} MenuItem;;
●This struct efficiently stores the name and price of each menu item.
2. Array for Menu:
● An array of MenuItem structs (menu[MAX_ITEMS]) is used to store all menu items.
● MenuItem menu[MAX_ITEMS] = { ... };
●This array structure organizes the menu items, making them easily
accessible for display and calculation.
3. Array for User Choices:
● An array of integers (choices[MAX_ITEMS]) is used to store the quantities of
each menu item chosen by the user.
● int choices[MAX_ITEMS] = {0};
This array tracks the user's selections, allowing for calculation of the total
●
price and validation of quantities.
4. Character Array for User Input:
● A character array (money_input[20]) is used to temporarily store the user's
input for the amount of money they have.
● char money_input[20];
31 | Page
Demonstration of structured programming concepts
System Architect
1. User Interface (UI):
- Responsible for interacting with the user, displaying the menu, and taking user inputs such as
the amount of money and quantities of items to order.
2. Menu Management:
- Responsible for storing the menu items and their prices.
- Provides functions to display the menu.
3. Order Management:
- Responsible for managing the user's order, including storing the quantities of items selected
by the user and calculating the total price.
4. File Handling:
- Responsible for writing order details to a file, including the items ordered, total price, change,
and order number.
system architecture:
User Interface <--> Menu Management <--> Order Management <--> File Handling <-->
Random Number Generation
Menu Management:
- Stores the menu items and their prices.
- Provides a function to display the menu.
Order Management:
32 | Page
- Manages the user's order by storing the quantities of items selected.
- Calculates the total price of the order.
- Validates the user's order against available funds.
File Handling:
- Writes order details to a file, including items ordered, total price, change, and order number.
- Handles errors related to file operations.
Structure Chart
Main
└── User Interface
├── Display Menu
├── Get Money Input
├── Get Item Quantities
│ └── Validate Quantity
├── Calculate Total
│ └── Validate Total
├── Check Funds
├── Generate Order Number
├── Write Order Details to File
└── Error Handling
33 | Page
Structure chart
Validate Quantity
Menu
Check Funds
Error Handling
Generate Order
Number
Write Order
details on file
34 | Page
User Documentation
User Documentation
Installing the software
Dev-C++ requirements
Dev-C++ requires Windows. You need about 9 megabytes for the download file and 60.
megabytes more for the installed IDE.
System Requirements For DEV-C++ For Window 10
• Operating System: Windows XP/Vista/7/8/8.1/10
• Memory (RAM): 2 GB of RAM required.
• Hard Disk Space: 500 MB of free space required.
• Processor: 1.0 GHz Intel Pentium processor or later.
• NET 4.5 Framework Required
1. Download Dev-c++ from the official website https://www.bloodshed.net
2. Run the setup.exe program
3. Choose the appropriate language
4. Agree to the license agreement
5. Select next when prompted with choose components
6. The destination folder for the program will by defaut be C:\Program Files (x86) \Dev-Cpp
(The destination can be changed by the user if wanted)
7. The space required for version 5.11 is 346.8 mb
8. After meeting the requirements select install to install the program, wait patiently until all
the files are extracted.
9. After the files are extracted a message will come up saying the program has been installed
On your computer, select finish to run the program.
10. First time configuration prompts will be asked and answer to your preference
Running the program
Running the Program:
1. Preparation: Before running the program, it's recommended to watch a tutorial video on how to
use Dev-C++ for basic understanding.
Apologies for the confusion. Let's revise the user documentation to correspond with your provided
code:
2. Order Placement:
35 | Page
- Upon execution, the program will prompt the user to input the amount of money they have.
- Enter the amount of money, ensuring it is a valid non-negative integer.
- After entering the money amount, the program will display the menu with various food items
and their prices.
- Enter the quantity of each item you wish to order, ensuring it is between 0 and 10.
- The program will calculate the total price of the order and display it along with the change (if
any).
- A random order number will be generated and displayed.
- The details of the order, including quantities, item names, total price, change, and order
number, will be saved to a file named "order_details.txt" in the same directory as the program.
3. Error Handling:
- If the entered money amount is not a valid non-negative integer, an error message will be
displayed, prompting the user to enter a valid amount.
- If the quantity of any item selected is not within the range of 0 to 10, an error message will be
shown, and the user will be prompted to enter a valid quantity.
Note: For any issues or further assistance, please refer to the source code or contact the program's
developer.
Contact Information: For any assistance or queries, you can contact us at 876-875-0110 or via email
at [email protected]@gmail.com.
36 | Page
Coding of Program
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#define MAX_ITEMS 15
#define MAX_NAME_LENGTH 50
#define MAX_QUANTITY 10
typedef struct {
char name[MAX_NAME_LENGTH];
float price;
} MenuItem;
int main() {
37 | Page
MenuItem menu[MAX_ITEMS] = {
{"Hamburger", 600},
{"Cheeseburger", 650},
{"Pepperoni Pizza", 1200},
{"Cheese Pizza", 1100},
{"Salad", 750},
{"Shrimp Pasta", 850},
{"Pasta", 500},
{"Chicken Sandwich", 650},
{"Ham Sandwich", 800},
{"Chicken Wings Bucket", 1000},
{"Large Fries", 300},
{"Small Fries", 200},
{"Water", 150},
{"Splash", 200},
{"Soda", 250}
};
while (1) {
fgets(money_input, sizeof(money_input), stdin);
int valid_input = 1; // Assume input is valid
for (int i = 0; money_input[i] != '\0' && money_input[i] != '\n'; ++i) {
if (!isdigit(money_input[i])) {
valid_input = 0;
break;
}
}
if (!valid_input) {
printf("Error: Invalid input. Please enter a valid non-negative
amount.\n");
38 | Page
continue;
}
money = atoi(money_input);
if (money <= 0 || money < 150 || money > 920000) {
printf("Error: Please enter a valid amount between $150 and
$920,000.\n");
continue;
}
break;
}
displayMenu(menu, MAX_ITEMS);
int order_item;
do {
printf("Enter the number of the item you want to order (1-%d), or 0 to
finish: ", MAX_ITEMS);
fgets(money_input, sizeof(money_input), stdin);
int valid_input = 1; // Assume input is valid
for (int i = 0; money_input[i] != '\0' && money_input[i] != '\n'; ++i) {
if (!isdigit(money_input[i])) {
valid_input = 0;
break;
}
}
if (!valid_input) {
printf("Error: Invalid input. Please enter a valid non-negative integer.\
n");
continue;
}
sscanf(money_input, "%d", &order_item);
if (order_item < 0 || order_item > MAX_ITEMS) {
printf("Error: Invalid item number.\n");
continue;
}
39 | Page
if (order_item == 0) {
break;
}
int quantity;
printf("Enter the quantity of item #%d (%s) you would like to order
(max 10): ", order_item, menu[order_item - 1].name);
while (1) {
fgets(money_input, sizeof(money_input), stdin);
int valid_input = 1; // Assume input is valid
for (int j = 0; money_input[j] != '\0' && money_input[j] != '\n'; ++j) {
if (!isdigit(money_input[j])) {
valid_input = 0;
break;
}
}
if (!valid_input) {
printf("Error: Invalid input. Please enter a valid non-negative
integer.\n");
continue;
}
quantity = atoi(money_input);
if (quantity < 0 || quantity > MAX_QUANTITY) {
printf("Error: Quantity must be between 0 and %d.\n",
MAX_QUANTITY);
continue;
}
break;
}
choices[order_item - 1] += quantity;
} while (1);
40 | Page
printf("Error: Insufficient funds. Your order total exceeds the amount of
money you have ($%d).\n", money);
printf("Please adjust your order or enter a new amount of money.\n");
printf("How much money do you have now? $");
srand(time(NULL));
int random_number = rand() % 1000 + 1;
printf("Your order number: %d\n", random_number);
42 | Page