Computer Science Notes
Computer Science Notes
Problem Definition
Big J’s Jerk Restaurant is located in, Hatfield, Mandeville, Jamaica. It is a well-
established business that ensures that community members have access to quality
meals at an affordable price. The restaurant severs 1000s of customers per week.
The restaurant not only offers food for sale but beverage, desserts. The
restaurant, Big J’s Jerk Restaurant, uses a printed or a paper-based menu. This is
useful as it allows multiple people to have access to it. This method used to
provide meals, prices and drinks has a number of inefficiencies, chief of which is
the fact that the paper-based menus could be destroyed by food or drinks,
misplaced. If any of these situations occur, Big J will have to reprint them which
would be costly.
The new system will also electronically calculate the sales price for the products
and output it to the user. The program will allow the user to add, view and delete
information on each goods which will provide a more reliable method of managing
customers orders. Better management of customers’ orders is expected to result in
increased business productivity.
The C program should have the following features: Menu utilising the switch
case
must have at
least 5 functions
Must use
arrays
Must use the
struct feature
Must use
files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_PRODUCTS 100
#define FILENAME "inventory.txt"
// Function declarations
void addProduct(Product products[], int *count);
void viewProducts(Product products[], int count);
void searchProduct(Product products[], int count);
void deleteProduct(Product products[], int *count);
void saveProductsToFile(Product products[], int count);
void loadProductsFromFile(Product products[], int *count);
int main() {
int choice;
Product products[MAX_PRODUCTS];
int count = 0;
do {
printf("\nBig J's Jerk Restaurant Inventory Management\n");
printf("1. Add Product\n");
printf("2. View Products\n");
printf("3. Search Product\n");
printf("4. Delete Product\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
getchar(); // Consume newline character left by scanf
switch (choice) {
case 1:
addProduct(products, &count);
break;
case 2:
viewProducts(products, count);
break;
case 3:
searchProduct(products, count);
break;
case 4:
deleteProduct(products, &count);
break;
case 5:
saveProductsToFile(products, count);
printf("Exiting program. Data saved to file.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 5);
return 0;
}
(*count)++;
printf("Product added successfully!\n");
}
int found = 0;
int i;
for (i = 0; i < count; i++) {
if (strcmp(products[i].name, searchName) == 0) {
printf("Product found:\n");
printf("Name: %s\n", products[i].name);
printf("Price: %.2f\n", products[i].price);
printf("Quantity: %d\n", products[i].quantity);
found = 1;
break;
}
}
if (!found) {
printf("Product not found.\n");
}
}
E.G.
struct student
{
char name[40];
int age;
char branch[10];
// F for female and M for male
char gender;
} student1={''Jim", 41,Business, M};
Global declaration is outside the main function. The who program has access to
these variables
Local declaration is inside the main function. Only a part of the program has
access to these variables
The grocer Needs to store data about some products using a C program. Each product
has an id(int), Name(char), quantity in stock(int) and a price(float)
A. Write a declaration for a C struct productrec that can store the record
for each product.
B. Declare 2 variables, item1 and item2, associated with the structure
declared in part A.
C. Write C code to put data in Item1 and Item2 declared in part B. Use values
that you like.
D. Display the results to the user.
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
#include <stdio.h>
#include <string.h>
// For item2:
item2.id = 102;
strcpy(item2.name, "Bread");
item2.quantity = 15;
item2.price = 1.75f;
printf("Item2:\n");
printf(" ID: %d\n", item2.id);
printf(" Name: %s\n", item2.name);
printf(" Quantity: %d\n", item2.quantity);
printf(" Price: $%.2f\n", item2.price);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
#include <stdio.h>
struct productrec {
int id; // Product ID
char name[50]; // Product name (string)
int quantity; // Quantity in stock
float price; // Price
};
int main(void) {
// Declaration and initialization without using <string.h>
struct productrec item1 = {101, "Milk", 20, 2.50f};
struct productrec item2 = {102, "Bread", 15, 1.75f};
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
#include <stdio.h>
int main(void) {
// B. Declare 2 variables, item1 and item2, associated with
// the structure declared in part A.
struct productrec item1, item2;
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
#include <stdio.h>
int main(void) {
// B. Declare two variables, item1 and item2, and initialize them directly.
struct productrec item1 = {1001, "Milk", 50, 1.25f};
struct productrec item2 = {1002, "Bread", 30, 1.75f};
// C. Data has already been put into item1 and item2 using initialization.
printf("Item2:\n");
printf(" ID: %d\n", item2.id);
printf(" Name: %s\n", item2.name);
printf(" Quantity: %d\n", item2.quantity);
printf(" Price: $%.2f\n", item2.price);
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
/*
Documentation Section
Program Name:Stuct Practice
Author:Pierce-Mikal McNamee
Date:2/18/2025
(i)Write a C declaration for a struct in C that can hold the record of a customer.
Each record contains a customer ID (integer) and a customer balance (float). Note
that balance represents the amount of money a customer has for making purchases. \
[3 marks\]
(ii)Declare two variables to represent two customers, Andrew and Jamie. Next, set
their record values as follows:
| | ID | Balance |
|-------|--------|---------|
| Andrew| 1200 | 2000 |
| Jamie | 1500 | 3000 |
\[4 marks\]
(iii) Assume that Andrew pays full price for any purchases made and Jamie gets a
10% discount on all purchases. Write C code to read two values representing the
purchases of Andrew and Jamie respectively, from the keyboard. Next, adjust each
customer’s balance based on the purchases. \[3 marks\]
(iv) Write C code to interchange the records of Andrew and Jamie. \[3 marks\]
*/
#include <stdio.h>
int main(void) {
// (ii) Declare two variables for Andrew and Jamie
struct Customer Andrew, Jamie;
// (iii) Prompt for and read the purchase amounts for Andrew and Jamie
float purchaseAndrew, purchaseJamie;
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
Computer Science
2/20/2025
The processor
-----------------------------------------------------------------------------------
-------------------------------
The central processing unit/processor is the brain of the computer. It handles all
processing and controls all activities of a computer system. the main functions of
the CPU are:
1. To fetch data and instructions from memory (RAM).
2. To decode and coordinate instructions and data received.
3. To execute and perform instructions on data received.
4. To send the results of execution to storage (RAM or secondary storage).
CPU Components
-----------------------------------------------------------------------------------
-------------------------------
Them main components of a CPU are:
<Busses
<Arithmetic Logic Unit
<Registers
<Control Unit
<CPU Clock
Control Units
-----------------------------------------------------------------------------------
-------------------------------
The functions of the control unit are
1.To process input instructions and data given to the computer.
2.To control and coordinate all activities of the computer.
3.To fetch data and instructions from memory.
4.To execute and perform instructions on data given to the computer.
5.To decode and coordinate instructions on data received.
Bus
-----------------------------------------------------------------------------------
-------------------------------
A bus is an electrical pathway that transports bits of instructions and data
between the different parts of the CPU.
Registers
-----------------------------------------------------------------------------------
-------------------------------
Registers are high speed storage locations in the CPU which temporarily holds the
next data or instructions needed for processing.
CPU Clock
-----------------------------------------------------------------------------------
-------------------------------
The CPU Clock manages the speed of the CPU. The clocks speed is an internal timing
in the processor which is measured in Megahertz
2.Instructions set
>Instruction set is the basic number of commands or instructions that a
processor understands or executes. The instructions set is also called command set.
3.Instruction size
>Instruction size refers to how many instructions or commands a
processor can hold.
4.Cache memory
>Cache memory refers to a temporary storage location that speeds up
access to frequently used data. It plays a vital role to a computers overall
performance.
Content of an Instruction Set
-----------------------------------------------------------------------------------
-------------------------------
An instruction set consists of opcode (operation code) which specifies the
operation to be performed such as to add content to memory; it also contains 0 or
more OPERAND specifiers. The operand specifies registers, memory locations or
literal data. Computer instructions indicate the operation to be performed and the
operand to use. The operands May come from memory, from registers or from the
instruction itself.
2.Register addressing
>In this addressing mode a register in stead of memory is used to
specify the operand. this is very similar to direct addressing except that instead
of a memory address the address field contains a register reference.
3.Indirect addressing
>In this addressing mode the bits in the address field specify a memory
address that is to be used as a pointer. The address of the OPERAND is found by
going to the memory address.
Terminologies
-----------------------------------------------------------------------------------
-------------------------------
1.Disk caching
>Disk Caching is a type of caching that involves the use of buffers to
separate operations that vary significantly in speed, so that the slower operation
does not hold up to the faster operation. The purpose of disk cache
is to improve processing speed.
2.Buffer
>A buffer is an internal memory area used for temporary storage of data
during input and output operations. This storage area is usually found in RAM.
3.Word size
>Word size refers to how much bits of instructions can be stored in
memory. A word is the amount of data and instructions the CPU can process or
manipulate at one time.
4.Word length
>Word Length refers to the number of bits the CPU can process at any
one time.
5.Surge protectors
>Surge protectors guards the computer equipment against spike in
electricity. They allow multiple components to be plugged into one power outlet.
6.Bolted regulator
>This is an electronic circuit used to maintain a constant level amount
of voltage in an electrical line. It eliminates power surges, spikes and brown outs
(low voltage).
Memory features
-----------------------------------------------------------------------------------
-------------------------------
Memory is determined by the following;
<speed
>speed refers to how fast data can be retrieved from memory.
<size
>the storage capacity of memory .
<volatility
>The ability of memory to change its content.
<word size
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
Computer Science
3/3/2025
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_PRODUCTS 100
#define FILENAME "inventory.txt"
// Function declarations
void addProduct(Product products[], int *count);
void viewProducts(Product products[], int count);
void searchProduct(Product products[], int count);
void deleteProduct(Product products[], int *count);
void saveProductsToFile(Product products[], int count);
void loadProductsFromFile(Product products[], int *count);
int main() {
int choice;
Product products[MAX_PRODUCTS];
int count = 0;
// Load existing products from file (if any)
loadProductsFromFile(products, &count);
do {
printf("\nBig J's Jerk Restaurant Inventory Management\n");
printf("1. Add Product\n");
printf("2. View Products\n");
printf("3. Search Product\n");
printf("4. Delete Product\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
getchar(); // Consume newline character left by scanf
switch (choice) {
case 1:
addProduct(products, &count);
break;
case 2:
viewProducts(products, count);
break;
case 3:
searchProduct(products, count);
break;
case 4:
deleteProduct(products, &count);
break;
case 5:
saveProductsToFile(products, count);
printf("Exiting program. Data saved to file.\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 5);
return 0;
}
(*count)++;
printf("Product added successfully!\n");
}
int found = 0;
for (int i = 0; i < count; i++) {
if (strcmp(products[i].name, searchName) == 0) {
printf("Product found:\n");
printf("Name: %s\n", products[i].name);
printf("Price: %.2f\n", products[i].price);
printf("Quantity: %d\n", products[i].quantity);
found = 1;
break;
}
}
if (!found) {
printf("Product not found.\n");
}
}
Computer science
3/11/2025
body
struct brochrec
{
int Id;
int quality;
int price;
}
struct bookrec book1, book2
#include <iostream>
int main() {
int result = larger(10, 20); // Example function call
std::cout << "Larger number: " << result << std::endl;
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
Computer Science
Port connectivity is the ability of a device to connect and communicate with other
devices and interfaces. Facilitating data communication.
E.g. connecting a laptop to a printer or a projector
-----------------------------------------------------------------------------------
-------------------------------
pda, laptop micro, mini, mainframe,
-----------------------------------------------------------------------------------
-------------------------------
instruction set
>number of commands or instructions the cpu can execute
-----------------------------------------------------------------------------------
-------------------------------
fetch
>retrive data from memory (RAM)
decode
>define what operation needs to be performed and by breaking down the
instruction into its opcodes and operands
excute
>processor performs the operation specified by the opcode on the operands
-----------------------------------------------------------------------------------
-------------------------------
>Opcode refers to a unique binary code that identifies the operation to be
performed(MOV-move, ADD-), while operands or registers that the instruction
operates
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
>RAM is volatile and used for temporary storage, while ROM is non-volatile
stores essential instructions.
Read-Only Memory (ROM) stores firmware and system boot instructions and is
Non-volatile meaning it retains data when power is off while Random Access Memory
(RAM) temporarily stores data and instructions for active processes and is
Volatile meaning it loses data when power is off.
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
>Erasable Programmable Read-Only Memory (EPROM) is Non-volatile memory that
can be erased using ultraviolet light and reprogrammed and is Non-volatile while
Electrically Erasable Programmable Read-Only Memory (EEPROM) is Non-volatile
memory that can be electrically erased and rewritten and is Non-volatile while
being Faster than EPROM, slower than RAM
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
A supercomputer is the most powerful type of computer, designed to perform complex
computations at extremely high speeds while A microcomputer is a small, personal
computer designed for individual use. Desktops are the most common type of
microcomputer, featuring a separate monitor, keyboard, and CPU unit.
Problem definition: State clearly the problem that you want to solve.
Problem analysis: Investigate the problem in detail by determining what the
input, process and output will be. Problem analysis involves identifying what the
inputs are and what process is needed to achieve a desired output or end result.
Generating possible solutions: At this stage all possible solutions to the
problem is identified. This is important as it gives the development team options
in relation to solving the problem.
Analyzing possible solutions: This stage will see the evaluation of each solution
generated in the previous stage in an effort to determine suitability to the
problem.
Select and develop the best solution: Here the team determines the most suitable
solution and represents it using a pseudocode or flowchart.
Implementation and review of solutions: At this stage the solution is developed
and deployed in the organization it is created for. Review is done to evaluate if
the solution effectively solves the problem.
ARRAY
-----------------------------------------------------------------------------------
-------------------------------
int variable_size(int arr[ ], int size, int n)
{
int counter, total;
for (counter [size];counter++)// For loop is iterating through the array
{
if (arr[counter]==n)
{
total++;// total =total + 1; is another way of incrementing by 1.
}
}
return total;
}
FUNCTION
-----------------------------------------------------------------------------------
-------------------------------
float CalculateVat(float price, float vat)
{
vat=0.165;
float newprice;
newprice=price+(price*vat);
return newprice;
}
STRUCTURE
-----------------------------------------------------------------------------------
-------------------------------
Struct BookRec
{
int Id;
int stock_quantity;
float price;
}
Struct BookRec book1, book2;
printf("enter Id for book 1 and book 2");
scanf("%d%d",&book1.Id, &book2.Id);
book1.price=book1.price+(book1.price*0.25);
The decimal system is the standard numbering system used in everyday life. It
consists of ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.
octal (base-8)
The octal systems uses eight digits: 0-7. it is often used in computing as a
shorthand for binary representation, with each octal digit corresponding to three
binary digits.
Hexadecimal (base-16)
the hexadecimal system consist of sixteen symbols:0-9 and A-F where A= 10 B= 11 C=
12 D= 13 E= 14 F=15. It is widely ued in computing because it provides a more
compact representation of binary numbers, with each hex digit corresponding to four
binary digits.
272^727= 128(1)| 262^626= 64(0)| 252^525= 32(1)| 242^424= 16(1)| 232^323= 8(0)|
222^222= 4(1)| 212^121= 2(1)| 202^020= 1(0)
128+32+16+4+2= 182
Cache memory is a smaller, faster memory component that stores frequently accessed
data and instructions, acting as a buffer between the CPU and the main memory (RAM)
This improves system performance by reducing the time it takes for the CPU to
access needed information, as it can retrieve data from the cache instead of the
slower RAM.
declarative languages are logic based rather than flow of control (what to do
instead of how to do it.) imperative are logic based and flow of control
focused(how instead of what)
START
FUNCTION main:
OPEN "menu.txt" in write mode
IF file fails to open:
DISPLAY "Could not open file"
EXIT with error
DO
CLEAR the screen
DISPLAY menu options:
1. Add an order
2. View order
3. Search for an order
4. Delete Orders
5. Exit
READ user's choice
FUNCTION addOrder:
DECLARE variables for meal and drink choices, quantities, prices, and totals
OPEN "menu.txt" in append mode
PROMPT for and READ customer name
PROMPT for meal choice and quantity
PROMPT for drink choice and quantity
FUNCTION viewOrder:
OPEN "menu.txt" in read mode
IF file not found:
DISPLAY "No orders found"
RETURN
IF no orders read:
DISPLAY "No orders found"
CLOSE file
FUNCTION searchOrders:
PROMPT for customer name to search
OPEN "menu.txt" in read mode
IF file not found:
DISPLAY "No orders found"
RETURN
IF not found:
DISPLAY "No order found for [name]"
CLOSE file
FUNCTION deleteOrders:
CLEAR screen
PROMPT for customer's name (as order number) to delete
OPEN "menu.txt" in read mode
OPEN "order.txt" in write mode (temp file)
DISPLAY summary stats (e.g., totals for meal types and drinks)
CLOSE files
FUNCTION exitProgram:
DISPLAY exit message
TERMINATE program
END