Professional Documents
Culture Documents
Computer Science IA Timothy Adams
Computer Science IA Timothy Adams
Computer Science IA Timothy Adams
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
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
• Mimic a cash register, using the files as the items in the database
• Produce an audit that will inform the user of the profits,expenses and debts.
Non-Functional Requirements
• 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
• The security of the program is highly dependant on the security of the system it is ran on, meaning it can be prone to
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
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
1. Inventory
2. Point of Sales
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
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
void inventoryMenu() : The Function inventoryMenu(), uses a switch statement to perform the appropriate function
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
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
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
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
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
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>
struct stock
Begin
int amount
float cp
float sp
End item_stock
main
Begin
systemcolor 9F
Display rocket
int j = 300000
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
system clearscreen
delay 3000
exit1
- 12 - Computer Science I.A|Timothy Adams|Fatima College
End
else
Begin
Begin
systemcolor 1A
system clearscreen
u delay 900000
system clearscreen
systemcolor 1C
u delay 900000
system clearscreen
systemcolor 1A
systemPause
break
End
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
Display ______________________________
_________________________________
Display ||
Display ||
Display ||
Display ||
Display | 1.
Display Inventory
Display |
Display | 2. Point Of
Display Sale
Display |
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
input choice
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...
delay 3000
exit1
break
default:
system clearscreen
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 ||
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
fcloseintialise
inventoryMenu
End
else already
Begin
fclosecheck
inventoryMenu
End
End
inventoryMenu
Begin
int choice
input choice
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...
delay 3000
system clearscreen
printMenu
default:
system clearscreen
systempause
Inventory
End
End
- 19 - Computer Science I.A|Timothy Adams|Fatima College
viewInventory
Begin
File count=fopencountofstocks.txt r
int i max
fclosecount
File in=fopenlistofallstocks.txt r
File read
system clearscreen
Begin
fori=0i<maxi++
Begin
read=fopenitem_stock i .item r
Display *
Display
Display :
Display Costs $
- 20 - Computer Science I.A|Timothy Adams|Fatima College
Display Dollars
Display $
Display Dollars
Display *
End
fclosein
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
char *randstringsize_t
time_t t
srandunsignedtime t
int max i
File count=fopencountofstocks.txt r
fclosecount
File in=fopenlistofallstocks.txt r
- 22 - Computer Science I.A|Timothy Adams|Fatima College
File read
fori=0i<maxi++
Begin
read=fopenitem_stock i .item r
Display *
Display
Display :
Display Costs
Display Dollars
Display $
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 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
Begin
if falseinva
End
End
if trueinv
Begin
system clearscreen
File data
File count=fopencountofstocks.txt r
fclosecount
current=store+1
File countout=fopencountofstocks.txt w
fclosecountout
Display no spaces :
fflushstdin
systempause
letter=checkspace 0
do
Begin
letter=checkspace block
if isspaceletter
Begin
spaces++
End
- 25 - Computer Science I.A|Timothy Adams|Fatima College
block++
End
if spaces>=1
Begin
do
Begin
fflushstdin
memsetcheckspace 0 100
letter=checkspace 0
block=0 spaces=0
Begin
letter=checkspace block
if isspaceletter
Begin
spaces++
End
block++
End
End
End
fflushstdin
Display Enter the available amount for stock : item_stock store .item
Display Enter the cost price for stock : item_stock store .item
Display Enter the selling price for stock : item_stock store .item
Display dollars is the selling price for one unit of item_stock store .item
closedata
File list=fopenlistofallstocks.txt a
closelist
delay 3000
Inventory
End
if falseinv
Begin
File count=fopencountofstocks.txt r
File in=fopenlistofallstocks.txt r
File read
int i i2 max
fori=0i<=maxi++
Begin
Begin
File data
- 28 - Computer Science I.A|Timothy Adams|Fatima College
system clearscreen
Display has
Display dollars
Display If some values remain the same please re-enter the original value
Display dollars is the selling price for one unit of item_stock i .item
fcloseedit
- 29 - Computer Science I.A|Timothy Adams|Fatima College
systempause
Inventory
i2=60
End
End
if i2 not equal to 60
Begin
fcloseread
fclosecount
fclosein
system clearscreen
systemcolor 1C
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
fclosecount
File in=fopenlistofallstocks.txt r
File read
Begin
fori=0i<maxi++
Begin
read=fopenitem_stock i .item r
Display *
Display
Display :
SetConsoleTextAttributehConsole FOREGROUND_BLUE|BACKGROUND_BLUE
Display Costs $
- 31 - Computer Science I.A|Timothy Adams|Fatima College
Display Dollars
Display $
Display Dollars
Display *
End
fclosein
fcloseread
End
input stock
delstock
End
delstock
Begin
char *randstringsize_t
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
input hold
Begin
if removestock==0
Begin
systempause
updateliststock
End
else
Begin
if errno==1
Begin
End
else
if errno==2
Begin
End
- 33 - Computer Science I.A|Timothy Adams|Fatima College
else
if errno==3
Begin
End
else
if errno==4
Begin
End
else
if errno==5
Begin
End
else
if errno==6
Begin
End
else
if errno==7
Begin
End
else
- 34 - Computer Science I.A|Timothy Adams|Fatima College
if errno==8
Begin
End
else
if errno==9
Begin
End
else
if errno==10
Begin
End
else
if errno==11
Begin
End
else
if errno==12
Begin
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
systempause
Inventory
End
End
updatelista
Begin
File fPtr
File fTemp
char path 21
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
Begin
Display Please check whether file exists and you have read/write privilege.
exitEXIT_SUCCESS
End
Begin
removeAllbuffer toRemove
fputsbuffer fTemp
End
fclosefPtr
fclosefTemp
removepath
renamedelete.tmp path
File count=fopencountofstocks.txt r
int max
fclosecount
File countout=fopencountofstocks.txt w
int current
current=max-1
fclosecountout
systempause
printMenu
End
Begin
int found
stringLen= strlenstr
toRemoveLen=strlentoRemove
Begin
found = 1
Begin
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
Begin
End
i--
End
End
End
if length
Begin
randomString=mallocsizeofchar*length +1
if randomString
Begin
Begin
End
End
- 39 - Computer Science I.A|Timothy Adams|Fatima College
End
pos
Begin
startfiles
Display ------------------------------------------------------------
File count=fopencountofstocks.txt r
float n change
File in=fopenlistofallstocks.txt r
File read
File current=fopenongoingtransaction.txt w
fDisplay current \0
system clearscreen
Begin
fori=0i<maxi++
Begin
read=fopenitem_stock i .item r
Display
- 40 - Computer Science I.A|Timothy Adams|Fatima College
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
Begin
systempause
system clearscreen
fflushstdin
flag=1End
else
Begin
flag=0
End
- 41 - Computer Science I.A|Timothy Adams|Fatima College
if limit==-9
Begin
systempause
Inventory
End
else
if limit==1
Begin
systempause
End
else
if limit<=0
Begin
do
Begin
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
systempause
End
forint i2=1i2<=limiti2++
Begin
system clearscreen
forint i4=0i4<maxi4++
Begin
read=fopenitem_stock i4 .item r
Display
Display
End
int ch
input item
fori=0i<maxi++
Begin
Begin
if item_stock i .amount<=0
Begin
systempause
printMenu
End
input amount
id=i
if amount>item_stock i .amount
Begin
do
Begin
input 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
systempause
printMenu
End
End
File current2=fopenongoingtransaction.txt a
File current3=fopenongoingtransaction.txt r
char s
Display s
End
float payment
input payment
change=payment-n
if change<0
Begin
float remain
change=n-payment
systempause
input remain
change=remain-change
End
int LEN=150
time_t curtime
struct tm *loc_time
File lastprocess=fopenlasttransaction.txt w
if change>0
Begin
File sales=fopentotalsales.txt a
fDisplay sales Item : | Quantity : | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f | Change : $%0.2f item_stock
fcloselastprocess
fclosesales
Display Item : | Quantity : | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f | Change : $%0.2f item_stock id
File expensesr=fopenexpenses.txt r
float expenses
File profitsr=fopenprofits.txt r
float profits
File totalr=fopenpayments.txt r
float paymenttotal
fcloseexpensesr
fcloseprofitsr
fclosetotalr
paymenttotal=paymenttotal+n
expenses=expenses+item_stock id .cp*amount
profits=profits+n-expenses
File expensesw=fopenexpenses.txt w
File profitsw=fopenprofits.txt w
File totalw=fopenpayments.txt w
fcloseexpensesw
fcloseprofitsw
fclosetotalw
systempause
system clearscreen
fclosedata
systempause
End
if change==0
Begin
File sales=fopentotalsales.txt a
fDisplay sales Item : | Quantity : | Price : $%0.2f each | Total : $%0.2f | Payment : $%0.2f | Change : $%0.2f item_stock
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
systempause
system clearscreen
File expensesr=fopenexpenses.txt r
float expenses
File profitsr=fopenprofits.txt r
float profits
File totalr=fopenpayments.txt r
float paymenttotal
fcloseexpensesr
fcloseprofitsr
fclosetotalr
paymenttotal=paymenttotal+n
expenses=expenses+item_stock id .cp*amount
profits=profits+n-expenses
File expensesw=fopenexpenses.txt w
File profitsw=fopenprofits.txt w
File totalw=fopenpayments.txt w
fcloseexpensesw
fcloseprofitsw
fclosetotalw
systempause
system clearscreen
fclosedata
systempause
End
End
sale
End
else
Begin
system clearscreen
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
fclosecheck
fcloseintialise
End
File check1=fopenprofits.txt r
if check1==NULL||check1==\0
Begin
File intialise=fopenprofits.txt w
int num=0
fclosecheck1
fcloseintialise
End
File check2=fopenpayments.txt r
if check2==NULL||check2==\0
Begin
File intialise=fopenpayments.txt w
int num=0
fclosecheck2
fcloseintialise
End
End
sale
Begin
File lastprocess=fopenlasttransaction.txt r
File current3=fopentotalsales.txt r
system clearscreen
Begin
Display Sales
char s
Display s
End
Display ----------------------------------
Display s
End
systempause
printMenu
End
else
Begin
- 52 - Computer Science I.A|Timothy Adams|Fatima College
system clearscreen
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
char s
Display s
End
Display $
Display s
End
Display dollars
Display $
Display s
End
Display dollars
float profits1
float total1
if expenses1>total1
Begin
int expenses2
expenses2=profits1-expenses1
Display $
Display s
End
Display dollars
systempause
printMenu
- 54 - Computer Science I.A|Timothy Adams|Fatima College
End
else
Begin
Display $
Display s
End
Display dollars
End
systempause
printMenu
End
else
Begin
system clearscreen
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
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
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
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
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
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
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
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
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:
Figures:
Void Password()
Void SelectMenu()
Void InventoryMenu()
Void EditInventory()
Void Iftrueinv()
Void Iffalseinv()
Void delInventory()
Void pos()
Files
EXE DIRECTORY.
totalsales.txt
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