Computer Science IA Timothy Adams

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 97

-0- Computer Science I.

A|Timothy Adams|Fatima College


-1- Computer Science I.A|Timothy Adams|Fatima College
-2- Computer Science I.A|Timothy Adams|Fatima College

Computer Science I.A UNIT 1

Student : Timothy Adams

School : Fatima College

Class : L6-1
-3- Computer Science I.A|Timothy Adams|Fatima College

Introduction:

The Printing Company, We Print, which is situated in Diego Martin. Operates using a paper and file based system.

Storing their records in filing cabinents and folders, this slows the efficiency of the company and backing up documents

is a tedious task. We Print is a great company that satisfies the needs of its customers but are being held back by their

outdated record system.


-4- Computer Science I.A|Timothy Adams|Fatima College

Problem Definition:

This particular company conducts all their operations on a file based system that uses physical methods such as paper, files

and filing cabinets. With this system used, an arise of issues have been occurring, there has been misplaced documents,

transactions and operations such as cashing take a lengthy amount of time to process and to be recorded, taking inventory

and analysis have been subject to the same faith as well. The Management of We Print would like to conjure a new

method/system to eradicate the issues that hinder the efficiency of the company.
-5- Computer Science I.A|Timothy Adams|Fatima College

Identification of Specifications:

Functional Requirements

• Create a file following a naming system using the name of items as the file name.

• Output the amount available, the cost price and selling price into the file.

• Be able to view the file in the program, formatting the data in the file for user readability

• Be able to delete the item within the program

• Allow users to edit the item at a later date

• Mimic a cash register, using the files as the items in the database

• Save and record these transacations for later date

• Produce an audit that will inform the user of the profits,expenses and debts.

Non-Functional Requirements

• Some users of this program may not be computer literate

• The application is in exe format meaning it can only be ran by systems operationg on A windows OS

• Besides OS, Theres other specifications of the system that determine functionality such as RAM availability, processing

power and system storage.

• The security of the program is highly dependant on the security of the system it is ran on, meaning it can be prone to

espionage and data breaches.


-6- Computer Science I.A|Timothy Adams|Fatima College

Narrative:

int Main() : The main function, takes the constant character rocket which acts as the logo for the program and pushes it

up and out of the consoles current line, then calls the password() function and once the password function is completed, it

then calls the printMenu() function.

void password() : The Function password(), asks the user for the correct password which is "252558" to continue to

ensure that an authorized individual is using the program and if the wrong password is entered it will be looped until the

correct string is entered, as well as allowing the user to exit the program by entering "6".

void printMenu() : The Function printMenu(), prints out a graphical menu that lists all the options that the user can

select within the program which include :

1. Inventory

2. Point of Sales

3. View All Sales

4. Profit and Expenses

5. Exit

void selectMenu() : The Function selectMenu() is attached and called by the printMenu() function. It uses a switch

statement to perform the appropriate function based on which number the user entered.

Switch Statement:

if 1 is entered :

1. Inventory()

if 2 is entered :

2. pos()

if 3 is entered :

3. sale()

If 4 is entered :

4. PnE()

If 5 is entered :

5. exit(1)
-7- Computer Science I.A|Timothy Adams|Fatima College

void Inventory() : The Function Inventory(), prints to the console a Graphical User Interface like menu, to allow the

user to see the selection of options specific to inventory of the company.

void Check() : The Function Check() , checks the the countofstocks file to see if there is a number in it, if there is no

number or if the file doesn’t exist the file will be created and haave a number inside of it to ensure the functions that rely

on this file are able to get a number from it.

void inventoryMenu() : The Function inventoryMenu(), uses a switch statement to perform the appropriate function

based on which number the user entered.

Switch Statement:

if 1 is entered :

1. viewInventory()

if 2 is entered :

2. editInventory()

if 3 is entered :

3. delInvetory()

If 4 is entered :

4. printMenu()

void viewInventory() : The Function viewInventory() reads the listofstocks.txt file and takes that name and searches for

a file with that name and prints out the data in that file, it is then repeated for the number of stock in the the list by

reading the number from the countofstocks file.


-8- Computer Science I.A|Timothy Adams|Fatima College

void editInventory() : The Function editInventory() prints out the available stock by opening the list of stocks file taking

the name of the stock from listofstocks, searches for a file name that corresponds with that name and then scans in the

data from that file. The countofstocks file which holds the total number of stock gives the amount of time to repeat the

function and print out the data in the appropriate files, it is then repeated for x amount of time given from the

countofstocks. It then asks for a user input stating whether it is a stock name or the unique string printed out by the

randomstring variable and then passes that input to the editInventory2() function.

void editInventory2(char , char) : The Function editInventory(a,b) compares a(hold) against b(random) to see if true

and then performs the appropriate action. If a is equal to b then it will call the iftrueinv()function else if a is not equal to b

it will then call the iffalseinv() function and passes a.

void iftrueinv() : The Function iftrueinv() starts after a(hold),b(random) were compared and proven to be the same

string, the program will then create a new file that is named by the user and using the datastruct member “item” prints

out user entered variables into the file such as amount,costprice,selling price which are part of the datastruct and

increment the count of stocks by 1 later printing it out into the countofstocks file for later use.

void iffalseinv(char) : The function iffalseinv(a) starts after a(hold),b(random) are proven to not be the same string, the

program will then search for a(hold) in the listofstocks file and if found it searches for a file with the name of a(hold) and

scans it in and prints it out, and allows the user to overwrite the values of the members of the data struct eg amount,cp,sp

and prints it back out into the file. and then calls Inventory().

void delInventory() : The function delInventory () prints out all the stock, in the inventory and then asks the user which

one they would want to delete. program then takes this and passes it to the del() function

void del(char[]) : The function del(stock) takes in the string stock then asks user to confirm that they want to delete this

file by entering the random string on their screen, the program then searches for the file name with the name of “stock”

and then deletes it, if the file is deleted it calls the updatelist() function and passes stock else if it is not deleted it prints

out the error based on the variable errno integer value.


-9- Computer Science I.A|Timothy Adams|Fatima College

void updatelist(char[]) : The function updatelist(stock) takes in the string stock and then searches the file

listofallstocks.txt and looks for any occurences of “stock” and calls the removeAll() function that removes it. Puts the

text of the files in the temp file and renames it with the original name of the listofallstocks file.

void removeAll(char *, const char * ) : The Function void removeAll(char *, const char *) takes the length of the

string,the string and searches the listofallstocks.txt file to find any occurences of the word and removes it.

char *randstring(size_t) : The Function *randstring randomizes a string based on the size of the length variable passed

through.

void pos() : The Function pos() is the point of sale function of the program and acts like a cash register, it asks user to

enter the item, and the amount being purchased

returns the total price and then asks for the amount the customer has given and returns the amount of change to give if the

amount paid is more than the price,then saves this and the time of transaction to the transaction file to be read in another

function.

void startfiles() : The Function startfiles() ensures that all the files related to the pos() function that doesnt include a

number are initialised with 0 to ensure a number is in it to be read

void Sale() : The Function sale() prints out the transaction file that shows all the transactions that occurred.

void PnE() : Function to print out the total income,expenses and prints out whether if it is a profit or a loss.
- 10 - Computer Science I.A|Timothy Adams|Fatima College

Psuedocode:

Use <stdio.h

Use <stdlib.h

Use <string.h>

Use <windows.h>

Use <unistd.h>

Use <conio.h>

Use <errno.h>

Use <time.h>

#define BUFFER_SIZE 1000

struct stock

Begin

char item 100

int amount

float cp

float sp

End item_stock

main

Begin

for int i = 0 i < 50 i ++ Display

systemcolor 9F

Display rocket

int j = 300000

for int i = 0 i < 50 i ++ Begin


- 11 - Computer Science I.A|Timothy Adams|Fatima College

u delay j

j = intj * 0.9

Display

End

password

printMenu/

End

void password

Begin

systemcolor 1B

Display

char password 6

while1

Begin

Display Please enter the password to use this program or enter 6 to exit :

input password

if string compare password 6

Begin delay 2000

system clearscreen

Display Exiting in 3 seconds...

delay 3000

exit1
- 12 - Computer Science I.A|Timothy Adams|Fatima College

End

else

Begin

if string compare password 252558

Begin

systemcolor 1A

system clearscreen

Display Correct Password entered!

u delay 900000

system clearscreen

systemcolor 1C

Display By Timothy Adams Fatima College Form 6

u delay 900000

system clearscreen

systemcolor 1A

systemPause

break

End

else //incorrect password entered

system clearscreen

Display You have entered the wrong password! Please try again.

u delay 900000

End

End

system clearscreen

End
- 13 - Computer Science I.A|Timothy Adams|Fatima College

printMenu

Begin

system clearscreen

systemcolor 1F

Display

Display

Display |All In One System|

Display

Display ______________________________

_________________________________

Display ||

Display ||

Display ||

Display ||

Display | 1.

Display Inventory

Display |

Display | 2. Point Of

Display Sale

Display |

Display | 3. View All

Display Sales

Display |

Display | 4.
- 14 - Computer Science I.A|Timothy Adams|Fatima College

Display Profit

Display And

Display Expenses

Display |

Display | 5.

Display Exit

Display |

Display ||

Display ||

Display ||

Display ||

Display _________________________________

______________________________

selectMenu

End

void selectMenu

Begin

int choice

Display Enter your choice :

input choice

switch choice Begin

case 1:

Inventory

break
- 15 - Computer Science I.A|Timothy Adams|Fatima College

case 2:

pos

break

case 3:

sale

break

case 4:

PnE

break

case 5:

Display Exiting...

Display Exiting in 3 seconds...

delay 3000

exit1

break

default:

system clearscreen

Display invalid choice Try again

delay 3000

printMenu

End
- 16 - Computer Science I.A|Timothy Adams|Fatima College

End

void Inventory

Begin

system clearscreen

systemcolor 1F

Display

Display

Display Inventory

Display

Display ______________________________

_________________________________

Display ||

Display ||

Display | 1. View Inventory |

Display | 2. Edit Inventory|

Display | 3. Delete Stock |

Display | 4. Return to Menu|

Display ||

Display ||

Display ||

Display ||

Display _________________________________

______________________________

check

End
- 17 - Computer Science I.A|Timothy Adams|Fatima College

check

Begin

File check=fopencountofstocks.txt r

if check==NULL||check==\0

Begin

fclosecheck

File intialise=fopencountofstocks.txt w

int num=0

fDisplay intialise num

fcloseintialise

inventoryMenu

End

else already

Begin

fclosecheck

inventoryMenu

End

End

inventoryMenu

Begin

int choice

Display Enter your choice :

input choice

switch choice Begin

case 1:

viewInventory
- 18 - Computer Science I.A|Timothy Adams|Fatima College

break

case 2:

editInventory

break

case 3:

delInventory

break

case 4:

Display Returning...

Display Returning in 3 seconds...

delay 3000

system clearscreen

printMenu

default:

system clearscreen

Display Invalid choice Try again

systempause

Inventory

End

End
- 19 - Computer Science I.A|Timothy Adams|Fatima College

viewInventory

Begin

File count=fopencountofstocks.txt r

int i max

char item 100

input count max

fclosecount

File in=fopenlistofallstocks.txt r

File read

system clearscreen

if in not equal to NULL

Begin

fori=0i<maxi++

Begin

input in item_stock i .item

read=fopenitem_stock i .item r

Display *

Display

Display item_stock i .item

Display :

input read item_stock i .amoun

Display item_stock i .amount

Display Units Available

input read item_stock i .cp

Display Costs $
- 20 - Computer Science I.A|Timothy Adams|Fatima College

Display %0.2f item_stock i .cp

input read item_stock i .sp

Display Dollars

Display and is sold for

Display $

Display %0.2f item_stock i .sp

Display Dollars

Display *

End

fclosein

Display These are currently all the stock in Inventory

fcloseread

systempause

Display Returning...

delay 2000

Inventory

End

else

Begin

fclosein

fclosecount

fcloseread

Display No stock in the database please add stocks using the Edit Inventory Option

systempause

Display Returning...

delay 2000
- 21 - Computer Science I.A|Timothy Adams|Fatima College

Inventory

End

if max==0

Begin

fclosein

fclosecount

fcloseread

Display No stock in the database please add stocks using the Edit Inventory Option

systempause

Display Returning...

delay 2000

Inventory

End

End

editInventory

Begin

const int limit=5

char *randstringsize_t

char hold 100 *random

time_t t

srandunsignedtime t

int max i

File count=fopencountofstocks.txt r

input count max

fclosecount

File in=fopenlistofallstocks.txt r
- 22 - Computer Science I.A|Timothy Adams|Fatima College

File read

Display All the stock found in the database are below

fori=0i<maxi++

Begin

input in item_stock i .item

read=fopenitem_stock i .item r

Display *

Display

Display item_stock i .item

Display :

input read item_stock i .amount

Display item_stock i .amount

Display Units Available

input read item_stock i .cp

Display Costs

Display %0.2f item_stock i .cp

input read item_stock i .sp

Display Dollars

Display and is sold for

Display $

Display %0.2f item_stock i .sp

Display Dollars

Display *

End

random=randstringlimit

Display Enter the stock to editThe Stock Must exist in the above list
- 23 - Computer Science I.A|Timothy Adams|Fatima College

Display Or enter

Display random

Display to add a new stock

Display Enter stock name an Invalid choice will cause the program to close :

input hold

editInventory2hold random

End

editInventory2

Begin

if string compare a b

Begin

if trueinv

End

else

if string comparea b not equal to 0

Begin

if falseinva

End

End

if trueinv

Begin

int current store

system clearscreen

File data

File count=fopencountofstocks.txt r

input count store


- 24 - Computer Science I.A|Timothy Adams|Fatima College

fclosecount

current=store+1

File countout=fopencountofstocks.txt w

fDisplay countout current

fclosecountout

Display Enter the name of the new stock

Display no spaces :

fflushstdin

input item_stock store .item 100 stdin

char letter checkspace 100

strcpycheckspace item_stock store .item

checkspace string char spancheckspace ='\0'

Display Checking to see if ' ' has any spaces checkspace

systempause

letter=checkspace 0

Display Starting at the letter letter

int block=0 spaces=0

do

Begin

letter=checkspace block

if isspaceletter

Begin

spaces++

Display Space found checking again

Display space found so far spaces

End
- 25 - Computer Science I.A|Timothy Adams|Fatima College

block++

End

whileletter not equal to '\0'

if spaces>=1

Begin

Display space detected use '_' instead

do

Begin

Display The name of the item has a spacex spaces

Display Try again...

Display Enter the name of the new stock no spaces:

fflushstdin

input item_stock store .item 100 stdin

memsetcheckspace 0 100

strcpycheckspace item_stock store .item

checkspace string char spancheckspace ='\0'

Display Checking to see if ' ' has any spaces checkspace

letter=checkspace 0

block=0 spaces=0

whileletter not equal to '\0'

Begin

letter=checkspace block

if isspaceletter

Begin

spaces++

Display Space found checking again


- 26 - Computer Science I.A|Timothy Adams|Fatima College

Display space found so far spaces

End

block++

End

End

whilespaces not equal to 0

End

Display no spaces found

item_stock store .item string char spanitem_stock store .item ='\0'

Display The Stock was successfully created item_stock store .item

Display The original number of stocks is now . store current

fflushstdin

Display Enter the available amount for stock : item_stock store .item

input item_stock store .amount

Display Enter the cost price for stock : item_stock store .item

input item_stock store .cp

Display $%0.2f item_stock store .cp

Display dollars paid for one unit of item_stock store .item

Display Enter the selling price for stock : item_stock store .item

input item_stock store .sp

Display $%0.2f item_stock store .sp

Display dollars is the selling price for one unit of item_stock store .item

data=fopenitem_stock store .item w

Display data item_stock store .amount

Display data %0.2f item_stock store .cp

Display data %0.2f item_stock store .sp


- 27 - Computer Science I.A|Timothy Adams|Fatima College

closedata

File list=fopenlistofallstocks.txt a

Display list item_stock store .item

closelist

Display Data written successfully.

delay 3000

Display Returning to menu....

Inventory

End

if falseinv

Begin

File count=fopencountofstocks.txt r

File in=fopenlistofallstocks.txt r

File read

int i i2 max

input count max

fori=0i<=maxi++

Begin

input in item_stock i .item

File read=fopenitem_stock i .item r

input read item_stock i .amount

input read item_stock i .cp

input read item_stock i .sp

if string comparea item_stock i .item==0

Begin

File data
- 28 - Computer Science I.A|Timothy Adams|Fatima College

system clearscreen

Display The stock

Display item_stock i .item

Display has

Display item_stock i .amou

Display %0.2f item_stock i .cp

Display dollars and is resold for

Display %0.2f item_stock i .sp

Display dollars

Display If some values remain the same please re-enter the original value

Display Enter the new amount of the stock : item_stock i .item

input item_stock i .amount

Display Enter the new cost price :

input item_stock i .cp

Display $%0.2f item_stock i .cp

Display dollars paid for one unit of item_stock i .item

Display Enter the new selling price :

input item_stock i .sp

Display $%0.2f item_stock i .s

Display dollars is the selling price for one unit of item_stock i .item

Display Editing Data for item_stock i .item

File edit=fopenitem_stock i .item w

fDisplay edit item_stock i .amount

fDisplay edit %0.2f item_stock i .cp

fDisplay edit %0.2f item_stock i .sp

fcloseedit
- 29 - Computer Science I.A|Timothy Adams|Fatima College

Display Data edited and saved

Display Returning to menu

systempause

Inventory

i2=60

End

End

if i2 not equal to 60

Begin

fcloseread

fclosecount

fclosein

system clearscreen

systemcolor 1C

Display Cannot open FILE

delay 1000

systempause

system clearscreen

systemcolor 1F

Inventory

End

fcloseread

fclosecount

End
- 30 - Computer Science I.A|Timothy Adams|Fatima College

delInventory

Begin

system clearscreen

int max i

File count=fopencountofstocks.txt r

input count max

fclosecount

File in=fopenlistofallstocks.txt r

File read

if in not equal to NULL

Begin

fori=0i<maxi++

Begin

input in item_stock i .item

read=fopenitem_stock i .item r

Display *

Display

Display item_stock i .item

Display :

input read item_stock i .amount

SetConsoleTextAttributehConsole FOREGROUND_BLUE|BACKGROUND_BLUE

Display item_stock i .amount

Display Units Available

input read item_stock i .cp

Display Costs $
- 31 - Computer Science I.A|Timothy Adams|Fatima College

Display %0.2f item_stock i .cp

input read item_stock i .sp

Display Dollars

Display and is sold for

Display $

Display %0.2f item_stock i .sp

Display Dollars

Display *

End

fclosein

Display These are currently all the stock in Inventory

fcloseread

End

char stock 200

Display Please enter the stock to delete :

input stock

Display entered searching for file. stock

delstock

End

delstock

Begin

const int limit=5

char *randstringsize_t

char hold 100 *random

time_t t
- 32 - Computer Science I.A|Timothy Adams|Fatima College

srandunsignedtime t

random=randstringlimit

Display To confirm that you are sure about deleting the file please type

Display random

Display Or enter x to exit :

input hold

if string comparehold random==0

Begin

if removestock==0

Begin

Display File Successfully Deleted

systempause

updateliststock

End

else

Begin

Display File was not deleted.

if errno==1

Begin

Display Operation not permitted

End

else

if errno==2

Begin

Display No such file or directory

End
- 33 - Computer Science I.A|Timothy Adams|Fatima College

else

if errno==3

Begin

Display No such process

End

else

if errno==4

Begin

Display Interrupted system call

End

else

if errno==5

Begin

Display I/O error

End

else

if errno==6

Begin

Display No such device or address

End

else

if errno==7

Begin

Display Argument list too long

End

else
- 34 - Computer Science I.A|Timothy Adams|Fatima College

if errno==8

Begin

Display Exec format error

End

else

if errno==9

Begin

Display Bad file number

End

else

if errno==10

Begin

Display No child processes

End

else

if errno==11

Begin

Display Try again

End

else

if errno==12

Begin

Display Out of memory

End

else

if errno==13
- 35 - Computer Science I.A|Timothy Adams|Fatima College

Begin

Display Permission denied Try running the exe of this build as administrator

End

systempause

printMenu

End

End

else

Begin

Display Operation Cancelled

Display Exiting to menu

systempause

Inventory

End

End

updatelista

Begin

File fPtr

File fTemp

char path 21

char toRemove 100

char buffer 1000

strcpypath listofallstocks.txt

strcpytoRemove a

Display Reading the stock list ' ' and looking for the stock path toRemove
- 36 - Computer Science I.A|Timothy Adams|Fatima College

fPtr = fopenpath

fTemp = fopendelete.tmp w

if fPtr == NULL || fTemp == NULL

Begin

Display Unable to open stock file.

Display Please check whether file exists and you have read/write privilege.

exitEXIT_SUCCESS

End

while input buffer BUFFER_SIZE fPtr not equal to NULL

Begin

removeAllbuffer toRemove

fputsbuffer fTemp

End

fclosefPtr

fclosefTemp

removepath

renamedelete.tmp path

Display All occurrence of ' ' removed successfully. toRemove

File count=fopencountofstocks.txt r

int max

input count max

fclosecount

File countout=fopencountofstocks.txt w

int current

current=max-1

Display The original number of stock is now max current


- 37 - Computer Science I.A|Timothy Adams|Fatima College

fDisplay countout current

fclosecountout

systempause

printMenu

End

removeAllchar * str const char * toRemove

Begin

int i j stringLen toRemoveLen

int found

stringLen= strlenstr

toRemoveLen=strlentoRemove

fori=0 i <= stringLen - toRemoveLen i++

Begin

found = 1

forj=0 j < toRemoveLen j++

Begin

if str i + j not equal to toRemove j

Begin

found = 0

break

End

End

if str i + j not equal to ' ' str i + j not equal to '' str i + j not equal to '' str i + j not equal to '\0'

Begin

found = 0
- 38 - Computer Science I.A|Timothy Adams|Fatima College

End

if found == 1

Begin

forj=i j <= stringLen - toRemoveLen j++

Begin

str j = str j + toRemoveLen

End

stringLen = stringLen - toRemoveLen

i--

End

End

End

randstringsize_t length Begin

static char charset = abcdefghijklmnopqrstuvwxyz0123456789

char *randomString = NULL

if length

Begin

randomString=mallocsizeofchar*length +1

if randomString

Begin

for int n = 0n<lengthn++

Begin

int key = rand%36-1

randomString n = charset key

End

End
- 39 - Computer Science I.A|Timothy Adams|Fatima College

End

return char *randomString

pos

Begin

startfiles

Display ------------------------------------------------------------

File count=fopencountofstocks.txt r

int i id max limit total amount

float n change

char item 100 tempvalue 100

input count max

File in=fopenlistofallstocks.txt r

File read

File current=fopenongoingtransaction.txt w

fDisplay current \0

system clearscreen

if in not equal to NULL

Begin

Display all the available stock are below

fori=0i<maxi++

Begin

input in item_stock i .item

read=fopenitem_stock i .item r

Display
- 40 - Computer Science I.A|Timothy Adams|Fatima College

Display : item_stock i .item

input read item_stock i .amount

Display Units: item_stock i .amount

input read item_stock i .cp

Display Cost: $%0.2f item_stock i .cp

input read item_stock i .sp

Display Selling Price: $%0.2f item_stock i .sp

Display

End

int flag

do

Begin

Display Please enter how much times to repeat the purchase function for each stock being purchasedor -9 to exit :

char term

i input limit term not equal to 2 || term not equal to ''

Begin

Display Invalid Data type Try again

systempause

system clearscreen

fflushstdin

flag=1End

else

Begin

flag=0

Display Valid integer entered

End
- 41 - Computer Science I.A|Timothy Adams|Fatima College

Endwhileflag not equal to 0

if limit==-9

Begin

Display Exiting to Menu

Display process cancelled

systempause

Inventory

End

else

if limit==1

Begin

Display One entered...

Display This process will only happen once

systempause

End

else

if limit<=0

Begin

do

Begin

Display Invalid number please enter a valid number starting from 1

Display Please enter how much times to repeat the purchase function for each stock being purchased :

input limit

End

whilelimit<1

End
- 42 - Computer Science I.A|Timothy Adams|Fatima College

else

if limit>1

Begin

Display This process will be repeated times limit

systempause

End

forint i2=1i2<=limiti2++

Begin

system clearscreen

Display all the available stock are below

forint i4=0i4<maxi4++

Begin

input in item_stock i4 .item

read=fopenitem_stock i4 .item r

Display

Display : item_stock i4 .item

input read item_stock i4 .amount

Display Units: item_stock i4 .amount

input read item_stock i4 .cp

Display Cost: $%0.2f item_stock i4 .cp

input read item_stock i4 .sp

Display Selling Price: $%0.2f item_stock i4 .sp

Display

End

int ch

Display Enter the item :


- 43 - Computer Science I.A|Timothy Adams|Fatima College

input item

fori=0i<maxi++

Begin

if string compareitem item_stock i .item==0

Begin

Display Item found!

if item_stock i .amount<=0

Begin

Display Sorry There is no available amount in this stock.

systempause

printMenu

End

Display Enter the quantity being purchased :

input amount

id=i

if amount>item_stock i .amount

Begin

do

Begin

Display This amount is more than the available amount

Display Enter a valid amount :

input amount

End whileamount>item_stock i .amount

End

Display Total for is : units X %0.2f dollars item_stock i .item amount item_stock i .sp

n=item_stock i .sp*amount
- 44 - Computer Science I.A|Timothy Adams|Fatima College

Display Item : | Quantity : | Price : $%0.2f each | Total : $%0.2f dollars item_stock i .item amount item_stock i .sp n

fclosecurrent

File current2=fopenongoingtransaction.txt w

fDisplay current2 Item : | Quantity : | Price : $%0.2f each | Total : $%0.2f dollars item_stock i .item amount item_stock i

.sp n

fclosecurrent2

systempause

ch=60

End

else

if ch not equal to 60

Begin

Display Invalid Entry Item does not exist

systempause

printMenu

End

End

File current2=fopenongoingtransaction.txt a

fDisplay current2 -----------------%0.2f n

File current3=fopenongoingtransaction.txt r

char s

whiles=fgetccurrent3 not equal to end of file Begin

Display s

End

float payment

Display Enter the amount of money the customer has given :


- 45 - Computer Science I.A|Timothy Adams|Fatima College

input payment

change=payment-n

if change<0

Begin

float remain

change=n-payment

Display The customer is owing $%0.2f dollars change

systempause

Display Enter the remaining amount the customer has given :

input remain

change=remain-change

End

int LEN=150

char buf LEN

time_t curtime

struct tm *loc_time

curtime = time NULL

loc_time = localtime curtime

File lastprocess=fopenlasttransaction.txt w

if change>0

Begin

File sales=fopentotalsales.txt a

Display Please give the customer $%0.2f dollars change change

Display Transaction Saved

fDisplay sales Item : | Quantity : | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f | Change : $%0.2f item_stock

id .item amount item_stock id .sp n payment change


- 46 - Computer Science I.A|Timothy Adams|Fatima College

fDisplay sales Processed at : ---------------------------------- asctime loc_time

fDisplay lastprocess asctime loc_time

fcloselastprocess

fclosesales

Display Item : | Quantity : | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f | Change : $%0.2f item_stock id

.item amount item_stock id .sp n payment change

Display Processed at : asctime loc_time

File expensesr=fopenexpenses.txt r

float expenses

File profitsr=fopenprofits.txt r

float profits

File totalr=fopenpayments.txt r

float paymenttotal

input totalr paymenttotal

input expensesr expenses

input profitsr profits

fcloseexpensesr

fcloseprofitsr

fclosetotalr

paymenttotal=paymenttotal+n

expenses=expenses+item_stock id .cp*amount

profits=profits+n-expenses

File expensesw=fopenexpenses.txt w

fDisplay expensesw %0.2f expenses

File profitsw=fopenprofits.txt w

fDisplay profitsw %0.2f profits


- 47 - Computer Science I.A|Timothy Adams|Fatima College

File totalw=fopenpayments.txt w

fDisplay totalw %0.2f paymenttotal

fcloseexpensesw

fcloseprofitsw

fclosetotalw

systempause

system clearscreen

item_stock id .amount=item_stock id .amount-amount

Display units of left item_stock id .amount item_stock id .item

File data=fopenitem_stock id .item w

fDisplay data item_stock id .amount

fDisplay data %0.2f item_stock id .cp

fDisplay data %0.2f item_stock id .sp

fclosedata

systempause

End

if change==0

Begin

File sales=fopentotalsales.txt a

Display Transaction Saved

fDisplay sales Item : | Quantity : | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f | Change : $%0.2f item_stock

id .item amount item_stock id .sp n payment change

fDisplay sales Processed at : ---------------------------------- asctime loc_time

fDisplay lastprocess asctime loc_time

fclosesales

fcloselastprocess
- 48 - Computer Science I.A|Timothy Adams|Fatima College

Display Item : | Quantity : | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f | Change : $%0.2f item_stock id

.item amount item_stock id .sp n payment change

Display Processed at : asctime loc_time

systempause

system clearscreen

File expensesr=fopenexpenses.txt r

float expenses

File profitsr=fopenprofits.txt r

float profits

File totalr=fopenpayments.txt r

float paymenttotal

input totalr paymenttotal

input expensesr expenses

input profitsr profits

fcloseexpensesr

fcloseprofitsr

fclosetotalr

paymenttotal=paymenttotal+n

expenses=expenses+item_stock id .cp*amount

profits=profits+n-expenses

File expensesw=fopenexpenses.txt w

fDisplay expensesw %0.2f expenses

File profitsw=fopenprofits.txt w

fDisplay profitsw %0.2f profits

File totalw=fopenpayments.txt w

fDisplay totalw %0.2f paymenttotal


- 49 - Computer Science I.A|Timothy Adams|Fatima College

fcloseexpensesw

fcloseprofitsw

fclosetotalw

systempause

system clearscreen

item_stock id .amount=item_stock id .amount-amount

Display units of left item_stock id .amount item_stock id .item

File data=fopenitem_stock id .item w

fDisplay data item_stock id .amount

fDisplay data %0.2f item_stock id .cp

fDisplay data %0.2f item_stock id .sp

fclosedata

systempause

End

End

sale

End

else

Begin

system clearscreen

Display No Stocks in database

systempause

printMenu

End

End
- 50 - Computer Science I.A|Timothy Adams|Fatima College

startfiles

Begin

File check=fopenexpenses.txt r

if check==NULL||check==\0

Begin

File intialise=fopenexpenses.txt w

int num=0

fDisplay intialise num

fclosecheck

fcloseintialise

End

File check1=fopenprofits.txt r

if check1==NULL||check1==\0

Begin

File intialise=fopenprofits.txt w

int num=0

fDisplay intialise num

fclosecheck1

fcloseintialise

End

File check2=fopenpayments.txt r

if check2==NULL||check2==\0

Begin

File intialise=fopenpayments.txt w

int num=0

fDisplay intialise num


- 51 - Computer Science I.A|Timothy Adams|Fatima College

fclosecheck2

fcloseintialise

End

End

sale

Begin

File lastprocess=fopenlasttransaction.txt r

File current3=fopentotalsales.txt r

system clearscreen

if lastprocess not equal to NULL current3 not equal to NULL

Begin

Display Sales

Display Last Transaction was at :

char s

whiles=fgetclastprocess not equal to end of file Begin

Display s

End

Display ----------------------------------

whiles=fgetccurrent3 not equal to end of file Begin

Display s

End

systempause

printMenu

End

else

Begin
- 52 - Computer Science I.A|Timothy Adams|Fatima College

system clearscreen

Display No Stocks in database

systempause

printMenu

End

End

PnE

Begin

File expenses=fopenexpenses.txt r

File lastprocess=fopenlasttransaction.txt r

File total=fopenpayments.txt r

File profits=fopenprofits.txt r

if expenses not equal to NULL lastprocess not equal to NULL total not equal to NULL profits not equal to NULL

Begin

system clearscreen

systemcolor 3F

float expenses1

input expenses 0.2f expenses1

char s

Display After the last transaction at :

whiles=fgetclastprocess not equal to end of file Begin

Display s

End

Display The business's expenses ran a total of :

Display $

whiles=fgetcexpenses not equal to end of file Begin


- 53 - Computer Science I.A|Timothy Adams|Fatima College

Display s

End

Display dollars

Display With a total income of :

Display $

whiles=fgetctotal not equal to end of file Begin

Display s

End

Display dollars

float profits1

input profits 0.2f profits1

float total1

input total 0.2f total1

if expenses1>total1

Begin

int expenses2

expenses2=profits1-expenses1

Display Unfortunately suffering a debt of %0.2f expenses2

Display Due to the profit income of

Display $

whiles=fgetcprofits not equal to end of file Begin

Display s

End

Display dollars

systempause

printMenu
- 54 - Computer Science I.A|Timothy Adams|Fatima College

End

else

Begin

Display Making a profit income of :

Display $

whiles=fgetcprofits not equal to end of file Begin

Display s

End

Display dollars

End

systempause

printMenu

End

else

Begin

system clearscreen

Display No Stocks in database

systempause

printMenu

End

End
- 55 - Computer Science I.A|Timothy Adams|Fatima College

Source Code:
1 //VVVVVHEADERSVVVVV
2
3 /*A header file in C is the one in which it contains function declarations/ definitions,
4 variables and macro definitions
5 to be shared between several source files and has a filename with extension ".h".*/
6
7 /*---------------------------------------------------------------------------------------------------------------
--*/
8 #include <stdio.h>//Including Standard Input Output,Allows program to take input and produce output as
well,HEADER
9 /*---------------------------------------------------------------------------------------------------------------
--*/
10 #include <stdlib.h>//Including Standard library,Allows program to use unsigned interger types,NULL,malloc
etc,HEADER
11 /*---------------------------------------------------------------------------------------------------------------
--*/
12 #include <string.h>//Including String, Allows program to use NULL,strcmp and strcpy and array allocation,HEADER
13 /*---------------------------------------------------------------------------------------------------------------
--*/
14 #include <windows.h>//Including Windows,Windows-specific header file for C allowing for sleep(),Handle,HEADER
15 /*---------------------------------------------------------------------------------------------------------------
--*/
16 #include <unistd.h>//Including C POSIX library,Allows program to use NULL,write,FILE management,HEADER
17 /*---------------------------------------------------------------------------------------------------------------
--*/
18 #include <conio.h>//Including Console Input Output,Allows program to use clrscr,getch,HEADER
19 /*---------------------------------------------------------------------------------------------------------------
--*/
20 #include <errno.h>//Including Error Number,def..integer variable errno,which number corresponds with an
error,HEADER
21 /*---------------------------------------------------------------------------------------------------------------
--*/
22 #include <time.h>//Including Time,defines the tm structure which records various members for time and
*asctime,HEADER
23 /*struct tm {
24 int tm_sec; // seconds, range 0 to 59 //
25 int tm_min; // minutes, range 0 to 59 //
26 int tm_hour; // hours, range 0 to 23 //
27 int tm_mday; // day of the month, range 1 to 31 //
28 int tm_mon; // month, range 0 to 11 //
29 int tm_year; // The number of years since 1900 //
30 int tm_wday; // day of the week, range 0 to 6 //
31 int tm_yday; // day in the year, range 0 to 365 //
32 int tm_isdst; // daylight saving time //
33 };*/
34 /*---------------------------------------------------------------------------------------------------------------
--*/
35 #define BUFFER_SIZE 1000//character array size defined for later on in the program,function del()
36 /*---------------------------------------------------------------------------------------------------------------
--*/
37
38
39 /*---------------------------------------------------------------------------------------------------------------
--*/
40 struct stock //data structure to save various information about item stock, used later on
41 {
42 //members of the data structure
43 char item[100]; //name of item
44 int amount; //amount of the item available
45 float cp; //cp=cost price, cost price of the item(how much the company paid for one unit of the item)
46 float sp; //sp=selling price, selling price of the item(how much the companny is selling for one unit of the
item)
47 }item_stock[1000]; //name of the structure variable
48 /*---------------------------------------------------------------------------------------------------------------
--*/
49
50
51
52
53 /*---------------------------------------------------------------------------------------------------------------
--*/
54 const /*declaring a constant character*/ char rocket[] =
55 " _\n\
56 /^\\\n\
57 |-|\n\
58 |W|\n\
59 |E|\n\
60 | |\n\
61 |P|\n\
62 |R|\n\
63 /|I|\\\n\
64 / |N| \\\n\
65 | |T| |\n\
66 `-\"\"\"-`\n\
67 ";//We print logo for boot up
68 /*---------------------------------------------------------------------------------------------------------------
--*/
69
70
71
- 56 - Computer Science I.A|Timothy Adams|Fatima College

72 /*---------------------------------------------------------------------------------------------------------------
--*/
73 int main() //Main function
74
75 {
76 for (int i = 0; i < 50; i ++) printf("\n"); // jump to bottom of console
77 system("color 9F");
78 printf("%s", rocket);
79 int j = 300000; //determines how long the rocket takes to move up.
80 for ( int i = 0; i < 50; i ++) {
81 usleep(j);
82 j = (int)(j * 0.9);
83 printf("\n"); // move rocket a line upward
84 }
85
86 password();//Calls the password function
87 printMenu();//Calls the print menu function
88
89 } //End of Function
90 /*---------------------------------------------------------------------------------------------------------------
--*/
91
92
93 /**
94 * Function password(), asks the user for the password "252558" to continue to ensure that an authorized
individual is using the program
95 * as well as allowing the user to exit by entering "6"
96 */
97 /*---------------------------------------------------------------------------------------------------------------
--*/
98 void password()
99 {
100 system("color 1B");
101 printf("\n");
102 char password[6];
103 while(1) //a loop that repeats indefinitely until broken by the break; statement
104 {
105 printf("Please enter the password to use this program or enter 6 to exit : \n");
106 scanf("%s",password);
107 if (strcmp(password,"6")==0)
108 { Sleep(2000);
109 system("cls");
110 printf("Exiting in 3 seconds...\n");
111 Sleep(3000);
112 exit(1); //exit loop indefinitely
113 }
114 else //if the condition if (strcmp(password,"6")==0) is not true it will then perform this else if
115 {
116 if (strcmp(password,"252558")==0) //password is 252558
117 {
118 system("color 1A");
119 system("cls");
120 printf("Correct Password entered!\n");
121 usleep(900000);
122 system("cls");
123 system("color 1C");
124 printf("By Timothy Adams Fatima College Form 6");
125 usleep(900000);
126 system("cls");
127 system("color 1A");
128 system("Pause");
129 break;
130 }
131 else //incorrect password entered
132 system("cls");
133 printf("You have entered the wrong password! Please try again.\n");
134 usleep(900000);
135 }
136 }
137 system("cls");
138 } //while repeats until 6 or the correct password is entered. //End Of Function
139 /*---------------------------------------------------------------------------------------------------------------
--*/
140
141
142
143 /**
144 * Function printMenu(), prints to the console a Graphical User Interface like menu,
145 * to make selection of options much accesible and easier.
146 */
147 /*---------------------------------------------------------------------------------------------------------------
--*/
148 void printMenu()
149 {
150 system("cls");
151
152 system("color 1F");
153 printf("\n");
154
155 // Create Menu
156 printf("\xB2 \xB2\xB2\xB2\xB2"
157 "\xB2\xB2\xB2\xB2\xB2"
158 "\xB2\xB2\xB2\xB2\xB2 We Print");//\xB2 is a special character that resembles a block.
- 57 - Computer Science I.A|Timothy Adams|Fatima College

159
160 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);//Console Color Handle
161 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE); //Defines the color of text (FOREGROUND)
and background of menu (BACKGROUND) both use RED,BLUE,GREEN
162 printf("|All In One System|");
163
164 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE); //There can be more than one FOREGROUND color these colors are
mixed to produce one color, for eg red green blue makes white and that color is intensified using FOREGROUND_INTENSITY.
same goes for BACKGROUND
165 printf("\xB2\xB2\xB2\xB2"
166 "\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"
167 "\xB2\xB2 \xB2");
168 printf("\n ______________________________"
169 "_________________________________");
170 printf("\n|\t\t\t\t\t\t\t\t|");
171 printf("\n|\t\t\t\t\t\t\t\t|");
172 printf("\n|\t\t\t\t\t\t\t\t|");
173 printf("\n|\t\t\t\t\t\t\t\t|");
174 printf("\n|\t\t\t 1. ");
175 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE);
176 printf("Inventory \t\t\t\t");
177 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
178 printf("|");
179 printf("\n|\t\t\t 2. Point Of ");
180 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|FOREGROUND_RED|BACKGROUND_BLUE);
181 printf("Sale \t\t\t");
182 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
183 printf("|");
184 printf("\n|\t\t\t 3. View All");
185 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|FOREGROUND_RED|BACKGROUND_BLUE);
186 printf(" Sales \t\t\t");
187 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
188 printf("|");
189 printf("\n|\t\t\t 4. ");
190 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE|FOREGROUND_INTENSITY);
191 printf("Profit");
192 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
193 printf(" And ");
194 SetConsoleTextAttribute(hConsole, FOREGROUND_RED|BACKGROUND_BLUE|FOREGROUND_INTENSITY);
195 printf("Expenses \t\t");
196 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
197 printf("|");
198 printf("\n|\t\t\t 5. ");
199 SetConsoleTextAttribute(hConsole, FOREGROUND_RED|BACKGROUND_BLUE);
200 printf("Exit \t\t\t\t");
201 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
202 printf("|");
203 printf("\n|\t\t\t\t\t\t\t\t|");
204 printf("\n|\t\t\t\t\t\t\t\t|");
205 printf("\n|\t\t\t\t\t\t\t\t|");
206 printf("\n|\t\t\t\t\t\t\t\t|");
207 printf("\n\xB2_________________________________"
208 "______________________________\xB2\n");
209
210 // Function call for select options
211 selectMenu();
212 }//end of function
213 /*---------------------------------------------------------------------------------------------------------------
--*/
214
215
216 /**
217 * Function to take user choices and perform the appropriate operation
218 */
219 /*---------------------------------------------------------------------------------------------------------------
--*/
220 void selectMenu()
221 {
222
223 int choice;
224 printf("\n Enter your choice : ");
225 scanf("%d", &choice); //scans the value entered and input it in the variable choice
226
227 switch/*Switch statement allows the variable choice to be test against a lsit of values*/ (choice) {
228 case 1: //if 1 is entered
229 Inventory(); //Calls the Inventory Function
230 break;
231
232 case 2: //if 2 is entered
233 pos(); //Calls the pos function, Point of Sale
234 break;
235
236 case 3: //if 3 is entered
237 sale(); //Calls the sale function
238 break;
239
- 58 - Computer Science I.A|Timothy Adams|Fatima College

240 case 4: // if 4 is entered


241 PnE(); //Calls the PnE Function, Profits and Expenses
242 break;
243
244 case 5: // if 5 is entered, exits program
245 printf("\n Exiting... \n\n");
246 printf("Exiting in 3 seconds...\n");
247 Sleep(3000);
248 exit(1);
249 break;
250
251
252 default: // if an unknown option is entered
253 system("cls");
254 printf("\ninvalid choice Try again \n");
255 Sleep(3000);
256 printMenu();//Calls the printMenu function
257 }
258 }//End of function
259 /*---------------------------------------------------------------------------------------------------------------
--*/
260
261
262
263 /**
264 * Function Inventory(), prints to the console a Graphical User Interface like menu,
265 * to list the selection of options specific to inventory of the company
266 */
267 /*---------------------------------------------------------------------------------------------------------------
--*/
268 void Inventory()
269 {
270 system("cls");
271 system("color 1F");
272 printf("\n");
273
274 // Create Menu
275 printf("\xB2 \xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"
276 "\xB2\xB2\xB2\xB2\xB2"
277 "\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
278
279 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
280 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE);
281 printf(" Inventory ");
282
283 SetConsoleTextAttribute(hConsole,
284 FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
285 printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"
286 "\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2"
287 "\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2 \xB2");
288 printf("\n ______________________________"
289 "_________________________________");
290 printf("\n|\t\t\t\t\t\t\t\t|");
291 printf("\n|\t\t\t\t\t\t\t\t|");
292 printf("\n|\t\t\t 1. View Inventory \t\t\t|");
293 printf("\n|\t\t\t 2. Edit Inventory\t\t\t|");
294 printf("\n|\t\t\t 3. Delete Stock \t\t\t|");
295 printf("\n|\t\t\t 4. Return to Menu\t\t\t|");
296 printf("\n|\t\t\t\t\t\t\t\t|");
297 printf("\n|\t\t\t\t\t\t\t\t|");
298 printf("\n|\t\t\t\t\t\t\t\t|");
299 printf("\n|\t\t\t\t\t\t\t\t|");
300 printf("\n\xB2_________________________________"
301 "______________________________\xB2\n");
302
303 check(); //Calls check function
304
305 }//End of function
306 /*---------------------------------------------------------------------------------------------------------------
--*/
307
308
309
310 /**
311 * Function check(),creates countofstocks.txt and writes a 0 to it so that a value can be read later on
312 */
313 /*---------------------------------------------------------------------------------------------------------------
--*/
314 void check()
315 {
316 FILE*check=fopen("countofstocks.txt","r");
317 if(check==NULL||check=="\0")
318 {
319 fclose(check);
320 FILE*intialise=fopen("countofstocks.txt","w");
321 int num=0;
322 fprintf(intialise,"%d",num);
323 fclose(intialise);
324 inventoryMenu(); //Calls the inventoryMenu function
325 }
326 else //else if the above condition isnt true its assumed there is a number in countofstocks.txt already
327 {
- 59 - Computer Science I.A|Timothy Adams|Fatima College

328 fclose(check);
329 inventoryMenu(); //Calls the inventoryMenu function
330 }
331 }//End of function
332 /*---------------------------------------------------------------------------------------------------------------
--*/
333
334
335
336
337 /**
338 * Function to take user choices and perform the appropriate operation
339 */
340 /*---------------------------------------------------------------------------------------------------------------
--*/
341 void inventoryMenu()
342 {
343
344 int choice; //intialise the integer choice
345 printf("\n Enter your choice : ");
346 scanf("%d",&choice);
347
348 switch/*Switch statement allows the variable choice to be test against a list of values*/ (choice) {
349 case 1://if 1 is entered
350 viewInventory();//Calls the viewInventory function
351 break;
352
353 case 2://if 2 is entered
354 editInventory();//Calls the editInventory function
355 break;
356
357 case 3://if 3 is entered
358 delInventory();//Calls the delInventory function
359 break;
360
361
362 case 4://if 4 is entered
363 //Returns to menu
364 printf("\n Returning... \n\n");
365 printf("Returning in 3 seconds...\n");
366 Sleep(3000);
367 system("cls");
368 printMenu(); //Calls the printMenu function
369
370
371 default:// if an unknown option is entered
372 system("cls");
373 printf("\nInvalid choice Try again \n");
374 system("pause");
375 Inventory();//Calls the Inventory Function
376 }
377 }//End of function
378 /*---------------------------------------------------------------------------------------------------------------
--*/
379
380
381
382 /**
383 * Function viewInventory() reads the listofstocks.txt file and takes that name and searches for a file with that
name
384 * and prints out the data in that file, it is then repeated for the number of stock in the the list.
385 */
386 /*---------------------------------------------------------------------------------------------------------------
--*/
387 void viewInventory()
388 {
389 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
390 FILE*count=fopen("countofstocks.txt","r");
391 int i,max;
392 char item[100];
393
394
395 fscanf(count,"%d",&max);
396 fclose(count);
397
398
399 FILE*in=fopen("listofallstocks.txt","r");
400 FILE*read;
401 system("cls");
402
403 if(in!=NULL)
404 {
405 for(i=0;i<max;i++)
406 {
407 fscanf(in,"%s",item_stock[i].item);
408 read=fopen(item_stock[i].item,"r");
409 printf("*");
410 SetConsoleTextAttribute(hConsole,FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
411 printf("\n");
412 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |FOREGROUND_BLUE|BACKGROUND_BLUE);
413 printf("%s",item_stock[i].item);
414 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
- 60 - Computer Science I.A|Timothy Adams|Fatima College

415 printf(" : ");


416 fscanf(read,"%d ",&item_stock[i].amount);
417 SetConsoleTextAttribute(hConsole,FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
418 printf("%d",item_stock[i].amount);
419 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
420 printf(" Units Available, ");
421 fscanf(read,"%f ",&item_stock[i].cp);
422 printf("Costs $");
423 SetConsoleTextAttribute(hConsole, FOREGROUND_RED|BACKGROUND_BLUE);
424 printf("%0.2f",item_stock[i].cp);
425 fscanf(read,"%f ",&item_stock[i].sp);
426 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
427 printf(" Dollars,");
428 printf(" and is sold for ");
429 printf("$");
430 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE);
431 printf("%0.2f",item_stock[i].sp);
432 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
433 printf(" Dollars");
434 printf("\n*");
435 }
436 fclose(in);
437 printf("\nThese are currently all the stock in Inventory\n");
438 fclose(read);
439 system("\npause");
440 printf("\nReturning...");
441 Sleep(2000);
442 Inventory();
443 }
444 else
445 {
446 fclose(in);
447 fclose(count);
448 fclose(read);
449 printf("\nNo stock in the database, please add stocks using the Edit Inventory Option\n");
450 system("\npause");
451 printf("\nReturning...");
452 Sleep(2000);
453 Inventory();
454 }
455
456 if(max==0)
457 {
458 fclose(in);
459 fclose(count);
460 fclose(read);
461 printf("\nNo stock in the database, please add stocks using the Edit Inventory Option\n");
462 system("\npause");
463 printf("\nReturning...");
464 Sleep(2000);
465 Inventory();
466 }
467 }//End of function
468 /*---------------------------------------------------------------------------------------------------------------
--*/
469
470
471
472 /**
473 * Function editInventory() prints out the available stock by opening the list of stocks file taking the name of
the stock from listofstocks,
474 * searches for a file name with that name and then scans in the data from that file.
475 * countofstocks file which holds the total no. of stock gives the amount of time to repeat the function,
476 * and prints out the data in that file, it is then repeated for x amount of time given from the countofstocks,
then asks the user for an input and then passes it to the editInventory2()function
477 */
478 /*---------------------------------------------------------------------------------------------------------------
--*/
479 void editInventory()
480 {
481 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
482
483 const int limit=5;
484 char *randstring(size_t); //intializing randomstring function
485 char hold[100],*random;
486
487 time_t t;
488 srand((unsigned)time(&t)); //calling time for the random function
489
490 int max,i;
491 FILE*count=fopen("countofstocks.txt","r");
492 fscanf(count,"%d",&max);
493 fclose(count);
494 FILE*in=fopen("listofallstocks.txt","r");
495 FILE*read;
496
497 printf("\nAll the stock found in the database are below\n");
498 for(i=0;i<max;i++)
499 {
500 fscanf(in,"%s",item_stock[i].item);
- 61 - Computer Science I.A|Timothy Adams|Fatima College

501 read=fopen(item_stock[i].item,"r");
502 printf("*");
503 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
504 printf("\n");
505 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE|BACKGROUND_BLUE);
506 printf("%s",item_stock[i].item);
507 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
508 printf(" : ");
509 fscanf(read,"%d ",&item_stock[i].amount);
510 SetConsoleTextAttribute(hConsole,FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
511 printf("%d",item_stock[i].amount);
512 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
513 printf(" Units Available, ");
514 fscanf(read,"%f ",&item_stock[i].cp);
515 printf("Costs $");
516 SetConsoleTextAttribute(hConsole, FOREGROUND_RED|BACKGROUND_BLUE);
517 printf("%0.2f",item_stock[i].cp);
518 fscanf(read,"%f ",&item_stock[i].sp);
519 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
520 printf(" Dollars,");
521 printf(" and is sold for ");
522 printf("$");
523 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE);
524 printf("%0.2f",item_stock[i].sp);
525 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
526 printf(" Dollars");
527 printf("\n*");
528 }
529
530 random=randstring(limit);//calling ranstring to create a random string, and intializing random with it.
531 printf(" Enter the stock to edit(The Stock Must exist in the above list) \n");
532 printf(" Or enter");
533 SetConsoleTextAttribute(hConsole, FOREGROUND_RED|FOREGROUND_GREEN|BACKGROUND_BLUE);
534 printf(" %s ",random);
535 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
536 printf("to add a new stock \n");
537 printf(" \n Enter stock name, an Invalid choice will cause the program to close : ");
538 scanf("%s",hold);
539 editInventory2(hold,random); //Passes the two variables to the editInventory2 function
540 }//End of function
541 /*---------------------------------------------------------------------------------------------------------------
--*/
542
543
544
545 /**
546 * Function editInventory2() compares a(hold) against b(random) to see if true and then performs the appropriate
action
547 */
548 /*---------------------------------------------------------------------------------------------------------------
--*/
549 void editInventory2(a/*hold*/,b/*random*/)
550 {
551 if(strcmp(a,b)==0)//if the text entered is equal to the random string
552 {
553 iftrueinv(); //calls the iftrueinv function
554 }
555 else
556 if(strcmp(a,b)!=0)//if the text entered is not equal to the random string
557 {
558 iffalseinv(a); //calls the iffalseinv function and passes through a(hold)
559 }
560 }//End of function
561 /*---------------------------------------------------------------------------------------------------------------
--*/
562
563
564
565 /**
566 * If a(hold),b(random) are the same string the program will then create a new file using the datastruct member
item
567 * and prints out user entered variables into the file such as amount,costprice,selling price, increments the
count of stocks by 1
568 * and calls Inventory()
569 */
570 /*---------------------------------------------------------------------------------------------------------------
--*/
571 void iftrueinv()
572 {
573 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
574 int current,store;
575 system("cls");
576 FILE*data;
577 FILE*count=fopen("countofstocks.txt","r");
578 fscanf(count,"%d\n",&store);
579 fclose(count);
580
- 62 - Computer Science I.A|Timothy Adams|Fatima College

581 current=store+1;
582
583 FILE*countout=fopen("countofstocks.txt","w");
584 fprintf(countout,"%d\n",current);
585 fclose(countout);
586
587
588 printf("\nEnter the name of the new stock");
589 printf("(no spaces) : ");
590 fflush(stdin);
591 fgets(item_stock[store].item,100,stdin);
592 char letter,checkspace[100];
593 strcpy(checkspace,item_stock[store].item);
594 checkspace[strcspn(checkspace,"\n")]='\0';
595 printf("\nChecking to see if '%s' has any spaces",checkspace);
596 system("pause");
597 letter=checkspace[0];
598 printf("\nStarting at the letter %c",letter);
599 int block=0,spaces=0;
600 do
601 {
602 letter=checkspace[block];
603 if(isspace(letter))
604 {
605 spaces++;
606 printf("\n Space found, checking again");
607 printf("\n%d space found so far",spaces);
608 }
609 block++;
610 }
611 while(letter!='\0');
612 if(spaces>=1)
613 {
614 printf("\nspace detected,use '_' instead");
615 do
616 {
617 printf("\nThe name of the item has a space(x%d)",spaces);
618 printf("\nTry again...");
619 printf("Enter the name of the new stock (no spaces): ");
620 fflush(stdin);
621 fgets(item_stock[store].item,100,stdin);
622 memset(checkspace, 0, 100);
623 strcpy(checkspace,item_stock[store].item);
624 checkspace[strcspn(checkspace,"\n")]='\0';
625 printf("\nChecking to see if '%s' has any spaces",checkspace);
626 letter=checkspace[0];
627 block=0; spaces=0;
628 while(letter!='\0')
629 {
630 letter=checkspace[block];
631 if(isspace(letter))
632 {
633 spaces++;
634 printf("\n Space found, checking again");
635 printf("\n%d space found so far",spaces);
636 }
637 block++;
638 }
639 }
640 while(spaces!=0);
641 }
642 printf("\nno spaces found");
643 item_stock[store].item[strcspn(item_stock[store].item,"\n")]='\0';
644
645 printf("\nThe Stock %s was successfully created\n",item_stock[store].item);
646 printf("The original number of stocks %d is now %d.\n",store,current);
647 fflush(stdin);
648
649 printf("Enter the available amount for stock %s : ",item_stock[store].item);
650 scanf("%d",&item_stock[store].amount);
651
652 printf("\nEnter the cost price for stock %s : ",item_stock[store].item);
653 scanf("%f",&item_stock[store].cp);
654 SetConsoleTextAttribute(hConsole,FOREGROUND_GREEN|BACKGROUND_BLUE);
655 printf("\n$%0.2f ",item_stock[store].cp);
656
SetConsoleTextAttribute(hConsole,FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
657 printf("dollars paid for one unit of %s\n",item_stock[store].item);
658 printf("\nEnter the selling price for stock %s : ",item_stock[store].item);
659 scanf("%f",&item_stock[store].sp);
660 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE);
661 printf("\n$%0.2f ",item_stock[store].sp);
662
SetConsoleTextAttribute(hConsole,FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
663 printf("dollars is the selling price for one unit of %s\n",item_stock[store].item);
664
665 data=fopen(item_stock[store].item,"w");
666 fprintf(data,"%d ",item_stock[store].amount);
667 fprintf(data,"%0.2f ",item_stock[store].cp);
668 fprintf(data,"%0.2f ",item_stock[store].sp);
669 fclose(data);
670
- 63 - Computer Science I.A|Timothy Adams|Fatima College

671 FILE*list=fopen("listofallstocks.txt","a");
672 fprintf(list,"\n%s",item_stock[store].item);
673 fclose(list);
674
675
676 printf("\nData written successfully.");
677 Sleep(3000);
678 printf("\n Returning to menu....");
679 Inventory();
680 }//End of file
681 /*---------------------------------------------------------------------------------------------------------------
--*/
682
683
684
685 /**
686 * If a(hold),b(random) are not the same string, the program will then search for a(hold) in the listofstocks
file and if found
687 * it searches for a file with the name of a(hold) and scans it in and prints it out, and allows the user to
overwrite the values of the
688 * members of the data struct eg amount,cp,sp and prints it back out into the file. and then calls Inventory()
689 */
690 /*---------------------------------------------------------------------------------------------------------------
--*/
691 void iffalseinv(a)
692 {
693 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
694 FILE*count=fopen("countofstocks.txt","r");
695 FILE*in=fopen("listofallstocks.txt","r");
696 FILE*read;
697 int i,i2,max;
698
699 fscanf(count,"%d",&max);
700
701
702 for(i=0;i<=max;i++)
703 {
704 fscanf(in,"%s",item_stock[i].item);
705 FILE*read=fopen(item_stock[i].item,"r");
706 fscanf(read,"%d ",&item_stock[i].amount);
707 fscanf(read,"%f ",&item_stock[i].cp);
708 fscanf(read,"%f ",&item_stock[i].sp);
709 if(strcmp(a,item_stock[i].item)==0)
710 {
711 FILE*data;
712 system("cls");
713 printf("\nThe stock");
714 SetConsoleTextAttribute(hConsole, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
715 printf(" %s ",item_stock[i].item);
716 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
717 printf("has");
718 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
719 printf(" %d ",item_stock[i].amount);
720 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
721 printf("units, costs");
722 SetConsoleTextAttribute(hConsole, FOREGROUND_RED|BACKGROUND_BLUE);
723 printf(" %0.2f ",item_stock[i].cp);
724 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
725 printf("dollars and is resold for");
726 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE);
727 printf(" %0.2f ",item_stock[i].sp);
728 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
729 printf("dollars");
730 printf("\n If some values remain the same please re-enter the original value");
731
732 printf("\nEnter the new amount of the stock %s : ",item_stock[i].item);
733 scanf("%d",&item_stock[i].amount);
734 printf("\n Enter the new cost price : ");
735 scanf("%f",&item_stock[i].cp);
736 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE);
737 printf("\n$%0.2f ",item_stock[i].cp);
738 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
739 printf("dollars paid for one unit of %s\n",item_stock[i].item);
740
741 printf("\n Enter the new selling price : ");
742 scanf("%f",&item_stock[i].sp);
743 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE);
744 printf("\n$%0.2f ",item_stock[i].sp);
745 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
746 printf("dollars is the selling price for one unit of %s\n",item_stock[i].item);
747 printf("Editing Data for %s ",item_stock[i].item);
748
749
750
751
752 FILE*edit=fopen(item_stock[i].item,"w");
753 fprintf(edit,"%d ",item_stock[i].amount);
- 64 - Computer Science I.A|Timothy Adams|Fatima College

754 fprintf(edit,"%0.2f ",item_stock[i].cp);


755 fprintf(edit,"%0.2f ",item_stock[i].sp);
756 fclose(edit);
757
758 printf("\n Data edited and saved");
759 printf("\nReturning to menu\n");
760 system("pause");
761 Inventory();
762
763
764 i2=60;
765 }
766 }
767
768 if(i2!=60);
769 {
770 fclose(read);
771 fclose(count);
772 fclose(in);
773 system("cls");
774 system("color 1C");
775 printf("Cannot open FILE \n");
776 Sleep(1000);
777 system("pause");
778 system("cls");
779 system("color 1F");
780 Inventory();
781 }
782 fclose(read);
783 fclose(count);
784 }//End of function
785 /*---------------------------------------------------------------------------------------------------------------
--*/
786
787
788
789 /**
790 * Prints out all the stock, in the inventory and then asks the user which one they would want to delete.
791 * program then takes this and passes it to the del(stock) function
792 */
793 /*---------------------------------------------------------------------------------------------------------------
--*/
794 void delInventory()
795 {
796 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
797 system("cls");
798
799 int max,i;
800 FILE*count=fopen("countofstocks.txt","r");
801 fscanf(count,"%d",&max);
802 fclose(count);
803 FILE*in=fopen("listofallstocks.txt","r");
804 FILE*read;
805
806 if(in!=NULL)
807 {
808 for(i=0;i<max;i++)
809 {
810 fscanf(in,"%s",item_stock[i].item);
811 read=fopen(item_stock[i].item,"r");
812 printf("*");
813 SetConsoleTextAttribute(hConsole,FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
814 printf("\n");
815 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |FOREGROUND_BLUE|BACKGROUND_BLUE);
816 printf("%s",item_stock[i].item);
817 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
818 printf(" : ");
819 fscanf(read,"%d ",&item_stock[i].amount);
820 SetConsoleTextAttribute(hConsole,FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
821 printf("%d",item_stock[i].amount);
822 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
823 printf(" Units Available, ");
824 fscanf(read,"%f ",&item_stock[i].cp);
825 printf("Costs $");
826 SetConsoleTextAttribute(hConsole, FOREGROUND_RED|BACKGROUND_BLUE);
827 printf("%0.2f",item_stock[i].cp);
828 fscanf(read,"%f ",&item_stock[i].sp);
829 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
830 printf(" Dollars,");
831 printf(" and is sold for ");
832 printf("$");
833 SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN|BACKGROUND_BLUE);
834 printf("%0.2f",item_stock[i].sp);
835 SetConsoleTextAttribute(hConsole,FOREGROUND_RED | FOREGROUND_GREEN |
FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
836 printf(" Dollars");
837 printf("\n*");
838 }
839 fclose(in);
840 printf("\nThese are currently all the stock in Inventory\n");
- 65 - Computer Science I.A|Timothy Adams|Fatima College

841 fclose(read);
842 }
843 char stock[200];
844
845 printf("Please enter the stock to delete : ");
846 scanf("%s",stock);
847 printf("%s entered, searching for file.",stock);
848 del(stock);
849 }//End of function
850 /*---------------------------------------------------------------------------------------------------------------
--*/
851
852 /**
853 * Asks user to confirm and then deletes the file, else prints and error according to errorno's status.
854 */
855 /*---------------------------------------------------------------------------------------------------------------
--*/
856 void del(stock)
857 {
858 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
859 const int limit=5;
860 char *randstring(size_t);
861 char hold[100],*random;
862
863 time_t t;
864 srand((unsigned)time(&t));
865 random=randstring(limit);
866 printf("\nTo confirm that you are sure about deleting the file, please type");
867 SetConsoleTextAttribute(hConsole, FOREGROUND_RED|FOREGROUND_GREEN|BACKGROUND_BLUE);
868 printf(" %s ",random);
869 SetConsoleTextAttribute(hConsole,
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
870 printf("\nOr enter x to exit : ");
871 scanf("%s",hold);
872 if(strcmp(hold,random)==0)
873 {
874 if(remove(stock)==0)
875 {
876 printf("\nFile Successfully Deleted\n");
877 system("pause");
878 updatelist(stock);
879 }
880 else
881 {
882 printf("\nFile was not deleted.\n");
883 if(errno==1)
884 {
885 printf("\nOperation not permitted\n");
886 }
887 else
888 if(errno==2)
889 {
890 printf("\nNo such file or directory\n");
891 }
892 else
893 if(errno==3)
894 {
895 printf("\nNo such process\n");
896 }
897 else
898 if(errno==4)
899 {
900 printf("\nInterrupted system call\n");
901 }
902 else
903 if(errno==5)
904 {
905 printf("\nI/O error\n");
906 }
907 else
908 if(errno==6)
909 {
910 printf("\nNo such device or address\n");
911 }
912 else
913 if(errno==7)
914 {
915 printf("\nArgument list too long\n");
916 }
917 else
918 if(errno==8)
919 {
920 printf("\nExec format error\n");
921 }
922 else
923 if(errno==9)
924 {
925 printf("\nBad file number\n");
926 }
927 else
928 if(errno==10)
929 {
- 66 - Computer Science I.A|Timothy Adams|Fatima College

930 printf("\nNo child processes\n");


931 }
932 else
933 if(errno==11)
934 {
935 printf("\nTry again\n");
936 }
937 else
938 if(errno==12)
939 {
940 printf("\nOut of memory\n");
941 }
942 else
943 if(errno==13)
944 {
945 printf("\nPermission denied, Try running the exe of this build as administrator\n");
946 }
947 system("pause");
948 printMenu();
949 }
950 }
951 else
952 {
953 printf("\nOperation Cancelled");
954 printf("\nExiting to menu\n");
955 system("pause");
956 Inventory();
957 }
958 }//End of function
959 /*---------------------------------------------------------------------------------------------------------------
--*/
960
961
962
963 /**
964 * Remove all occurences of the filename from the list of stocks, and decreases the count of stocks by 1.
965 */
966 /*---------------------------------------------------------------------------------------------------------------
--*/
967 void updatelist(a)
968 {
969 FILE*fPtr;
970 FILE*fTemp;
971 char path[21];
972
973 char toRemove[100];
974 char buffer[1000];
975
976 strcpy(path,"listofallstocks.txt");
977 strcpy(toRemove,a);
978 printf("\nReading the stock list '%s' and looking for the stock %s",path,toRemove);
979
980
981
982
983
984 /* Open files */
985 fPtr = fopen(path, "r");
986 fTemp = fopen("delete.tmp", "w");
987
988 /* fopen() return NULL if unable to open file in given mode. */
989 if (fPtr == NULL || fTemp == NULL)
990 {
991 /* Unable to open file hence exit */
992 printf("\nUnable to open stock file.\n");
993 printf("Please check whether file exists and you have read/write privilege.\n");
994 exit(EXIT_SUCCESS);
995 }
996
997
998 /*
999 * Read line from source file and write to destination
1000 * file after removing given word.
1001 */
1002 while ((fgets(buffer, BUFFER_SIZE, fPtr)) != NULL)
1003 {
1004 // Remove all occurrence of word from current line
1005 removeAll(buffer,toRemove);
1006
1007 // Write to temp file
1008 fputs(buffer, fTemp);
1009 }
1010
1011
1012 /* Close all files to release resource */
1013 fclose(fPtr);
1014 fclose(fTemp);
1015
1016
1017 /* Delete original source file */
1018 remove(path);
1019
- 67 - Computer Science I.A|Timothy Adams|Fatima College

1020 /* Rename temp file as original file */


1021 rename("delete.tmp", path);
1022
1023
1024 printf("\nAll occurrence of '%s' removed successfully.", toRemove);
1025 FILE*count=fopen("countofstocks.txt","r");
1026 int max;
1027 fscanf(count,"%d",&max);
1028 fclose(count);
1029 FILE*countout=fopen("countofstocks.txt","w");
1030 int current;
1031 current=max-1;
1032 printf("\nThe original number of stock %d, is now %d\n",max,current);
1033 fprintf(countout,"%d",current);
1034 fclose(countout);
1035 system("pause");
1036 printMenu();
1037 }//End of function
1038 /*---------------------------------------------------------------------------------------------------------------
--*/
1039
1040
1041 /**
1042 * Function to Remove all occurrences of a given word in string.
1043 */
1044 /*---------------------------------------------------------------------------------------------------------------
--*/
1045 void removeAll(char * str, const char * toRemove)
1046 {
1047 int i, j, stringLen, toRemoveLen;
1048 int found;
1049
1050 stringLen= strlen(str); // Length of string
1051 toRemoveLen=strlen(toRemove); // Length of word to remove
1052
1053
1054 for(i=0; i <= stringLen - toRemoveLen; i++)
1055 {
1056 /* Match word with string */
1057 found = 1;
1058 for(j=0; j < toRemoveLen; j++)
1059 {
1060 if(str[i + j] != toRemove[j])
1061 {
1062 found = 0;
1063 break;
1064 }
1065 }
1066
1067 /* If it is not a word */
1068 if(str[i + j] != ' ' && str[i + j] != '\t' && str[i + j] != '\n' && str[i + j] != '\0')
1069 {
1070 found = 0;
1071 }
1072
1073 /*
1074 * If word is found then shift all characters to left
1075 * and decrement the string length
1076 */
1077 if(found == 1)
1078 {
1079 for(j=i; j <= stringLen - toRemoveLen; j++)
1080 {
1081 str[j] = str[j + toRemoveLen];
1082 }
1083
1084 stringLen = stringLen - toRemoveLen;
1085
1086 //match next occurrence of word from current index.
1087 i--;
1088 }
1089 }
1090 }
1091 /*---------------------------------------------------------------------------------------------------------------
--*/
1092
1093
1094 /**
1095 * Function to Randomize a string of characters.
1096 */
1097 /*---------------------------------------------------------------------------------------------------------------
--*/
1098 char *randstring(size_t length) {
1099
1100 static char charset[] = "abcdefghijklmnopqrstuvwxyz0123456789";
1101 char *randomString = NULL;
1102
1103 if (length)
1104 {
1105 randomString=malloc(sizeof(char)*(length +1));
1106
1107
- 68 - Computer Science I.A|Timothy Adams|Fatima College

1108 if (randomString)
1109 {
1110 for (int n = 0;n<length;n++)
1111 {
1112 int key = rand()%(36-1);
1113 randomString[n] = charset[key];
1114 }
1115 }
1116 }
1117
1118 return (char *)randomString;
1119 }//End of function
1120 /*---------------------------------------------------------------------------------------------------------------
--*/
1121
1122
1123
1124 /**
1125 * Point of sale function of the program acts like a cash register, asks user to enter the item, and the amount
being purchased
1126 * returns the total price and then asks for the amount the customer has given and returns the amount of change
to give if the amount paid
1127 * is more than the price,then saves this and the time of transaction to the transaction file to be read in
another function.
1128 */
1129 /*---------------------------------------------------------------------------------------------------------------
--*/
1130 void pos()
1131 {
1132 startfiles();
1133 printf("------------------------------------------------------------");
1134 FILE*count=fopen("countofstocks.txt","r");
1135 int i,id,max,limit,total,amount;
1136 float n,change;
1137 char item[100],tempvalue[100];
1138
1139
1140 fscanf(count,"%d",&max);
1141
1142 FILE*in=fopen("listofallstocks.txt","r");
1143 FILE*read;
1144 FILE*current=fopen("ongoingtransaction.txt","w");
1145 fprintf(current,"\0");
1146
1147 system("cls");
1148
1149 if(in!=NULL)
1150 {
1151 printf("all the available stock are below");
1152 for(i=0;i<max;i++)
1153 {
1154 fscanf(in,"%s",item_stock[i].item);
1155 read=fopen(item_stock[i].item,"r");
1156 printf(" ");
1157 printf("\n%s: ",item_stock[i].item);
1158 fscanf(read,"%d ",&item_stock[i].amount);
1159 printf("Units:%d ",item_stock[i].amount);
1160 fscanf(read,"%f ",&item_stock[i].cp);
1161 printf("Cost: $%0.2f ",item_stock[i].cp);
1162 fscanf(read,"%f ",&item_stock[i].sp);
1163 printf("Selling Price: $%0.2f \t",item_stock[i].sp);
1164 printf("\n");
1165 }
1166 int flag;
1167 do
1168 {
1169 printf("\nPlease enter how much times to repeat the purchase function, for each stock being purchased\nor -9
to exit : ");
1170 char term;
1171 if(scanf("%d%c", &limit, &term) != 2 || term != '\n')
1172 {
1173 printf("\nInvalid Data type, Try again\n");
1174 system("pause");
1175 system("cls");
1176 fflush(stdin);
1177 flag=1;}
1178 else
1179 {
1180 flag=0;
1181 printf("\nValid integer entered\n");
1182 }
1183 }while(flag!=0);
1184
1185 if(limit==-9)
1186 {
1187 printf("\nExiting to Menu");
1188 printf("\nprocess cancelled\n");
1189 system("pause");
1190 Inventory();
1191 }
1192 else
1193 if(limit==1)
1194 {
- 69 - Computer Science I.A|Timothy Adams|Fatima College

1195 printf("\nOne entered...");


1196 printf("\nThis process will only happen once\n");
1197 system("pause");
1198 }
1199 else
1200 if(limit<=0)
1201 {
1202
1203 do
1204 {
1205 printf("\nInvalid number, please enter a valid number starting from 1");
1206 printf("\nPlease enter how much times to repeat the purchase function, for each stock being purchased
: ");
1207 scanf("%d",&limit);
1208 }
1209 while(limit<1);
1210 }
1211 else
1212 if(limit>1)
1213 {
1214 printf("This process will be repeated %d times\n",limit);
1215 system("pause");
1216 }
1217
1218
1219 for(int i2=1;i2<=limit;i2++)
1220 {
1221 system("cls");
1222 printf("all the available stock are below");
1223 for(int i4=0;i4<max;i4++)
1224 {
1225 fscanf(in,"%s",item_stock[i4].item);
1226 read=fopen(item_stock[i4].item,"r");
1227 printf(" ");
1228 printf("\n%s: ",item_stock[i4].item);
1229 fscanf(read,"%d ",&item_stock[i4].amount);
1230 printf("Units:%d ",item_stock[i4].amount);
1231 fscanf(read,"%f ",&item_stock[i4].cp);
1232 printf("Cost: $%0.2f ",item_stock[i4].cp);
1233 fscanf(read,"%f ",&item_stock[i4].sp);
1234 printf("Selling Price: $%0.2f \t",item_stock[i4].sp);
1235 printf("\n");
1236 }
1237
1238 int ch;
1239 printf("Enter the item : ");
1240 scanf("%s",item);
1241 for(i=0;i<max;i++)
1242 {
1243 if(strcmp(item,item_stock[i].item)==0)
1244 {
1245 printf("\nItem found!");
1246 if(item_stock[i].amount<=0)
1247 {
1248 printf("Sorry There is no available amount in this stock.");
1249 system("pause");
1250 printMenu();
1251 }
1252 printf("\nEnter the quantity being purchased : ");
1253 scanf("%d",&amount);
1254 id=i;
1255 if(amount>item_stock[i].amount)
1256 {
1257 do
1258 {
1259 printf("This amount is more than the available amount");
1260 printf(" Enter a valid amount : ");
1261 scanf("%d",&amount);
1262 } while(amount>item_stock[i].amount);
1263 }
1264 printf("\nTotal for %s is : %d units X %0.2f dollars",item_stock[i].item,amount,item_stock[i].sp);
1265 n=item_stock[i].sp*amount;
1266 printf("\nItem : %s | Quantity : %d | Price : $%0.2f each | Total : $%0.2f
dollars\n",item_stock[i].item,amount,item_stock[i].sp,n);
1267 fclose(current);
1268 FILE*current2=fopen("ongoingtransaction.txt","w");
1269 fprintf(current2,"\nItem : %s | Quantity : %d | Price : $%0.2f each | Total : $%0.2f
dollars",item_stock[i].item,amount,item_stock[i].sp,n);
1270 fclose(current2);
1271 system("pause");
1272 ch=60;
1273 }
1274 else
1275 if(ch!=60)
1276 {
1277 printf("Invalid Entry, Item does not exist\n");
1278 system("pause");
1279 printMenu();
1280 }
1281 }
1282
1283
- 70 - Computer Science I.A|Timothy Adams|Fatima College

1284 FILE*current2=fopen("ongoingtransaction.txt","a");
1285 fprintf(current2,"\n-----------------\n%0.2f",n);
1286 FILE*current3=fopen("ongoingtransaction.txt","r");
1287 char s;
1288 while((s=fgetc(current3))!=EOF) {
1289 printf("%c",s);
1290 }
1291 float payment;
1292 printf("\nEnter the amount of money the customer has given : ");
1293 scanf("%f",&payment);
1294 change=payment-n;
1295 if(change<0)
1296 {
1297 float remain;
1298 change=n-payment;
1299 printf("The customer is owing $%0.2f dollars\n",change);
1300 system("pause");
1301 printf("\nEnter the remaining amount the customer has given : ");
1302 scanf("%f",&remain);
1303 change=remain-change;
1304 }
1305 int LEN=150;
1306 char buf[LEN];
1307 time_t curtime;
1308 struct tm *loc_time;
1309
1310 //Getting current time of system
1311 curtime = time (NULL);
1312
1313 // Converting current time to local time
1314 loc_time = localtime (&curtime);
1315
1316
1317 FILE*lastprocess=fopen("lasttransaction.txt","w");
1318
1319 if(change>0)
1320 {
1321 FILE*sales=fopen("totalsales.txt","a");
1322
1323 printf("Please give the customer $%0.2f dollars change",change);
1324 printf("\nTransaction Saved");
1325 fprintf(sales,"\nItem : %s | Quantity : %d | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f |
Change : $%0.2f ",item_stock[id].item,amount,item_stock[id].sp,n,payment,change);
1326 fprintf(sales,"\nProcessed at : %s\n----------------------------------", asctime (loc_time));
1327 fprintf(lastprocess,"\n%s\n", asctime (loc_time));
1328 fclose(lastprocess);
1329 fclose(sales);
1330 printf("\nItem : %s | Quantity : %d | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f | Change
: $%0.2f ",item_stock[id].item,amount,item_stock[id].sp,n,payment,change);
1331 printf("\nProcessed at : %s", asctime (loc_time));
1332 FILE*expensesr=fopen("expenses.txt","r");
1333 float expenses;
1334 FILE*profitsr=fopen("profits.txt","r");
1335 float profits;
1336 FILE*totalr=fopen("payments.txt","r");
1337 float paymenttotal;
1338 fscanf(totalr,"%f",&paymenttotal);
1339 fscanf(expensesr,"%f",&expenses);
1340 fscanf(profitsr,"%f",&profits);
1341 fclose(expensesr);
1342 fclose(profitsr);
1343 fclose(totalr);
1344 paymenttotal=paymenttotal+n;
1345 expenses=expenses+(item_stock[id].cp*amount);
1346 profits=profits+(n-expenses);
1347 FILE*expensesw=fopen("expenses.txt","w");
1348 fprintf(expensesw,"%0.2f",expenses);
1349 FILE*profitsw=fopen("profits.txt","w");
1350 fprintf(profitsw,"%0.2f",profits);
1351 FILE*totalw=fopen("payments.txt","w");
1352 fprintf(totalw,"%0.2f",paymenttotal);
1353 fclose(expensesw);
1354 fclose(profitsw);
1355 fclose(totalw);
1356 system("pause");
1357 system("cls");
1358 item_stock[id].amount=item_stock[id].amount-amount;
1359 printf("%d units of %s left\n",item_stock[id].amount,item_stock[id].item);
1360 FILE*data=fopen(item_stock[id].item,"w");
1361 fprintf(data,"%d ",item_stock[id].amount);
1362 fprintf(data,"%0.2f ",item_stock[id].cp);
1363 fprintf(data,"%0.2f ",item_stock[id].sp);
1364 fclose(data);
1365 system("pause");
1366 }
1367
1368 if(change==0)
1369 {
1370 FILE*sales=fopen("totalsales.txt","a");
1371
1372 printf("\nTransaction Saved");
1373 fprintf(sales,"\nItem : %s | Quantity : %d | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f |
- 71 - Computer Science I.A|Timothy Adams|Fatima College

Change : $%0.2f ",item_stock[id].item,amount,item_stock[id].sp,n,payment,change);


1374 fprintf(sales,"\nProcessed at : %s\n----------------------------------", asctime (loc_time));
1375 fprintf(lastprocess,"\n%s\n", asctime (loc_time));
1376 fclose(sales);
1377 fclose(lastprocess);
1378 printf("\nItem : %s | Quantity : %d | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f | Change
: $%0.2f ",item_stock[id].item,amount,item_stock[id].sp,n,payment,change);
1379 printf("\nProcessed at : %s", asctime (loc_time));
1380 system("pause");
1381 system("cls");
1382 FILE*expensesr=fopen("expenses.txt","r");
1383 float expenses;
1384 FILE*profitsr=fopen("profits.txt","r");
1385 float profits;
1386 FILE*totalr=fopen("payments.txt","r");
1387 float paymenttotal;
1388 fscanf(totalr,"%f",&paymenttotal);
1389 fscanf(expensesr,"%f",&expenses);
1390 fscanf(profitsr,"%f",&profits);
1391 fclose(expensesr);
1392 fclose(profitsr);
1393 fclose(totalr);
1394 paymenttotal=paymenttotal+n;
1395 expenses=expenses+(item_stock[id].cp*amount);
1396 profits=profits+(n-expenses);
1397 FILE*expensesw=fopen("expenses.txt","w");
1398 fprintf(expensesw,"%0.2f",expenses);
1399 FILE*profitsw=fopen("profits.txt","w");
1400 fprintf(profitsw,"%0.2f",profits);
1401 FILE*totalw=fopen("payments.txt","w");
1402 fprintf(totalw,"%0.2f",paymenttotal);
1403 fclose(expensesw);
1404 fclose(profitsw);
1405 fclose(totalw);
1406 system("pause");
1407 system("cls");
1408 item_stock[id].amount=item_stock[id].amount-amount;
1409
1410 printf("%d units of %s left\n",item_stock[id].amount,item_stock[id].item);
1411 FILE*data=fopen(item_stock[id].item,"w");
1412 fprintf(data,"%d ",item_stock[id].amount);
1413 fprintf(data,"%0.2f ",item_stock[id].cp);
1414 fprintf(data,"%0.2f ",item_stock[id].sp);
1415 fclose(data);
1416 system("pause");
1417 }
1418 }
1419 sale();
1420
1421 }
1422 else
1423 {
1424 system("cls");
1425 printf("\nNo Stocks in database\n");
1426 system("pause");
1427 printMenu();
1428 }
1429 }//End of function
1430 /*---------------------------------------------------------------------------------------------------------------
--*/
1431
1432
1433
1434 /**
1435 * Function to ensure that all the files related to the pos() function that includes a number are initialised
with 0
1436 * to ensure a number is in it to be read
1437 */
1438 /*---------------------------------------------------------------------------------------------------------------
--*/
1439 void startfiles()
1440 {
1441 FILE*check=fopen("expenses.txt","r");
1442 if(check==NULL||check=="\0")
1443 {
1444 FILE*intialise=fopen("expenses.txt","w");
1445 int num=0;
1446 fprintf(intialise,"%d",num);
1447 fclose(check);
1448 fclose(intialise);
1449 }
1450
1451 FILE*check1=fopen("profits.txt","r");
1452 if(check1==NULL||check1=="\0")
1453 {
1454 FILE*intialise=fopen("profits.txt","w");
1455 int num=0;
1456 fprintf(intialise,"%d",num);
1457 fclose(check1);
1458 fclose(intialise);
1459 }
1460
- 72 - Computer Science I.A|Timothy Adams|Fatima College

1461 FILE*check2=fopen("payments.txt","r");
1462 if(check2==NULL||check2=="\0")
1463 {
1464 FILE*intialise=fopen("payments.txt","w");
1465 int num=0;
1466 fprintf(intialise,"%d",num);
1467 fclose(check2);
1468 fclose(intialise);
1469 }
1470 }//End of function
1471 /*---------------------------------------------------------------------------------------------------------------
--*/
1472
1473
1474
1475 /**
1476 * Function to print out the transaction file that shows all the transactins that occured.
1477 */
1478 /*---------------------------------------------------------------------------------------------------------------
--*/
1479 void sale()
1480 {
1481 FILE*lastprocess=fopen("lasttransaction.txt","r");
1482 FILE*current3=fopen("totalsales.txt","r");
1483 system("cls");
1484 if((lastprocess!=NULL)&&(current3!=NULL))
1485 {
1486 printf("\xB2\xB2\xB2\xB2Sales\xB2\xB2\xB2\xB2\n");
1487 printf("Last Transaction was at : \n");
1488 char s;
1489 while((s=fgetc(lastprocess))!=EOF) {
1490 printf("%c",s);
1491 }
1492 printf("\n----------------------------------\n");
1493
1494 while((s=fgetc(current3))!=EOF) {
1495 printf("%c",s);
1496 }
1497 system("pause");
1498 printMenu();
1499 }
1500 else
1501 {
1502 system("cls");
1503 printf("\nNo Stocks in database\n");
1504 system("pause");
1505 printMenu();
1506 }
1507 }//End of function
1508 /*--------------------------------------------------------------------------------------------------------------
---*/
1509
1510
1511
1512 /**
1513 * Function to print out the total income,expenses and prints out whether if it is a profit or a loss
1514 */
1515 /*---------------------------------------------------------------------------------------------------------------
--*/
1516 void PnE()
1517 {
1518 FILE*expenses=fopen("expenses.txt","r");
1519 FILE*lastprocess=fopen("lasttransaction.txt","r");
1520 FILE*total=fopen("payments.txt","r");
1521 FILE*profits=fopen("profits.txt","r");
1522 if((expenses!=NULL)&&(lastprocess!=NULL)&&(total!=NULL)&&(profits!=NULL))
1523 {
1524 system("cls");
1525 system("color 3F");
1526
1527 float expenses1;
1528 fscanf(expenses,"0.2f",expenses1);
1529 char s;
1530 printf("After the last transaction at : ");
1531
1532 while((s=fgetc(lastprocess))!=EOF) {
1533 printf("%c",s);
1534 }
1535 printf("\nThe business's expenses ran a total of : ");
1536 printf("$");
1537 while((s=fgetc(expenses))!=EOF) {
1538 printf("%c",s);
1539 }
1540 printf(" dollars");
1541
1542
1543
1544 printf("\nWith a total income of : ");
1545 printf("$");
1546 while((s=fgetc(total))!=EOF) {
1547 printf("%c",s);
1548 }
- 73 - Computer Science I.A|Timothy Adams|Fatima College

1549 printf(" dollars");


1550
1551
1552
1553
1554 float profits1;
1555 fscanf(profits,"0.2f",profits1);
1556 float total1;
1557 fscanf(total,"0.2f",total1);
1558
1559 if(expenses1>total1)
1560 {
1561 int expenses2;
1562 expenses2=(profits1-expenses1);
1563 printf("\nUnfortunately suffering a debt of %0.2f",expenses2);
1564 printf("\nDue to the profit income of");
1565 printf("$");
1566 while((s=fgetc(profits))!=EOF) {
1567 printf("%c",s);
1568 }
1569 printf(" dollars");
1570 system("pause");
1571 printMenu();
1572 }
1573 else
1574 {
1575 printf("\nMaking a profit income of : ");
1576 printf("$");
1577 while((s=fgetc(profits))!=EOF) {
1578 printf("%c",s);
1579 }
1580 printf(" dollars\n");
1581 }
1582 system("pause");
1583 printMenu();
1584 }
1585 else
1586 {
1587 system("cls");
1588 printf("\nNo Stocks in database\n");
1589 system("pause");
1590 printMenu();
1591 }
1592 }//End of function
1593 /*---------------------------------------------------------------------------------------------------------------
--*/
- 74 - Computer Science I.A|Timothy Adams|Fatima College

Testing Stage:

Presentation of program

Main
Password()
Prints the logo
PrintMenu()
and then calls Asks user for
SelectMenu()
correct Prints out a
password graphic Switch
showing all statement
the options that performs
[252558]
one of the
choices below

Switch
SelectMenu()
statement

Choices [1]Inventory() [2]pos() [3]sale() [4]PnE() [5]Exit

Prints Prints out Prints out


Process
Inventory time of last profits and Exits Program
Transaction
Menu sale expenses

Switch Records Prints out all Confirms debt


Statement Transaction sales or Profit

Above is a graphical presentation of what the program performs and in


what order and what criteria should be met in order for certain functions
to occur.
- 75 - Computer Science I.A|Timothy Adams|Fatima College

In order to test this program and ensure full reliability and that it is in an operable and working state. A few tests will be
ran and documented via a trace table and screenshots.

What this program should first do is create a logo boot up, and from a logo boot up ask for the password to access the
rest of the program if the correct password is correct it will then print a Menu screen and list all the options and allow the
user to choose their wanted option. Each option calls a function and each function will be tested and documented in the
Trace Table below.
- 76 - Computer Science I.A|Timothy Adams|Fatima College

Trace Table :

Trace tables are tables that consist of columns. Each column can represent a variable, a condition, or an output. Not every
variable, condition or output in an algorithm needs a column in a trace table. If every action in this program was recorded the
trace table alone would have taken up a lot of unnecessary tables, therefore only the functions that accept user inputs are record
in this trace table below… There will be three types of data inputs to test the functionality of each function. These three data types
are:

1. Normal data - Normal data is test data that is


typical (expected) and should be accepted by the
system.

2. Abnormal data - Abnormal data is test data that


is with in data limits, but is not accepted by the
system

3. Extreme data - Extreme data is test data that is


beyond the boundaries and is typically out of data
limits.
- 77 - Computer Science I.A|Timothy Adams|Fatima College

# Function Data Input Input Type Expectation Actual Result

Acceptable Correct Password


252558 Correct Password
(Figure 1.1) (Figure 1.1)
Incorrect
Abnormal Incorrect
2 Password Void 626747 Password
(Figure 1.2) Password
(Figure 1.2)
Incorrect
Extreme Incorrect
&$&%*$sugma Password
(Figure 1.3) Password
(Figure 1.3)
Acceptable Accepted
1 Accepted
(Figure 2.1) (Figure 2.1)
Abnormal Rejected, Go to Rejected
4 SelectMenu Void 10
(Figure 2.2) Default Option (Figure 2.2)
Extreme Rejected, Go to Rejected
66#%#!
(Figure 2.3) Default Option (Figure 2.3)
Acceptable Accepted
3 Accepted
(Figure 3.1) (Figure 3.1)
Abnormal Rejected, Go to Rejected
7 inventoryMenu Void 20
(Figure 3.2) Default Option (Figure 3.2)
Extreme Rejected, Go to Rejected
8558*$*U*5F
(Figure 3.3) Default Option (Figure 3.3)
Accepted,Matches
Acceptable Accepted
0ok8b the string on the
(Figure 4.1) (Figure 4.1)
display
9 editInventory Void Abnormal Rejected
Peas Rejected
(Figure 4.2) (Figure 4.2)
Extreme Rejected
36363636$& Rejected
(Figure 4.3) (Figure 4.3)
Acceptable Accepted
Black_Ink Accepted
(Figure 5.1) (Figure 5.1)
Abnormal Rejected
11 iftrueinv Void Black Ink Rejected
(Figure 5.2) (Figure 5.2)
Extreme Rejected
48438u 636 Rejected
(Figure 5.3) (Figure 5.3)
Accepted, The file
Acceptable Accepted
Color_Ink Color_Ink was
(Figure 6.1) (Figure 6.1)
found
Rejected, The file
12 iffalseinv Void Abnormal Rejected
Peas peas does not
(Figure 6.2) (Figure 6.2)
exist
Extreme Rejected
36363636$& Rejected
(Figure 6.3) (Figure 6.3)
Denied, No Admin
Acceptable
Color_Ink Accepted Priviledges
(Figure 7.1)
(Figure 7.1)
13 delInventory Void Abnormal Accepted
Corn Accepted
(Figure 7.2) (Figure 7.2)
Extreme Accepted
584%@$%FaaA Accepted
(Figure 7.3) (Figure 7.3)
Acceptable Accepted
2 Accepted
(Figure 8.1) (Figure 8.1)
Abnormal Rejected,Not a Rejected
18 pos Void Bread
(Figure 8.2) number (Figure 8.2)
Extreme Rejected
5864%//////A Rejected
(Figure 8.3) (Figure 8.3)
- 78 - Computer Science I.A|Timothy Adams|Fatima College

Figures:

Void Password()

Acceptable Data Input


- 79 - Computer Science I.A|Timothy Adams|Fatima College

Abnormal Data Input

Extreme Data Input


- 80 - Computer Science I.A|Timothy Adams|Fatima College

Void SelectMenu()

Acceptable Data Input

Abnormal Data Input


- 81 - Computer Science I.A|Timothy Adams|Fatima College

Extreme Data Input


- 82 - Computer Science I.A|Timothy Adams|Fatima College

Void InventoryMenu()

Acceptable Data Input

Abnormal Data Input


- 83 - Computer Science I.A|Timothy Adams|Fatima College

Extreme Data Input


- 84 - Computer Science I.A|Timothy Adams|Fatima College

Void EditInventory()

Acceptable Data Input

Abnormal Data Input


- 85 - Computer Science I.A|Timothy Adams|Fatima College

Extreme Data Input


- 86 - Computer Science I.A|Timothy Adams|Fatima College

Void Iftrueinv()

Acceptable Data Input

Abnormal Data Input


- 87 - Computer Science I.A|Timothy Adams|Fatima College

Extreme Data Input


- 88 - Computer Science I.A|Timothy Adams|Fatima College

Void Iffalseinv()

Acceptable Data Input

Abnormal Data Input


- 89 - Computer Science I.A|Timothy Adams|Fatima College

Extreme Data Input


- 90 - Computer Science I.A|Timothy Adams|Fatima College

Void delInventory()

Acceptable Data Input

Abnormal Data Input


- 91 - Computer Science I.A|Timothy Adams|Fatima College

Extreme Data Input


- 92 - Computer Science I.A|Timothy Adams|Fatima College

Void pos()

Acceptable Data Input

Abnormal Data Input


- 93 - Computer Science I.A|Timothy Adams|Fatima College

Extreme Data Input


- 94 - Computer Science I.A|Timothy Adams|Fatima College

Functions without user input


- 95 - Computer Science I.A|Timothy Adams|Fatima College
- 96 - Computer Science I.A|Timothy Adams|Fatima College

Files

EXE DIRECTORY.

The location where


the executable of the
program and the
files it creates are
located

totalsales.txt

Used in the function

Sales to display all


sale

profits.txt 200 is the value of the profits earned. Used in the function PnE

payments.txt 1600 is the value of the income earned by the business, used in the function PnE

Ongoingtransaction.txt used in the function pos, to display the ongoing transaction that is being processed

listofallstocks.txt

acts as a directory that tells the program what files to look for.

Also keeps a list of all the stocks in the stores inventory, Used in most functions.

lasttransaction.txt keeps record of the last sales transaction for record keeping. Used
in the function pos and sales

expenses.txt 1200 is the value of the expenses the business spent based on the sales of all stock.

countofstocks.txt keeps track of all the existing stocks in the inventory. Used in most functions

You might also like