Вы находитесь на странице: 1из 195

BIRAT LAL SHRESTHA (1801T3100045)

STOCK MANAGEMENT SYSTEM


NEOTERIC NEPAL
Student Name: Birat Lal Shrestha Student ID: 1801T3100045 Centre Code: 1801 Class Code: IDITC Module Name: Introduction to C (CPG102)

INTRODUCTION TO C (CPG102)

Page

BIRAT LAL SHRESTHA (1801T3100045)

TABLE OF CONTENTS Chapter INTRODUCTION REQUIREMENTS SPECIFICATION PROGRAM SPECIFICATION SCREEN DESIGNS PROCESSING AND VALIDATION PROGRAM DESIGN TESTING IMPLEMENTATION CONCLUSION 5 6 7-18 19 20-163 169-178 179-194 195 PAGE 2-4

INTRODUCTION TO C (CPG102)

Page

BIRAT LAL SHRESTHA (1801T3100045)

INTRODUCITON About the Stakeholders

Neoteric Nepal is one of the largest distributors for IT, communications and entertainment goods in Nepal. This organization is situated in Golchha House which is located at Ganabahal Street of Kathmandu City. This company contributes industrialization in the nation and was a key supporter of foreign business affairs. It is the first organization to use the new distribution procedures providing warranty and service arrangement. This company holds a history of high successes in supporting its brands like Nokia, Samsung, Dell, HP and other worldwide popular brands. It even provides high satisfaction to the consumers through its maintenance and replacement services of its products. Since its establishment, it has got a huge number of satisfied and loyal customers. It has huge market share of products with a network of many, computer and technology, wholesalers, outlets and shops around the country. Hence, it provides an excellent distribution arrangement to serve the consumers and delivers a money-making business schemes to its retailing partners. As per a discussion with Sanjay Golchha, the owner and the managing director, and Deepak Thapa, the sales officer of the company, Neoteric deals with variety of information technology and communications products such as computers, laptops, mobile, telephones, display and storage devices, printing and imaging products, networking devices, entertainment and power management systems too and service oriented repair centre. Neoterics width of achievement across the Nepali market is matchless, and it operates on financially practicable ideology. Its quick development and high monetary effectiveness makes it an ultimate business associate, and is dedicated for the endurance to the countrys economy, its partners and customers.

INTRODUCTION TO C (CPG102)

Page

BIRAT LAL SHRESTHA (1801T3100045)

Current System

The study of the companys current system shows that they are using an old stock management system, used since the establishment of the business. According to the staffs of the company, the system is very difficult to understand, use and consumes too much time. In the present context of the business, the company has to perform so many business activities that are needed to be recorded into the database. But different tasks done in different software is a difficult way of management for them. For instance, they use different software systems to view, add or remove stocks; to keep purchase and sales records. This proved to be very time consuming for staffs. So they wanted a new single software system that was easier and could handle all those tasks within it.

Problem Background

According to the study of the current system, different problems were found out which are listed below: 1) Different software is used for different task that made the work more time and resources consuming. 2) The staffs needed to study each of the software individually that created a lot of confusion and made it difficult for them to understand and memorize them thoroughly. 3) Different types of items were recorded under same category that made it difficult for them to search an individual product.

INTRODUCTION TO C (CPG102)

Page

4) The current system is less secure as no authentication system is used.

BIRAT LAL SHRESTHA (1801T3100045)

REQUIREMENTS SPECIFICATION

Requirements of new system


To avoid the problems specified, the new system needs to include the following requirements: 1) The new system must include and handle all the tasks inside single software. 2) It should be easy to understand and use for the staffs, with simple language. 3) Same types of products must be shown under their relevant category for easier and faster searching and modifying. 4) Authentication system must be included having username and password.

Proposal of new System: Stock Management System for Neoteric Nepal Aim: The main aim of new system is to create an easier and safer interface of business management system. Objective: To help in effective management with add, search, update and removal features of the products through a single system interface.

INTRODUCTION TO C (CPG102)

Page

BIRAT LAL SHRESTHA (1801T3100045)

PROGRAM SPECIFICATION

Input Specification
S. No. 1. 2. 3. 4. Input Variable Company Model Price Quantity It denotes the name of products company. It denotes the model no. of the product. It indicates the price of the product. It indicates the quantity or number of the product. 50 50 50 50 Description Size(bytes) Data Type String String String String

File Specification

S. No.

File Pointer Name

Description

File name

File Type

1. 2. 3. 4. 5.

fp fp fp fp ft

It holds the laptop details to be recorded. It holds the cellphone details to be recorded. It holds the accessories details to be recorded. It holds the accessories details to be recorded. It holds the temporary details entered.

Laptops.dat Cells.dat Accessories.dat Parts.dat temp.dat

Dat Dat Dat Dat Dat

INTRODUCTION TO C (CPG102)

Page

BIRAT LAL SHRESTHA (1801T3100045)

SCREEN DESIGNS Outline Screen Designs

Stock Management System Neoteric Nepal

Details Student ID: Name: Submitted To: Course Name: Module Name: Term:

Info

Fig: Start-up Splash


Page

INTRODUCTION TO C (CPG102)

BIRAT LAL SHRESTHA (1801T3100045)

AUTHENTICATION REQUIRED Username: Password:

Info

Fig: Authentication Screen

INTRODUCTION TO C (CPG102)

Page

BIRAT LAL SHRESTHA (1801T3100045)

Main Menu

1. Manage Laptops

2. Manage Cellphones

3. Manage Accessories

4. Manage Parts

5. Log Out

e. Exit

Info
Press Option(1/2/3/4/5/e):

Fig: Main Menu

INTRODUCTION TO C (CPG102)

Page

BIRAT LAL SHRESTHA (1801T3100045)

Manage Parts

1. Add Parts

2. Search/List Parts

3. Update Parts

4. Delete Parts

5. Menu

Press Option(1/2/3/4/5):

Fig: Manage Parts Menu

INTRODUCTION TO C (CPG102)

Page

10

BIRAT LAL SHRESTHA (1801T3100045)

Add Record

Details Company:

Model:

Price(Rs.):

Quantiy:

ADD

RESET

CANCEL

Info Press ENTER to ADD/ R to RESET/ C to CANCEL

INTRODUCTION TO C (CPG102)

Page

11

Fig: Add Screen

BIRAT LAL SHRESTHA (1801T3100045)

Search/List Record

Company:

Model:

SEARCH

CANCEL

Info Press ENTER to SEARCH/ C to CANCEL

Fig: Search/List Screen

INTRODUCTION TO C (CPG102)

Page

12

BIRAT LAL SHRESTHA (1801T3100045)

Update Record

Company:

Model:

Price:

Quantity:

Update

Cancel

Info Press ENTER to UPDATE/ C to CANCEL

Fig: Update Screen

INTRODUCTION TO C (CPG102)

Page

13

BIRAT LAL SHRESTHA (1801T3100045)

Delete Record

Company:

Model:

DELETE

CANCEL

Info Press ENTER to DELETE/ C to CANCEL

INTRODUCTION TO C (CPG102)

Page

14

Fig: Delete Screen

BIRAT LAL SHRESTHA (1801T3100045)

Output Screenshots
Splash Screen

Authentication Screen

INTRODUCTION TO C (CPG102)

Page

15

BIRAT LAL SHRESTHA (1801T3100045)

Main Menu

Manage Screen

INTRODUCTION TO C (CPG102)

Page

16

BIRAT LAL SHRESTHA (1801T3100045)

Add Screen

Search/List Screen

INTRODUCTION TO C (CPG102)

Page

17

BIRAT LAL SHRESTHA (1801T3100045)

Update Screen

Delete Screen

INTRODUCTION TO C (CPG102)

Page

18

BIRAT LAL SHRESTHA (1801T3100045)

PROCESSING AND VALIDATION Processing

1) Authentication Username and password are provided in the system for authentication so that the records can be kept safe and secure from loss and theft. 2) Add/remove Laptops, Cellphones, Accessories and Parts can be recorded with the details of their company, model, price and quantity or removed when required. 3) Increase or decrease The quantity and price of every record can be increased or decreased according to the purchase or sales done. 4) Search The records can be searched according to their company and model which generates the required result if they match the added records.

Validation
1) Authentication username and password must be entered with same cases (Uppercase or lowercase) as validated. 2) Model of products must be unique for same company. 3) Company and model of the products must contain minimum of single character and company must be entered with block letters (Uppercase). 4) Both company and model should match the record while searching, updating or deleting the record. 5) Special characters shouldnt be used in authentication. 6) Only dot (.) can be used to enter product price.
Page

INTRODUCTION TO C (CPG102)

19

BIRAT LAL SHRESTHA (1801T3100045)

PROGRAM DESIGN PSUEDOCODE

MODULE SPLASH

DO DISPLAY STOCK MANAGEMENT SYSTEM DISPLAY NEOTERIC NEPAL DISPLAY DETAILS DISPLAY STUDENT NAME: DISPLAY ID: DISPLAY SUBMITTED TO: DISPLAY COURSE NAME: DISPLAY MODULE NAME: DISPLAY TERM: DISPLAY INFO DISPLAY PRESS ANY KEY TO CONTINUE. DISPLAY BIRAT LAL SHRESTHA DISPLAY 1801T3100045 DISPLAY INFORMATICS COLLEGE

DISPLAY IDITC

INTRODUCTION TO C (CPG102)

Page

20

DISPLAY CPG102 (INTRODUCTION TO C)

BIRAT LAL SHRESTHA (1801T3100045)

DISPLAY T1 END DO

MODULE AUTHENTICATION

DO FOR I EQUALS TO 0, i LESSER THAN OR EQUALS TO 3, INCREASE i by 1 DO DISPLAY AUTHENTICATION REQUIRED DISPLAY USERNAME: DISPLAY PASSWORD: DISPLAY INFO INPUT username INPUT password IF username = birat AND password= birat DO BREAK END DO ELSE DO DISPLAY INVALID USERNAME OR PASSWORD ENTERED!

END DO

INTRODUCTION TO C (CPG102)

Page

21

DISPLAY ATTEMPTS LEFT:

BIRAT LAL SHRESTHA (1801T3100045)

END IF END DO END FOR IF i LESS THAN OR EQUALS TO 3 DO CALL menu END DO ELSE DO DISPLAY NO AUTHENTICATION ATTEMPT LEFT. TRY NEXT TIME! EXIT END DO END IF END DO

MODULE CUSTOM SCANF FOR PASSWORD

DO count EQUALS TO 0 DO DO

IF in EQUALS TO 13 AND count LESS THAN 0

INTRODUCTION TO C (CPG102)

Page

22

GET in

BIRAT LAL SHRESTHA (1801T3100045)

DO BREAK END DO ELSE IF in EQUALS TO 8 AND count GREATER THAN 0 DO DISPLAY 8,32,8 DECREASE count BY 2 END DO ELSE IF in EQUALS TO 27 DO CALL splash END DO ELSE IF in NOT EQUALS TO 13 AND in NOT EQUALS TO 8 AND in NOT EQUALS TO 27 DO input[count] EQUALS TO in DISPLAY * END DO ELSE DO CONTINUE END DO END IF

INTRODUCTION TO C (CPG102)

Page

UNTILL count LESS THAN 50

23

INCREASE count BY 1

BIRAT LAL SHRESTHA (1801T3100045)

input[count] EQUALS TO 0 STRING COPY input END DO

MODULE CUSTOM SCANF FOR USERNAME

DO count EQUALS TO 0 DO DO GET in IF in EQUALS TO 13 AND count GREATER THAN 0 DO BREAK END DO ELSE IF in EQUALS TO 8 AND count GREATER THAN 0 DO DISPLAY 8,32,8 DECREASE count by2 END DO ELSE IF in EQUALS TO 27

CALL splash

INTRODUCTION TO C (CPG102)

Page

24

DO

BIRAT LAL SHRESTHA (1801T3100045)

END DO ELSE IF in NOT EQUALS TO 13 AND in NOT EQUALS TO 8 AND in TO 27 DO input[count] EQUALS TO in DISPLAY input[count] END DO ELSE DO CONTINUE END DO END IF INCREASE count BY 1 UNTILL count LESS THAN 50 input[count] EQUALS TO 0 STRING COPY input ENDDO NOT EQUALS

MODULE MENU

INTRODUCTION TO C (CPG102)

Page

DO

25

DO

BIRAT LAL SHRESTHA (1801T3100045)

DISPLAY MAIN MENU DISPLAY 1. MANAGE LAPTOPS DISPLAY 2. MANAGE CELLPHONES DISPLAY 3. MANAGE ACCESSORIES DISPLAY 4. MANAGE PARTS DISPLAY 5. LOG OUT DIPSLAY E. EXIT DISPLAY PRESS OPTION (1/2/3/4/5/6/E): DISPLAY INFO GET choice IF choice NOT EQUALS 1 AND choice NOT EQUALS 2 AND choice NOT EQUALS 3 AND choice NOT EQUALS 4 AND choice NOT EQUALS 5 AND choice NOT EQUALS E DO DISPLAY INVALID OPTION END DO END IF UNTIL choice NOT EQUALS TO E DO CASE choice 1 DO CALL manageLaps END DO choice 2 DO CALL manageCells

INTRODUCTION TO C (CPG102)

Page

26

BIRAT LAL SHRESTHA (1801T3100045)

END DO choice '3' DO CALL manageAccessories END DO choice '4 DO CALL manageParts END DO choice '5' DO CALL authentication END DO choice 'e' DO DISPLAY SEE YOU SOON! EXIT END DO

END CASE END DO

MODULE MANAGELAPS

INTRODUCTION TO C (CPG102)

Page

27

BIRAT LAL SHRESTHA (1801T3100045)

DO DO DISPLAY MANAGE LAPTOPS DISPLAY 1.ADD LAPTOPS DISPLAY 2.LIST/SEARCH LAPTOPS DISPLAY 3.UPDATE LAPTOPS DISPLAY 4.DELETE LAPTOPS DISPLAY 5.MENU DISPLAY PRESS MENU (1/2/3/4/5): DISPLAY INFO GET choice IF choice NOT EQUALS 1 AND choice NOT EQUALS 2 AND choice NOT EQUALS 3 AND choice NOT EQUALS 4 AND choice NOT EQUALS 5 DO DISPLAY "INVALID OPTION!" END DO END IF UNTIL choice NOT EQUALS TO 5 DO CASE choice 1 DO CALL addLaps

INTRODUCTION TO C (CPG102)

Page

choice 2

28

END DO

BIRAT LAL SHRESTHA (1801T3100045)

DO CALL searchListLaps END DO choice '3' DO CALL updateLaps END DO choice '4 DO CALL deleteLaps END DO choice '5' DO CALL menu END DO END CASE END DO

MODULE ADDLAPS

DO CREATE FILE *fp

DISPLAY ADD LAPTOPS

INTRODUCTION TO C (CPG102)

Page

29

BIRAT LAL SHRESTHA (1801T3100045)

DISPLAY DETAILS DISPLAY COMPANY: DISPLAYMODEL: DISPLAY PRICE (RS.): DISPLAY QUANTITY: DISPLAY ADD DISPLAY RESET DISPLAY CANCEL DISPLAY INFO DISPLAY PRESS ENTER TO ADD/ R TO RESET/ C TO CANCEL

INPUT lapCompany INPUT lapModel INPUT lapPrice INPUT lapQuantity GET add IF add EQUALS TO r OR add EQUALS TO R DO CALL addLaps END DO ELSE IF add EQUALS TO 'c' OR add EQUALS TO 'C' DO CALL menu

END IF

INTRODUCTION TO C (CPG102)

Page

30

END DO

BIRAT LAL SHRESTHA (1801T3100045)

OPEN FILE Laptops.dat IF fp EQUALS TO NULL DO DISPLAY FILE NOT FOUND!" CALL menu END DO ELSE DO WRITE laptop CLOSE fp END DO END IF DISPLAY "THE LAPTOP WAS SUCCESSFULLY RECORDED!" DISPLAY "ADD ANOTHER RECORD? (Y/N)" GET exit IF exit EQUALS TO 'y' OR exit EQUALS TO 'Y' DO CALL addLaps END DO ELSE DO CALL menu END DO

END DO

INTRODUCTION TO C (CPG102)

Page

31

END IF

BIRAT LAL SHRESTHA (1801T3100045)

MODULE SEARCHLISTLAPS

DO y EQUALS TO 7 flag EQUALS TO 0 CREATE FILE *fp DISPLAY LIST/SEARCH LAPTOPS DISPLAY COMPANY: DISPLAY MODEL: DISPLAY SEARCH DISPLAY CANCEL DISPLAY INFO DISPLAY PRESS ENTER TO SEARCH/ C TO CANCEL GET getch()

INPUT input INPUT input1 IF getch() EQUALS TO 'C' OR getch() EQUALS TO c' DO

END DO

INTRODUCTION TO C (CPG102)

Page

32

CALL menu

BIRAT LAL SHRESTHA (1801T3100045)

END IF DISPLAY SHOW SEARCH DISPLAY COMPANY DISPLAY MODEL DISPLAY PRICE DISPLAY QUANTITY DISPLAY INFO FILE OPEN Laptops.dat IF fp EQUALS NULL DO DISPLAY "FILE NOT FOUND!" CALL menu END DO END IF

WHILE READ laptop NOT EQUALS TO 0 DO IF STRING COMPARE laptop DO flag EQUALS 1 DISPLAY laptop lapCompany DISPLAY laptop lapModel DISPLAY laptop lapPrice

INTRODUCTION TO C (CPG102)

Page

INCREASE y BY 1

33

DISPLAY laptop lapQuantity

BIRAT LAL SHRESTHA (1801T3100045)

END DO END IF END DO END WHILE CLOSE fp IF flag EQUALS 0 DO DISPLAY Record not found! END DO END IF CLOSE fp DISPLAY Press any key to go to menu. CALL menu END DO

MODULE UPDATELAPS

DO y EQUALS TO 7 flag EQUALS TO 1 CREATE FILE *fp DISPLAY UPDATE LAPTOPS"

DISPLAY MODEL:

INTRODUCTION TO C (CPG102)

Page

34

DISPLAY COMPANY:

BIRAT LAL SHRESTHA (1801T3100045)

DISPLAY PRICE: DISPLAY QUANTITY: DISPLAY UPDATE DISPLAY CANCEL DISPLAY INFO DISPLAY "PRESS ENTER TO UPDATE/ C TO CANCEL" INPUT input INPUT input1 OPEN FILE Laptops.dat IF fp EQUALS TO NULL DO DISPLAY FILE NOT FOUND! CALL menu END DO END IF WHILE READ laptop NOT EQUALS TO 0 DO IF STRING COMPARE laptop lapCompany EQUALS TO 0 AND laptop lapModel EQUALS TO 0 DO flag EQUALS TO 1 BREAK END DO

INTRODUCTION TO C (CPG102)

Page

END DO

35

END IF

BIRAT LAL SHRESTHA (1801T3100045)

END WHILE IF flag EQUALS TO 0 DO DISPLAY Record not found! CALL menu END DO END IF DISPLAY UPDATE THE RECORD? (Y/N) GET YESNO IF YESNO EQUALS TO 'y' OR YESNO EQUALS TO 'Y' DO INPUT laptop lapPrice INPUT laptop lapQuantity SEEK FILE WRITE FILE laptop END DO ELSE DO CALL menu END DO END IF CLOSE fp DISPLAY "RECORD UPDATED SUCCESSFULLY!

CALL menu

INTRODUCTION TO C (CPG102)

Page

36

DISPLAY "PRESS ANY KEY TO GO TO MENU!

BIRAT LAL SHRESTHA (1801T3100045)

END DO

MODULE DELETELAPS

DO CREATE FILE *fp,*ft Y EQUALS TO 12 Flag EQUALS TO 0 DISPLAY DELETE LAPTOPS DISPLAY COMPANY: DISPLAY MODEL: DISPLAY DELETE DISPLAY CANCEL DISPLAY INFO DISPLAY PRESS ENTER TO DELETE/ C TO CANCEL INPUT input INPUT input1 GET add IF add EQUALS TO 'c' OR add EQUALS TO 'C' DO

END DO

INTRODUCTION TO C (CPG102)

Page

37

CALL menu

BIRAT LAL SHRESTHA (1801T3100045)

END IF

DISPLAY DELETE SCREEN DISPLAY INFO DISPLAY COMPANY DISPLAY MODEL

fp EQUALS TO fopen "Laptops.dat" IF fp EQUALS TO NULL DO DISPLAY FILE NOT FOUND! CALL menu EXIT END DO END IF WHILE READ laptop NOT EQUALS TO 0 DO IF STRING COMPARE laptop lapCompany EQUALS TO 0 AND laptop lapModel EQUALS TO 0 DO flag EQUALS TO 1 DISPLAY laptop lapCompany

INTRODUCTION TO C (CPG102)

Page

INCREASE y BY 1

38

DISPLAY laptop lapModel

BIRAT LAL SHRESTHA (1801T3100045)

BREAK END DO END IF END DO END WHILE IF flag EQUALS TO 0 DO DISPLAY "Record not found!" CALL menu END DO END IF DISPLAY DELETE THE RECORD? (Y/N) GET YESNO IF YESNO EQUALS TO 'y' OR YESNO EQUALS TO Y' DO ft EQUALS TO fopen "temp.dat" WHILE READ laptop DO IF STRING COMPARE laptop lapModel EQUALS TO 0 DO WRITE laptop END DO END DO

CLOSE fp

INTRODUCTION TO C (CPG102)

Page

39

END WHILE

BIRAT LAL SHRESTHA (1801T3100045)

CLOSE ft REMOVE Laptops.dat RENAME temp.dat TO Laptops.dat DISPLAY RECORD DELETED SUCCESSFULLY! CALL menu END DO ELSE DO DISPLAY RECORD NOT DELETED! CALL menu END DO END IF END DO

SIMILAR PSUEDOCODE FOR REST OF THE PRODUCTS

INTRODUCTION TO C (CPG102)

Page

40

BIRAT LAL SHRESTHA (1801T3100045)

PROGRAMMING CODE

#include<stdio.h> #include<conio.h> #include<string.h>

void splash();//prototype declaration for splash screen void authentication();//prototype declaration for authentication screen void menu();//prototype declaration for main menu screen void manageLaps();//prototype declaration for manage laptops screen void addLaps();//prototype declaration for add laptops screen void searchListLaps();//prototype declaration for list/search laptops screen void updateLaps();//prototype declaration for update laptops screen void deleteLaps();//prototype declaration for delete laptops screen void manageCells();//prototype declaration for manage cellphones screen void addCells();//prototype declaration for add cellphones screen void searchListCells();//prototype declaration for list/search cellphones screen void updateCells();//prototype declaration for update cellphones screen void deleteCells();//prototype declaration for delete cellphones screen void manageAccessories();//prototype declaration for manage accessories screen void addAccessories();//prototype declaration for add accessories screen void searchListAccessories();//prototype declaration for list/search accessories screen void updateAccessories();//prototype declaration for update accessories screen

void manageParts();//prototype declaration for manage parts screen

INTRODUCTION TO C (CPG102)

Page

41

void deleteAccessories();//prototype declaration for delete accessories screen

BIRAT LAL SHRESTHA (1801T3100045)

void addParts();//prototype declaration for add parts screen void searchListParts();//prototype declaration for list/search parts screen void updateParts();//prototype declaration for update parts screen void deleteParts();//prototype declaration for delete parts screen void scanUsername(char *);//function define for username scan void scanPassword(char *);//function define for password scan void scanCompany(char *);//function define for company scan void scanModel(char *);//function define for model scan void scanPrice(char *);//function define for price scan void scanQuantity(char *);//function define for quantity scan void makeBox(int, int, int, int);//prototype declaration for making boxes

//########################STRUCT DECLARATION############################// struct Laptops { char lapCompany[50]; char lapModel[50]; char lapPrice[50]; char lapQuantity[50]; }laptop;

struct Cells

INTRODUCTION TO C (CPG102)

Page

char cellCompany[50];

42

BIRAT LAL SHRESTHA (1801T3100045)

char cellModel[50]; char cellPrice[50]; char cellQuantity[50]; }cell;

struct Accessories { char accCompany[50]; char accModel[50]; char accPrice[50]; char accQuantity[50]; }access;

struct Parts { char partCompany[50]; char partModel[50]; char partPrice[50]; char partQuantity[50]; }part;

//#############################MAIN################################// void main()

INTRODUCTION TO C (CPG102)

Page

43

BIRAT LAL SHRESTHA (1801T3100045)

splash(); authentication(); menu(); manageLaps(); addLaps(); searchListLaps(); updateLaps(); deleteLaps();

//####################SPLASH SCREEN##########################//

void splash() {

textbackground(BLACK); clrscr();

textcolor(DARKGRAY); makeBox(2,2,77,47); textcolor(WHITE);

makeBox(20,5,40,3);

INTRODUCTION TO C (CPG102)

Page

44

makeBox(19,4,42,4);

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(YELLOW); makeBox(20,36,40,5); gotoxy(20,35); cprintf("Info"); gotoxy(27,5); cprintf(" STOCK MANAGEMENT SYSTEM "); gotoxy(32,7); cprintf(" NEOTERIC NEPAL"); textcolor(CYAN); makeBox(19,21,42,7); textcolor(LIGHTBLUE); makeBox(18,20,44,9); makeBox(33,19,12,2); textcolor(YELLOW); gotoxy(36,20); cprintf("Details"); textcolor(YELLOW); gotoxy(21,22); cprintf("Student Name: "); gotoxy(21,23); cprintf("ID: "); gotoxy(21,24); cprintf("Submitted To: ");

cprintf("Course Name: ");

INTRODUCTION TO C (CPG102)

Page

45

gotoxy(21,25);

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(21,26); cprintf("Module Name: "); gotoxy(21,27); cprintf("Term: ");

textcolor(WHITE); gotoxy(35,22); cprintf("Birat Lal Shrestha"); gotoxy(35,23); cprintf("1801T3100045"); gotoxy(35,24); cprintf("Informatics College"); gotoxy(35,25); cprintf("CPG102 (Introduction to C)"); gotoxy(35,26); cprintf("IDITC"); gotoxy(35,27); cprintf("T1");

textcolor(CYAN); gotoxy(25,37); cprintf("Press any key to continue...."); textcolor(BLACK);

getch();

INTRODUCTION TO C (CPG102)

Page

46

_setcursortype(_NOCURSOR);

BIRAT LAL SHRESTHA (1801T3100045)

authentication();

//#######################AUTHENTICATION############################//

void authentication() {

char username[50], password[50]; int i,j;

char input;

for(i=1;i<=3;i++) { textbackground(BLACK); clrscr();

makeBox(2,2,77,47);

INTRODUCTION TO C (CPG102)

Page

47

textcolor(DARKGRAY);

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(YELLOW); makeBox(27,20,25,4); makeBox(20,36,40,5);

textcolor(RED); gotoxy(28,18); cprintf("AUTHENTICATION REQUIRED"); textcolor(YELLOW); gotoxy(28,21); cprintf("Username: "); gotoxy(28,23); cprintf("Password: "); gotoxy(20,35); cprintf("Info");

_setcursortype(_SOLIDCURSOR); textcolor(WHITE); gotoxy(38,21); fflush(stdin); //scanf("%s",username); scanUsername(username);

fflush(stdin);

INTRODUCTION TO C (CPG102)

Page

48

gotoxy(38,23);

BIRAT LAL SHRESTHA (1801T3100045)

//scanf("%s",password);

scanPassword(password);

if(stricmp(username,"birat")==0 && stricmp(password,"birat")==0) { break; } else { textcolor(WHITE); gotoxy(22,37); cprintf("Invalid Username or Password entered!"); gotoxy(32,38); cprintf("Attempts Left: %d", 3-i); getch(); } }

if(i<=3)

menu();

INTRODUCTION TO C (CPG102)

Page

49

BIRAT LAL SHRESTHA (1801T3100045)

//clrscr(); } else { clrscr(); gotoxy(18,10); textcolor(GREEN); cprintf("No authentication attempt left. Try next time!"); getch(); exit(0); }

getch();

//#########################MENU###################################// void menu() { char choice; do {

clrscr();

INTRODUCTION TO C (CPG102)

Page

50

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(DARKGRAY); makeBox(2,2,77,47); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,12,2); makeBox(6,10,69,25);

textcolor(WHITE); gotoxy(34,5); cprintf("Main Menu"); textcolor(WHITE); gotoxy(10,12); cprintf("1. Manage Laptops"); gotoxy(10,16); cprintf("2. Manage Cells"); gotoxy(10,20); cprintf("3. Manage Accessories"); gotoxy(10,24); cprintf("4. Manage Parts"); gotoxy(10,28); cprintf("5. Log Out"); gotoxy(10,32); cprintf("e. Exit");

gotoxy(28,41);

INTRODUCTION TO C (CPG102)

Page

51

textcolor(WHITE);

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Press Option(1/2/3/4/5/e):"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); _setcursortype(_SOLIDCURSOR); gotoxy(55,41); fflush(stdin); choice=getche(); getch(); textcolor(YELLOW); if(choice!='1' && choice!='2' && choice!='3' && choice!='4' && choice!='5' && choice!='e')//entering choices {

gotoxy(35,43); printf("Invalid Option"); getch(); } }while(choice!='1' && choice!='2' && choice!='3' && choice!='4' && choice!='5' && choice!='e'); clrscr(); switch(choice)//cases for choices { case '1': { manageLaps();

INTRODUCTION TO C (CPG102)

Page

52

BIRAT LAL SHRESTHA (1801T3100045)

}break; case '2': { manageCells(); }break; case '3': { manageAccessories(); }break; case '4': { manageParts(); }break; case '5': { authentication(); }break; case 'e': { clrscr(); gotoxy(33,10); textcolor(WHITE); cprintf("See You Soon!");

exit(0);

INTRODUCTION TO C (CPG102)

Page

53

getch();

BIRAT LAL SHRESTHA (1801T3100045)

}break; } getch(); } //#############################MANAGE LAPTOPS##########################//

void manageLaps() { char insChoice; do { clrscr(); textcolor(DARKGRAY); makeBox(2,2,77,47); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,17,2); makeBox(6,10,69,20); textcolor(WHITE); gotoxy(34,5); cprintf("Manage Laptops");

INTRODUCTION TO C (CPG102)

Page

textcolor(WHITE);

54

textcolor(WHITE);

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(10,12); cprintf("1. Add Laptops"); gotoxy(10,16); cprintf("2. Search\List Laptops"); gotoxy(10,20); cprintf("3. Update Laptops"); gotoxy(10,24); cprintf("4. Delete Laptops"); gotoxy(10,28); cprintf("5. Menu"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); textcolor(WHITE); gotoxy(28,41); cprintf("Press Option(1/2/3/4/5):"); gotoxy(53,41); fflush(stdin); insChoice=getche(); getch();

if(insChoice!='1' && insChoice!='2' && insChoice!='3' && insChoice!='4' && insChoice!='5')

INTRODUCTION TO C (CPG102)

Page

gotoxy(35,43);

55

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Invalid Option!"); getch(); } }while(insChoice!='1' && insChoice!='2' && insChoice!='3' && insChoice!='4' && insChoice!='5'); clrscr(); switch(insChoice) { case '1': { addLaps(); }break; case '2': { searchListLaps(); }break; case '3': { updateLaps(); }break; case '4': { deleteLaps();

INTRODUCTION TO C (CPG102)

Page

case '5':

56

}break;

BIRAT LAL SHRESTHA (1801T3100045)

{ menu(); }break; } getch(); }

//#########################ADD LAPTOPS############################// void addLaps() { FILE *fp; long int size; char add; char exit; size=sizeof(laptop);

clrscr(); textcolor(YELLOW); makeBox(18,40,46,5); makeBox(32,4,14,2); makeBox(6,15,69,15);

makeBox(2,2,77,47);

INTRODUCTION TO C (CPG102)

Page

57

textcolor(DARKGRAY);

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(WHITE); gotoxy(34,5); cprintf("Add Laptops"); gotoxy(11,14); cprintf("Details"); gotoxy(11,16); cprintf("Company:"); gotoxy(11,20); cprintf("Model: "); gotoxy(11,24); cprintf("Price(Rs.): "); gotoxy(11,28); cprintf("Quantity: "); textcolor(YELLOW); gotoxy(20,32); cprintf("Add"); gotoxy(40,32); cprintf("Reset"); gotoxy(60,32); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39);

gotoxy(20,41);

INTRODUCTION TO C (CPG102)

Page

58

cprintf("Info");

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(YELLOW); cprintf("Press ENTER to ADD/ R to RESET/ C to CANCEL"); textcolor(YELLOW);

//scanning values from user gotoxy(31,16); _setcursortype(_SOLIDCURSOR); fflush(stdin); scanCompany(laptop.lapCompany); gotoxy(31,20); fflush(stdin); scanModel(laptop.lapModel); gotoxy(31,24); fflush(stdin); scanPrice(laptop.lapPrice); gotoxy(31,28); fflush(stdin); scanQuantity(laptop.lapQuantity);

_setcursortype(_NOCURSOR);

add=getch(); if(add=='r' || add=='R')//used to reset the window

addLaps();

INTRODUCTION TO C (CPG102)

Page

59

BIRAT LAL SHRESTHA (1801T3100045)

} else if(add=='c' || add=='C')//go back to main menu after cancelling { menu(); }

fp=fopen("Laptops.dat","ab+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(29,43); cprintf("File not found!"); getch(); menu(); }

else { fwrite(&laptop,size,1,fp); fclose(fp); }

INTRODUCTION TO C (CPG102)

Page

60

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(23,42); textcolor(YELLOW); cprintf("The laptop was successfully recorded!"); gotoxy(29,43); cprintf("Add another record? (Y/N)"); exit=getch(); if(exit=='y' || exit=='Y')//decision for new data input { addLaps(); } else { menu(); }

//#########################SEARCH/LIST LAPTOPS####################//

void searchListLaps() { FILE *fp; int y=7;

int flag=0;

INTRODUCTION TO C (CPG102)

Page

61

BIRAT LAL SHRESTHA (1801T3100045)

char input[50]; char input1[50]; long int size=sizeof(laptop); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,22,2); makeBox(6,12,69,8); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Search/List Laptops"); gotoxy(8,14); cprintf("Company: "); gotoxy(8,18); cprintf("Model: "); textcolor(YELLOW); gotoxy(25,32); cprintf("Search"); gotoxy(48,32); cprintf("Cancel");

textcolor(WHITE);

INTRODUCTION TO C (CPG102)

Page

62

gotoxy(20,39);

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Info"); textcolor(YELLOW); gotoxy(23,41); cprintf("Press ENTER to Search/ C to Cancel");

_setcursortype(_SOLIDCURSOR); gotoxy(23,14); scanCompany(input); gotoxy(23,18); scanModel(input1); _setcursortype(_NOCURSOR); if(getch()=='c' || getch()=='c') { menu(); }

clrscr(); textcolor(DARKGRAY); makeBox(2,2,77,47); textcolor(YELLOW); makeBox(10,7,60,30); makeBox(30,4,18,2); makeBox(20,40,40,5);

textcolor(WHITE);

INTRODUCTION TO C (CPG102)

Page

63

gotoxy(34,5);

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Show Search"); gotoxy(20,39); textcolor(WHITE); cprintf("Info"); //statics tile gotoxy(15,9); cprintf("Company");

gotoxy(30,9); cprintf("Model");

gotoxy(45,9); cprintf("Price");

gotoxy(60,9); cprintf("Quantity");

fp=fopen("Laptops.dat","rb+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(30,43);

getch();

INTRODUCTION TO C (CPG102)

Page

64

cprintf("File not found!");

BIRAT LAL SHRESTHA (1801T3100045)

menu(); }

while(fread(&laptop,size,1,fp)!=0) //fread returning zero means, the file has reached the end {

if((stricmp(input,laptop.lapCompany)==0) (stricmp(input1,laptop.lapModel)==0)) { flag=1;

&&

textcolor(YELLOW);

gotoxy(15,12); cprintf("%s",laptop.lapCompany);

gotoxy(30,12); cprintf("%s",laptop.lapModel);

gotoxy(45,12); cprintf("%s",laptop.lapPrice);

gotoxy(60,12); cprintf("%s",laptop.lapQuantity); y++;

INTRODUCTION TO C (CPG102)

Page

65

BIRAT LAL SHRESTHA (1801T3100045)

} }

if(flag==0) // if the record was not found { gotoxy(30,43); textcolor(YELLOW); cprintf("Record not found!"); }

fclose(fp);

textcolor(YELLOW); gotoxy(25,41); cprintf("Press any key to go to menu!");

getch(); menu();

} //############################UPDATE LAPTOPS##########################//

INTRODUCTION TO C (CPG102)

Page

66

void updateLaps()

BIRAT LAL SHRESTHA (1801T3100045)

FILE *fp; int flag=0; char input[50]; char input1[50]; char yesno; long int size=sizeof(laptop); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,17,2); makeBox(6,10,69,8); makeBox(6,24,69,8); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Update Laptops"); gotoxy(10,12); cprintf("Company: "); gotoxy(10,16); cprintf("Model: ");

cprintf("Price: ");

INTRODUCTION TO C (CPG102)

Page

67

gotoxy(10,26);

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(10,30); cprintf("Quantity: "); textcolor(YELLOW); gotoxy(25,34); cprintf("Update"); gotoxy(48,34); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); gotoxy(23,41); textcolor(YELLOW); cprintf("Press ENTER to Update/ C to Cancel"); gotoxy(34,12); scanCompany(input); gotoxy(34,16); scanModel(input1);

_setcursortype(_NOCURSOR);

fp=fopen("Laptops.dat","rb+");

if(fp==NULL) // if the file couldn't be opened

textcolor(YELLOW);

INTRODUCTION TO C (CPG102)

Page

68

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(16,42); cprintf("File not found!"); getch(); menu(); } while(fread(&laptop,size,1,fp)!=0) //fread returning zero means, the file has reached the end {

if((stricmp(input,laptop.lapCompany)==0) (stricmp(input1,laptop.lapModel)==0)) { flag=1;

&&

break; } }

if(flag==0) // if the record was not found { gotoxy(24,42); textcolor(YELLOW); cprintf("Record not found!"); getch();

INTRODUCTION TO C (CPG102)

Page

69

menu();

BIRAT LAL SHRESTHA (1801T3100045)

//ASK for the confirmation to modify

gotoxy(27,42); cprintf("Update the record? (y/n)"); fflush(stdin); yesno=getche();

if(yesno=='y' || yesno=='Y') { //modifying steps

//scanning the values from user _setcursortype(_SOLIDCURSOR); gotoxy(34,26); fflush(stdin); scanPrice(laptop.lapPrice); gotoxy(34,30); fflush(stdin); scanQuantity(laptop.lapQuantity);

//seek one record up

INTRODUCTION TO C (CPG102)

Page

70

fseek(fp,-size,SEEK_CUR);

BIRAT LAL SHRESTHA (1801T3100045)

//write the modified record into the file fwrite(&laptop,size,1,fp);

} else { menu(); }

fclose(fp);

textcolor(GREEN); gotoxy(25,43); cprintf("Record updated successfully!");

textcolor(YELLOW); gotoxy(25,44); cprintf("Press any key to go to menu!");

getch(); menu();

INTRODUCTION TO C (CPG102)

Page

71

BIRAT LAL SHRESTHA (1801T3100045)

//###########################DELETE LAPTOPS############################// void deleteLaps() { FILE *fp,*ft; int y=12; int flag=0; char input[50]; char input1[50]; char add; char yesno; long int size; size=sizeof(laptop); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,17,2); makeBox(6,19,69,6); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE);

cprintf("Delete Laptops");

INTRODUCTION TO C (CPG102)

Page

72

gotoxy(34,5);

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(10,20); cprintf("Company: "); gotoxy(10,24); cprintf("Model: "); textcolor(YELLOW); gotoxy(25,34); cprintf("Delete"); gotoxy(48,34); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); textcolor(YELLOW); gotoxy(23,41); cprintf("Press ENTER to Delete/ C to Cancel"); _setcursortype(_SOLIDCURSOR); gotoxy(25,20); fflush(stdin); scanCompany(input); gotoxy(25,24); fflush(stdin); scanModel(input1);

add=getch();

INTRODUCTION TO C (CPG102)

Page

73

_setcursortype(_NOCURSOR);

BIRAT LAL SHRESTHA (1801T3100045)

if(add=='c' || add=='c') { menu(); }

clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(31,4,17,2); makeBox(10,7,60,30);

gotoxy(34,5); textcolor(WHITE); cprintf("Delete Screen"); gotoxy(20,39); textcolor(WHITE); cprintf("Info");

textcolor(YELLOW);

gotoxy(25,9);//statics tile cprintf("Company");

gotoxy(50,9);

INTRODUCTION TO C (CPG102)

Page

74

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Model");

fp=fopen("Laptops.dat","rb+");//opens Instruments.dat file

if(fp==NULL) //if anycase the file cannot be opened { gotoxy(16,42); textcolor(RED); cprintf("File not found!"); getch(); menu(); exit(0);

while(fread(&laptop,size,1,fp)!=0)//read file { if((stricmp(input,laptop.lapCompany)==0) (stricmp(input1,laptop.lapModel)==0)) { flag=1; &&

INTRODUCTION TO C (CPG102)

Page

gotoxy(25,y);

75

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("%s",laptop.lapCompany);

gotoxy(50,y); cprintf("%s",laptop.lapModel);

y++; //print every new records in the new line break; } } if(flag==0) //if the record was not found { //show error message gotoxy(27,43); textcolor(YELLOW); cprintf("Record not found!"); getch(); menu(); } gotoxy(27,42); textcolor(YELLOW); cprintf("Delete the record? (y/n)"); fflush(stdin); yesno=getche();

INTRODUCTION TO C (CPG102)

Page

76

if(yesno=='y' || yesno=='Y')

BIRAT LAL SHRESTHA (1801T3100045)

ft=fopen("temp.dat","wb+"); //creates a new temp.dat file

rewind(fp); //rewind the original file InsChart.dat

//to copy every record from original to temp except the record to be deleted. while(fread(&laptop,size,1,fp)!=0) { if(stricmp(laptop.lapModel,input1)!=0) { fwrite(&laptop,size,1,ft); //write every record into temp.dat } } fclose(fp); fclose(ft);

//delete the original file remove("Laptops.dat");

//rename the temp.dat to Instruments.dat rename("temp.dat","Laptops.dat");

gotoxy(25,43); textcolor(GREEN);

getch();

INTRODUCTION TO C (CPG102)

Page

77

cprintf("Record deleted successfully!");

BIRAT LAL SHRESTHA (1801T3100045)

menu();

} else { gotoxy(27,43); textcolor(YELLOW); cprintf("Record not deleted!"); getch(); menu(); } }

//##########################MANAGE CELLS##############################//

void manageCells() { char insChoice; do { clrscr(); textcolor(YELLOW);

makeBox(32,4,21,2);

INTRODUCTION TO C (CPG102)

Page

78

makeBox(20,40,40,5);

BIRAT LAL SHRESTHA (1801T3100045)

makeBox(6,10,69,20); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Manage Cell Phones"); textcolor(WHITE); textcolor(WHITE); gotoxy(10,12); cprintf("1. Add Cell Phones"); gotoxy(10,16); cprintf("2. List/Search Cell Phones"); gotoxy(10,20); cprintf("3. Update Cell Phones"); gotoxy(10,24); cprintf("4. Delete Cell Phones"); gotoxy(10,28); cprintf("5. Menu"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); textcolor(WHITE);

cprintf("Press Option(1/2/3/4/5):");

INTRODUCTION TO C (CPG102)

Page

79

gotoxy(28,41);

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(53,41); fflush(stdin); insChoice=getche(); getch();

if(insChoice!='1' && insChoice!='2' && insChoice!='3' && insChoice!='4' && insChoice!='5') { gotoxy(35,43); cprintf("Invalid Option!"); getch(); } }while(insChoice!='1' && insChoice!='2' && insChoice!='3' && insChoice!='4' && insChoice!='5'); clrscr(); switch(insChoice) { case '1': { addCells(); }break; case '2': { searchListCells(); }break; case '3':

INTRODUCTION TO C (CPG102)

Page

80

BIRAT LAL SHRESTHA (1801T3100045)

{ updateCells(); }break; case '4': { deleteCells(); }break; case '5': { menu(); }break; } getch(); }

//#########################ADD CELLPHONES############################// void addCells() { FILE *fp; long int size; char add; char exit;

INTRODUCTION TO C (CPG102)

Page

81

size=sizeof(cell);

BIRAT LAL SHRESTHA (1801T3100045)

clrscr(); textcolor(YELLOW); makeBox(18,40,46,5); makeBox(32,4,16,2); makeBox(6,15,69,15); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Add Cellphones"); gotoxy(11,14); cprintf("Details"); gotoxy(11,16); cprintf("Company:"); gotoxy(11,20); cprintf("Model: "); gotoxy(11,24); cprintf("Price(Rs.): "); gotoxy(11,28); cprintf("Quantity: "); textcolor(YELLOW);

cprintf("Add");

INTRODUCTION TO C (CPG102)

Page

82

gotoxy(20,32);

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(40,32); cprintf("Reset"); gotoxy(60,32); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); gotoxy(20,41); textcolor(YELLOW); cprintf("Press ENTER to ADD/ R to RESET/ C to CANCEL"); textcolor(YELLOW);

//scanning values from user gotoxy(31,16); _setcursortype(_SOLIDCURSOR); fflush(stdin); scanCompany(cell.cellCompany); gotoxy(31,20); fflush(stdin); scanModel(cell.cellModel); gotoxy(31,24); fflush(stdin); scanPrice(cell.cellPrice);

fflush(stdin);

INTRODUCTION TO C (CPG102)

Page

83

gotoxy(31,28);

BIRAT LAL SHRESTHA (1801T3100045)

scanQuantity(cell.cellQuantity);

_setcursortype(_NOCURSOR);

add=getch(); if(add=='r' || add=='R')//used to reset the window { addCells(); } else if(add=='c' || add=='C')//go back to main menu after cancelling { menu(); }

fp=fopen("Cells.dat","ab+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(29,43); cprintf("File not found!"); getch(); menu();

INTRODUCTION TO C (CPG102)

Page

84

BIRAT LAL SHRESTHA (1801T3100045)

else { fwrite(&cell,size,1,fp); fclose(fp); }

gotoxy(22,42); textcolor(YELLOW); cprintf("The cellphone was successfully recorded!"); gotoxy(29,43); cprintf("Add another record? (Y/N)"); exit=getch(); if(exit=='y' || exit=='Y')//decision for new data input { addCells(); } else { menu(); }

INTRODUCTION TO C (CPG102)

Page

85

BIRAT LAL SHRESTHA (1801T3100045)

//#########################SEARCH/LIST CELLPHONES####################//

void searchListCells() { FILE *fp; int y=7;

int flag=0; char input[50]; char input1[50]; long int size=sizeof(cell); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,25,2); makeBox(6,12,69,8); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Search/List CellPhones"); gotoxy(8,14);

gotoxy(8,18);

INTRODUCTION TO C (CPG102)

Page

86

cprintf("Company: ");

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Model: "); textcolor(YELLOW); gotoxy(25,32); cprintf("Search"); gotoxy(48,32); cprintf("Cancel"); gotoxy(20,39); textcolor(WHITE); cprintf("Info"); textcolor(YELLOW); gotoxy(23,41); cprintf("Press ENTER to Search/ C to Cancel");

_setcursortype(_SOLIDCURSOR); gotoxy(23,14); scanCompany(input); gotoxy(23,18); scanModel(input1); _setcursortype(_NOCURSOR); if(getch()=='c' || getch()=='c') { menu(); }

clrscr();

INTRODUCTION TO C (CPG102)

Page

87

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(DARKGRAY); makeBox(2,2,77,47); textcolor(YELLOW); makeBox(10,7,60,30); makeBox(30,4,18,2); makeBox(20,40,40,5); gotoxy(34,5); textcolor(WHITE); cprintf("Show Search"); gotoxy(20,39); textcolor(WHITE); cprintf("Info"); //statics tile gotoxy(15,9); cprintf("Company");

gotoxy(30,9); cprintf("Model");

gotoxy(45,9); cprintf("Price");

gotoxy(60,9);

INTRODUCTION TO C (CPG102)

Page

88

cprintf("Quantity");

BIRAT LAL SHRESTHA (1801T3100045)

fp=fopen("Cells.dat","rb+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(30,43); cprintf("File not found!"); getch(); menu(); }

while(fread(&cell,size,1,fp)!=0) //fread returning zero means, the file has reached the end {

if((stricmp(input,cell.cellCompany)==0) (stricmp(input1,cell.cellModel)==0)) { flag=1;

&&

textcolor(YELLOW);

gotoxy(15,12); cprintf("%s",cell.cellCompany);

INTRODUCTION TO C (CPG102)

Page

gotoxy(30,12);

89

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("%s",cell.cellModel);

gotoxy(45,12); cprintf("%s",cell.cellPrice);

gotoxy(60,12); cprintf("%s",cell.cellQuantity); y++; } }

if(flag==0) // if the record was not found { gotoxy(30,43); textcolor(YELLOW); cprintf("Record not found!"); }

fclose(fp);

textcolor(YELLOW); gotoxy(25,41);

INTRODUCTION TO C (CPG102)

Page

90

cprintf("Press any key to go to menu!");

BIRAT LAL SHRESTHA (1801T3100045)

getch(); menu();

} //############################UPDATE CELLPHONES##########################//

void updateCells() {

FILE *fp; int flag=0; char input[50]; char input1[50]; char yesno; long int size=sizeof(cell); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,20,2); makeBox(6,10,69,8); makeBox(6,24,69,8); textcolor(DARKGRAY);

INTRODUCTION TO C (CPG102)

Page

91

makeBox(2,2,77,47);

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(WHITE); gotoxy(34,5); cprintf("Update Cellphones"); gotoxy(10,12); cprintf("Company: "); gotoxy(10,16); cprintf("Model: "); gotoxy(10,26); cprintf("Price: "); gotoxy(10,30); cprintf("Quantity: "); textcolor(YELLOW); gotoxy(25,34); cprintf("Update"); gotoxy(48,34); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); gotoxy(23,41); textcolor(YELLOW); cprintf("Press ENTER to Update/ C to Cancel"); gotoxy(34,12);

gotoxy(34,16);

INTRODUCTION TO C (CPG102)

Page

92

scanCompany(input);

BIRAT LAL SHRESTHA (1801T3100045)

scanModel(input1);

_setcursortype(_NOCURSOR);

fp=fopen("Cells.dat","rb+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(16,42); cprintf("File not found!"); getch(); menu(); } while(fread(&cell,size,1,fp)!=0) //fread returning zero means, the file has reached the end {

if((stricmp(input,cell.cellCompany)==0) (stricmp(input1,cell.cellModel)==0)) { flag=1;

&&

break;

INTRODUCTION TO C (CPG102)

Page

93

BIRAT LAL SHRESTHA (1801T3100045)

if(flag==0) // if the record was not found { gotoxy(24,42); textcolor(YELLOW); cprintf("Record not found!"); getch(); menu(); }

//ASK for the confirmation to modify

gotoxy(27,42); cprintf("Update the record? (y/n)"); fflush(stdin); yesno=getche();

if(yesno=='y' || yesno=='Y') { //modifying steps

//scanning the values from user

gotoxy(34,26);

INTRODUCTION TO C (CPG102)

Page

94

_setcursortype(_SOLIDCURSOR);

BIRAT LAL SHRESTHA (1801T3100045)

fflush(stdin); scanPrice(cell.cellPrice); gotoxy(34,30); fflush(stdin); scanQuantity(cell.cellQuantity);

//seek one record up fseek(fp,-size,SEEK_CUR);

//write the modified record into the file fwrite(&cell,size,1,fp);

} else { menu(); }

fclose(fp);

textcolor(GREEN);

cprintf("Record updated successfully!");

INTRODUCTION TO C (CPG102)

Page

95

gotoxy(25,43);

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(YELLOW); gotoxy(25,44); cprintf("Press any key to go to menu!");

getch(); menu(); }

//###########################DELETE CELLPHONES############################// void deleteCells() { FILE *fp,*ft; int y=12; int flag=0; char input[50]; char input1[50]; char add; char yesno; long int size; size=sizeof(cell); clrscr();

INTRODUCTION TO C (CPG102)

Page

makeBox(20,40,40,5);

96

textcolor(YELLOW);

BIRAT LAL SHRESTHA (1801T3100045)

makeBox(32,4,20,2); makeBox(6,19,69,6); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Delete Cellphones"); gotoxy(10,20); cprintf("Company: "); gotoxy(10,24); cprintf("Model: "); textcolor(YELLOW); gotoxy(25,34); cprintf("Delete"); gotoxy(48,34); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); textcolor(YELLOW);

cprintf("Press ENTER to Delete/ C to Cancel");

INTRODUCTION TO C (CPG102)

Page

97

gotoxy(23,41);

BIRAT LAL SHRESTHA (1801T3100045)

_setcursortype(_SOLIDCURSOR); gotoxy(25,20); fflush(stdin); scanCompany(input); gotoxy(25,24); fflush(stdin); scanModel(input1);

_setcursortype(_NOCURSOR); add=getch(); if(add=='c' || add=='c') { menu(); }

clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(31,4,17,2); makeBox(10,7,60,30);

gotoxy(34,5); textcolor(WHITE);

gotoxy(20,39);

INTRODUCTION TO C (CPG102)

Page

98

cprintf("Delete Screen");

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(WHITE); cprintf("Info");

textcolor(YELLOW);

gotoxy(25,9);//statics tile cprintf("Company");

gotoxy(50,9); cprintf("Model");

fp=fopen("Cells.dat","rb+");//opens Instruments.dat file

if(fp==NULL) //if anycase the file cannot be opened { gotoxy(16,42); textcolor(RED); cprintf("File not found!"); getch(); menu(); exit(0);

INTRODUCTION TO C (CPG102)

Page

99

BIRAT LAL SHRESTHA (1801T3100045)

while(fread(&cell,size,1,fp)!=0)//read file { if((stricmp(input,cell.cellCompany)==0) (stricmp(input1,cell.cellModel)==0)) { flag=1; &&

gotoxy(25,y); cprintf("%s",cell.cellCompany);

gotoxy(50,y); cprintf("%s",cell.cellModel);

y++; //print every new records in the new line break; } } if(flag==0) //if the record was not found { //show error message gotoxy(27,43); textcolor(YELLOW); cprintf("Record not found!");

INTRODUCTION TO C (CPG102)

Page

100

BIRAT LAL SHRESTHA (1801T3100045)

getch(); menu(); } gotoxy(27,42); textcolor(YELLOW); cprintf("Delete the record? (y/n)"); fflush(stdin); yesno=getche(); if(yesno=='y' || yesno=='Y') { ft=fopen("temp.dat","wb+"); //creates a new temp.dat file

rewind(fp); //rewind the original file InsChart.dat

//to copy every record from original to temp except the record to be deleted. while(fread(&cell,size,1,fp)!=0) { if(stricmp(cell.cellModel,input1)!=0) { fwrite(&cell,size,1,ft); //write every record into temp.dat } } fclose(fp); fclose(ft);

INTRODUCTION TO C (CPG102)

Page

101

BIRAT LAL SHRESTHA (1801T3100045)

//delete the original file remove("Cells.dat");

//rename the temp.dat to Instruments.dat rename("temp.dat","Cells.dat");

gotoxy(25,43); textcolor(GREEN); cprintf("Record deleted successfully!"); getch(); menu();

} else { gotoxy(27,43); textcolor(YELLOW); cprintf("Record not deleted!"); getch(); menu(); } }

INTRODUCTION TO C (CPG102)

Page

102

BIRAT LAL SHRESTHA (1801T3100045)

//##########################MANAGE ACCESSORIES##############################//

void manageAccessories() { char insChoice; do { clrscr(); textcolor(DARKGRAY); makeBox(2,2,77,47); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,21,2); makeBox(6,10,69,20); textcolor(WHITE); gotoxy(34,5); cprintf("Manage Accessories"); textcolor(WHITE); textcolor(WHITE); gotoxy(10,12); cprintf("1. Add Accessories"); gotoxy(10,16); cprintf("2. List/Search Accessories");

INTRODUCTION TO C (CPG102)

Page

103

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(10,20); cprintf("3. Update Accessories"); gotoxy(10,24); cprintf("4. Delete Accessories"); gotoxy(10,28); cprintf("5. Menu"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); textcolor(WHITE); gotoxy(28,41); cprintf("Press Option(1/2/3/4/5):"); gotoxy(53,41); fflush(stdin); insChoice=getche(); getch();

if(insChoice!='1' && insChoice!='2' && insChoice!='3' && insChoice!='4' && insChoice!='5') { gotoxy(35,43); cprintf("Invalid Option!"); getch(); } }while(insChoice!='1' && insChoice!='2' && insChoice!='3' && insChoice!='4' && insChoice!='5');

INTRODUCTION TO C (CPG102)

Page

104

BIRAT LAL SHRESTHA (1801T3100045)

clrscr(); switch(insChoice) { case '1': { addAccessories(); }break; case '2': { searchListAccessories(); }break; case '3': { updateAccessories(); }break; case '4': { deleteAccessories(); }break; case '5': { menu(); }break; } getch();

INTRODUCTION TO C (CPG102)

Page

105

BIRAT LAL SHRESTHA (1801T3100045)

//#########################ADD ACCESSORIES############################// void addAccessories() { FILE *fp; long int size; char add; char exit; size=sizeof(access);

clrscr(); textcolor(YELLOW); makeBox(18,40,46,5); makeBox(32,4,18,2); makeBox(6,15,69,15); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Add Accessories"); gotoxy(11,14);

INTRODUCTION TO C (CPG102)

Page

106

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Details"); gotoxy(11,16); cprintf("Company:"); gotoxy(11,20); cprintf("Model: "); gotoxy(11,24); cprintf("Price(Rs.): "); gotoxy(11,28); cprintf("Quantity: "); textcolor(YELLOW); gotoxy(20,32); cprintf("Add"); gotoxy(40,32); cprintf("Reset"); gotoxy(60,32); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); gotoxy(20,41); textcolor(YELLOW); cprintf("Press ENTER to ADD/ R to RESET/ C to CANCEL"); textcolor(YELLOW);

//scanning values from user

INTRODUCTION TO C (CPG102)

Page

107

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(31,16); _setcursortype(_SOLIDCURSOR); fflush(stdin); scanCompany(access.accCompany); gotoxy(31,20); fflush(stdin); scanModel(access.accModel); gotoxy(31,24); fflush(stdin); scanPrice(access.accPrice); gotoxy(31,28); fflush(stdin); scanQuantity(access.accQuantity);

_setcursortype(_NOCURSOR);

add=getch(); if(add=='r' || add=='R')//used to reset the window { addAccessories(); } else if(add=='c' || add=='C')//go back to main menu after cancelling { menu(); }

INTRODUCTION TO C (CPG102)

Page

108

BIRAT LAL SHRESTHA (1801T3100045)

fp=fopen("Accessories.dat","ab+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(29,43); cprintf("File not found!"); getch(); menu(); }

else { fwrite(&access,size,1,fp); fclose(fp); }

gotoxy(22,42); textcolor(YELLOW); cprintf("The accessory was successfully recorded!"); gotoxy(29,43); cprintf("Add another record? (Y/N)");

INTRODUCTION TO C (CPG102)

Page

109

BIRAT LAL SHRESTHA (1801T3100045)

exit=getch(); if(exit=='y' || exit=='Y')//decision for new data input { addAccessories(); } else { menu(); }

//#########################SEARCH/LIST ACCESSORIES####################//

void searchListAccessories() { FILE *fp; int y=7;

int flag=0; char input[50]; char input1[50]; long int size=sizeof(access); clrscr(); textcolor(YELLOW);

INTRODUCTION TO C (CPG102)

Page

110

BIRAT LAL SHRESTHA (1801T3100045)

makeBox(20,40,40,5); makeBox(32,4,25,2); makeBox(6,12,69,8); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Search/List Accessories"); gotoxy(8,14); cprintf("Company: "); gotoxy(8,18); cprintf("Model: "); textcolor(YELLOW); gotoxy(25,32); cprintf("Search"); gotoxy(48,32); cprintf("Cancel"); gotoxy(20,39); textcolor(WHITE); cprintf("Info"); textcolor(YELLOW); gotoxy(23,41); cprintf("Press ENTER to Search/ C to Cancel");

INTRODUCTION TO C (CPG102)

Page

111

BIRAT LAL SHRESTHA (1801T3100045)

_setcursortype(_SOLIDCURSOR); gotoxy(23,14); scanCompany(input); gotoxy(23,18); scanModel(input1); _setcursortype(_NOCURSOR); if(getch()=='c' || getch()=='c') { menu(); }

clrscr(); textcolor(DARKGRAY); makeBox(2,2,77,47); textcolor(YELLOW); makeBox(10,7,60,30); makeBox(30,4,18,2); makeBox(20,40,40,5); gotoxy(34,5); textcolor(WHITE); cprintf("Show Search"); gotoxy(20,39); textcolor(WHITE); cprintf("Info"); //statics tile

INTRODUCTION TO C (CPG102)

Page

112

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(15,9); cprintf("Company");

gotoxy(30,9); cprintf("Model");

gotoxy(45,9); cprintf("Price");

gotoxy(60,9); cprintf("Quantity");

fp=fopen("Accessories.dat","rb+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(30,43); cprintf("File not found!"); getch(); menu(); }

while(fread(&access,size,1,fp)!=0) //fread returning zero means, the file has reached the end

INTRODUCTION TO C (CPG102)

Page

113

BIRAT LAL SHRESTHA (1801T3100045)

if((stricmp(input,access.accCompany)==0) (stricmp(input1,access.accModel)==0)) { flag=1;

&&

textcolor(YELLOW);

gotoxy(15,12); cprintf("%s",access.accCompany);

gotoxy(30,12); cprintf("%s",access.accModel);

gotoxy(45,12); cprintf("%s",access.accPrice);

gotoxy(60,12); cprintf("%s",access.accQuantity); y++; } }

INTRODUCTION TO C (CPG102)

Page

if(flag==0) // if the record was not found

114

BIRAT LAL SHRESTHA (1801T3100045)

{ gotoxy(30,43); textcolor(YELLOW); cprintf("Record not found!"); }

fclose(fp);

textcolor(YELLOW); gotoxy(25,41); cprintf("Press any key to go to menu!");

getch(); menu();

} //############################UPDATE ACCESSORIES##########################//

void updateAccessories() {

FILE *fp; int flag=0;

INTRODUCTION TO C (CPG102)

Page

115

BIRAT LAL SHRESTHA (1801T3100045)

char input[50]; char input1[50]; char yesno; long int size=sizeof(access); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,20,2); makeBox(6,10,69,8); makeBox(6,24,69,8); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Update Accessories"); gotoxy(10,12); cprintf("Company: "); gotoxy(10,16); cprintf("Model: "); gotoxy(10,26); cprintf("Price: "); gotoxy(10,30); cprintf("Quantity: "); textcolor(YELLOW);

INTRODUCTION TO C (CPG102)

Page

116

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(25,34); cprintf("Update"); gotoxy(48,34); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); gotoxy(23,41); textcolor(YELLOW); cprintf("Press ENTER to Update/ C to Cancel"); gotoxy(34,12); scanCompany(input); gotoxy(34,16); scanModel(input1);

_setcursortype(_NOCURSOR);

fp=fopen("Accessories.dat","rb+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(16,42); cprintf("File not found!"); getch();

INTRODUCTION TO C (CPG102)

Page

117

BIRAT LAL SHRESTHA (1801T3100045)

menu(); } while(fread(&access,size,1,fp)!=0) //fread returning zero means, the file has reached the end {

if((stricmp(input,access.accCompany)==0) (stricmp(input1,access.accModel)==0)) { flag=1;

&&

break; } }

if(flag==0) // if the record was not found { gotoxy(24,42); textcolor(YELLOW); cprintf("Record not found!"); getch(); menu(); }

//ASK for the confirmation to modify

INTRODUCTION TO C (CPG102)

Page

118

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(27,42); cprintf("Update the record? (y/n)"); fflush(stdin); yesno=getche();

if(yesno=='y' || yesno=='Y') { //modifying steps

//scanning the values from user _setcursortype(_SOLIDCURSOR); gotoxy(34,26); fflush(stdin); scanPrice(access.accPrice); gotoxy(34,30); fflush(stdin); scanQuantity(access.accQuantity);

//seek one record up fseek(fp,-size,SEEK_CUR);

//write the modified record into the file fwrite(&access,size,1,fp);

INTRODUCTION TO C (CPG102)

Page

119

BIRAT LAL SHRESTHA (1801T3100045)

} else { menu(); }

fclose(fp);

textcolor(GREEN); gotoxy(25,43); cprintf("Record updated successfully!");

textcolor(YELLOW); gotoxy(25,44); cprintf("Press any key to go to menu!");

getch(); menu(); }

INTRODUCTION TO C (CPG102)

Page

void deleteAccessories()

120

//###########################DELETE ACCESSORIES############################//

BIRAT LAL SHRESTHA (1801T3100045)

{ FILE *fp,*ft; int y=12; int flag=0; char input[50]; char input1[50]; char add; char yesno; long int size; size=sizeof(access); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,20,2); makeBox(6,19,69,6); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Delete Accessories"); gotoxy(10,20); cprintf("Company: ");

INTRODUCTION TO C (CPG102)

Page

121

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(10,24); cprintf("Model: "); textcolor(YELLOW); gotoxy(25,34); cprintf("Delete"); gotoxy(48,34); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); textcolor(YELLOW); gotoxy(23,41); cprintf("Press ENTER to Delete/ C to Cancel"); _setcursortype(_SOLIDCURSOR); gotoxy(25,20); fflush(stdin); scanCompany(input); gotoxy(25,24); fflush(stdin); scanModel(input1);

_setcursortype(_NOCURSOR); add=getch(); if(add=='c' || add=='c') {

INTRODUCTION TO C (CPG102)

Page

122

BIRAT LAL SHRESTHA (1801T3100045)

menu(); }

clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(31,4,17,2); makeBox(10,7,60,30);

gotoxy(34,5); textcolor(WHITE); cprintf("Delete Screen"); gotoxy(20,39); textcolor(WHITE); cprintf("Info");

textcolor(YELLOW);

gotoxy(25,9);//statics tile cprintf("Company");

gotoxy(50,9); cprintf("Model");

INTRODUCTION TO C (CPG102)

Page

123

BIRAT LAL SHRESTHA (1801T3100045)

fp=fopen("Accessories.dat","rb+");//opens Instruments.dat file

if(fp==NULL) //if anycase the file cannot be opened { gotoxy(16,42); textcolor(RED); cprintf("File not found!"); getch(); menu(); exit(0);

while(fread(&access,size,1,fp)!=0)//read file { if((stricmp(input,access.accCompany)==0) (stricmp(input1,access.accModel)==0)) { flag=1; &&

gotoxy(25,y); cprintf("%s",access.accCompany);

INTRODUCTION TO C (CPG102)

Page

124

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(50,y); cprintf("%s",access.accModel);

y++; //print every new records in the new line break; } } if(flag==0) //if the record was not found { //show error message gotoxy(27,43); textcolor(YELLOW); cprintf("Record not found!"); getch(); menu(); } gotoxy(27,42); textcolor(YELLOW); cprintf("Delete the record? (y/n)"); fflush(stdin); yesno=getche(); if(yesno=='y' || yesno=='Y') { ft=fopen("temp.dat","wb+"); //creates a new temp.dat file

INTRODUCTION TO C (CPG102)

Page

125

BIRAT LAL SHRESTHA (1801T3100045)

rewind(fp); //rewind the original file InsChart.dat

//to copy every record from original to temp except the record to be deleted. while(fread(&access,size,1,fp)!=0) { if(stricmp(access.accModel,input1)!=0) { fwrite(&access,size,1,ft); //write every record into temp.dat } } fclose(fp); fclose(ft);

//delete the original file remove("Accessories.dat");

//rename the temp.dat to Instruments.dat rename("temp.dat","Accessories.dat");

gotoxy(25,43); textcolor(GREEN); cprintf("Record deleted successfully!"); getch(); menu();

INTRODUCTION TO C (CPG102)

Page

126

BIRAT LAL SHRESTHA (1801T3100045)

} else { gotoxy(27,43); textcolor(YELLOW); cprintf("Record not deleted!"); getch(); menu(); } }

//##########################MANAGE PARTS##############################//

void manageParts() { char insChoice; do { clrscr(); textcolor(DARKGRAY); makeBox(2,2,77,47); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,15,2);

INTRODUCTION TO C (CPG102)

Page

127

BIRAT LAL SHRESTHA (1801T3100045)

makeBox(6,10,69,20); textcolor(WHITE); gotoxy(34,5); cprintf("Manage Parts"); textcolor(WHITE); textcolor(WHITE); gotoxy(10,12); cprintf("1. Add Parts"); gotoxy(10,16); cprintf("2. List/Search Parts"); gotoxy(10,20); cprintf("3. Update Parts"); gotoxy(10,24); cprintf("4. Delete Parts"); gotoxy(10,28); cprintf("5. Menu"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); textcolor(WHITE); gotoxy(28,41); cprintf("Press Option(1/2/3/4/5):"); gotoxy(53,41); fflush(stdin); insChoice=getche();

INTRODUCTION TO C (CPG102)

Page

128

BIRAT LAL SHRESTHA (1801T3100045)

getch();

if(insChoice!='1' && insChoice!='2' && insChoice!='3' && insChoice!='4' && insChoice!='5') { gotoxy(35,43); cprintf("Invalid Option!"); getch(); } }while(insChoice!='1' && insChoice!='2' && insChoice!='3' && insChoice!='4' && insChoice!='5'); clrscr(); switch(insChoice) { case '1': { addParts(); }break; case '2': { searchListParts(); }break; case '3':

updateParts(); }break;

INTRODUCTION TO C (CPG102)

Page

129

BIRAT LAL SHRESTHA (1801T3100045)

case '4': { deleteParts(); }break; case '5': { menu(); }break; } getch(); }

//#########################ADD PARTS############################// void addParts() { FILE *fp; long int size; char add; char exit; size=sizeof(part);

clrscr(); textcolor(YELLOW);

INTRODUCTION TO C (CPG102)

Page

130

BIRAT LAL SHRESTHA (1801T3100045)

makeBox(18,40,46,5); makeBox(32,4,12,2); makeBox(6,15,69,15); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Add Parts"); gotoxy(11,14); cprintf("Details"); gotoxy(11,16); cprintf("Company:"); gotoxy(11,20); cprintf("Model: "); gotoxy(11,24); cprintf("Price(Rs.): "); gotoxy(11,28); cprintf("Quantity: "); textcolor(YELLOW); gotoxy(20,32); cprintf("Add"); gotoxy(40,32); cprintf("Reset"); gotoxy(60,32);

INTRODUCTION TO C (CPG102)

Page

131

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); gotoxy(20,41); textcolor(YELLOW); cprintf("Press ENTER to ADD/ R to RESET/ C to CANCEL"); textcolor(YELLOW);

//scanning values from user gotoxy(31,16); _setcursortype(_SOLIDCURSOR); fflush(stdin); scanCompany(part.partCompany); gotoxy(31,20); fflush(stdin); scanModel(part.partModel); gotoxy(31,24); fflush(stdin); scanPrice(part.partPrice); gotoxy(31,28); fflush(stdin); scanQuantity(part.partQuantity);

_setcursortype(_NOCURSOR);

INTRODUCTION TO C (CPG102)

Page

132

BIRAT LAL SHRESTHA (1801T3100045)

add=getch(); if(add=='r' || add=='R')//used to reset the window { addParts(); } else if(add=='c' || add=='C')//go back to main menu after cancelling { menu(); }

fp=fopen("Parts.dat","ab+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(29,43); cprintf("File not found!"); getch(); menu(); }

else {

INTRODUCTION TO C (CPG102)

Page

133

BIRAT LAL SHRESTHA (1801T3100045)

fwrite(&part,size,1,fp); fclose(fp); }

gotoxy(22,42); textcolor(YELLOW); cprintf("The part was successfully recorded!"); gotoxy(29,43); cprintf("Add another record? (Y/N)"); exit=getch(); if(exit=='y' || exit=='Y')//decision for new data input { addParts(); } else { menu(); }

//#########################SEARCH/LIST PARTS####################//

void searchListParts()

INTRODUCTION TO C (CPG102)

Page

134

BIRAT LAL SHRESTHA (1801T3100045)

{ FILE *fp; int y=7;

int flag=0; char input[50]; char input1[50]; long int size=sizeof(part); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,20,2); makeBox(6,12,69,8); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Search/List Parts"); gotoxy(8,14); cprintf("Company: "); gotoxy(8,18); cprintf("Model: "); textcolor(YELLOW); gotoxy(25,32);

INTRODUCTION TO C (CPG102)

Page

135

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Search"); gotoxy(48,32); cprintf("Cancel"); gotoxy(20,39); textcolor(WHITE); cprintf("Info"); textcolor(YELLOW); gotoxy(23,41); cprintf("Press ENTER to Search/ C to Cancel");

_setcursortype(_SOLIDCURSOR); gotoxy(23,14); scanCompany(input); gotoxy(23,18); scanModel(input1); _setcursortype(_NOCURSOR); if(getch()=='c' || getch()=='c') { menu(); }

clrscr(); textcolor(DARKGRAY); makeBox(2,2,77,47); textcolor(YELLOW);

INTRODUCTION TO C (CPG102)

Page

136

BIRAT LAL SHRESTHA (1801T3100045)

makeBox(10,7,60,30); makeBox(30,4,18,2); makeBox(20,40,40,5); gotoxy(34,5); textcolor(WHITE); cprintf("Show Search"); gotoxy(20,39); textcolor(WHITE); cprintf("Info"); //statics tile gotoxy(15,9); cprintf("Company");

gotoxy(30,9); cprintf("Model");

gotoxy(45,9); cprintf("Price");

gotoxy(60,9); cprintf("Quantity");

fp=fopen("Parts.dat","rb+");

if(fp==NULL) // if the file couldn't be opened

INTRODUCTION TO C (CPG102)

Page

137

BIRAT LAL SHRESTHA (1801T3100045)

{ textcolor(YELLOW); gotoxy(30,43); cprintf("File not found!"); getch(); menu(); }

while(fread(&part,size,1,fp)!=0) //fread returning zero means, the file has reached the end {

if((stricmp(input,part.partCompany)==0) (stricmp(input1,part.partModel)==0)) { flag=1;

&&

textcolor(YELLOW);

gotoxy(15,12); cprintf("%s",part.partCompany);

gotoxy(30,12); cprintf("%s",part.partModel);

INTRODUCTION TO C (CPG102)

Page

gotoxy(45,12);

138

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("%s",part.partPrice);

gotoxy(60,12); cprintf("%s",part.partQuantity); y++; } }

if(flag==0) // if the record was not found { gotoxy(30,43); textcolor(YELLOW); cprintf("Record not found!"); }

fclose(fp);

textcolor(YELLOW); gotoxy(25,41); cprintf("Press any key to go to menu!");

getch(); menu();

INTRODUCTION TO C (CPG102)

Page

139

BIRAT LAL SHRESTHA (1801T3100045)

} //############################UPDATE PARTS##########################//

void updateParts() {

FILE *fp; int flag=0; char input[50]; char input1[50]; char yesno; long int size=sizeof(part); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,15,2); makeBox(6,10,69,8); makeBox(6,24,69,8); textcolor(DARKGRAY); makeBox(2,2,77,47);

textcolor(WHITE); gotoxy(34,5); cprintf("Update Parts"); gotoxy(10,12);

INTRODUCTION TO C (CPG102)

Page

140

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Company: "); gotoxy(10,16); cprintf("Model: "); gotoxy(10,26); cprintf("Price: "); gotoxy(10,30); cprintf("Quantity: "); textcolor(YELLOW); gotoxy(25,34); cprintf("Update"); gotoxy(48,34); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); gotoxy(23,41); textcolor(YELLOW); cprintf("Press ENTER to Update/ C to Cancel"); gotoxy(34,12); scanCompany(input); gotoxy(34,16); scanModel(input1);

_setcursortype(_NOCURSOR);

INTRODUCTION TO C (CPG102)

Page

141

BIRAT LAL SHRESTHA (1801T3100045)

fp=fopen("Parts.dat","rb+");

if(fp==NULL) // if the file couldn't be opened { textcolor(YELLOW); gotoxy(16,42); cprintf("File not found!"); getch(); menu(); } while(fread(&part,size,1,fp)!=0) //fread returning zero means, the file has reached the end {

if((stricmp(input,part.partCompany)==0) (stricmp(input1,part.partModel)==0)) { flag=1;

&&

break; } }

if(flag==0) // if the record was not found { gotoxy(24,42);

INTRODUCTION TO C (CPG102)

Page

142

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(YELLOW); cprintf("Record not found!"); getch(); menu(); }

//ASK for the confirmation to modify

gotoxy(27,42); cprintf("Update the record? (y/n)"); fflush(stdin); yesno=getche();

if(yesno=='y' || yesno=='Y') { //modifying steps

//scanning the values from user _setcursortype(_SOLIDCURSOR); gotoxy(34,26); fflush(stdin); scanPrice(part.partPrice); gotoxy(34,30); fflush(stdin);

INTRODUCTION TO C (CPG102)

Page

143

BIRAT LAL SHRESTHA (1801T3100045)

scanQuantity(part.partQuantity);

//seek one record up fseek(fp,-size,SEEK_CUR);

//write the modified record into the file fwrite(&part,size,1,fp);

} else { menu(); }

fclose(fp);

textcolor(GREEN); gotoxy(25,43); cprintf("Record updated successfully!");

textcolor(YELLOW); gotoxy(25,44); cprintf("Press any key to go to menu!");

INTRODUCTION TO C (CPG102)

Page

144

BIRAT LAL SHRESTHA (1801T3100045)

getch(); menu(); }

//###########################DELETE PARTS############################// void deleteParts() { FILE *fp,*ft; int y=12; int flag=0; char input[50]; char input1[50]; char add; char yesno; long int size; size=sizeof(part); clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(32,4,15,2); makeBox(6,19,69,6); textcolor(DARKGRAY); makeBox(2,2,77,47);

INTRODUCTION TO C (CPG102)

Page

145

BIRAT LAL SHRESTHA (1801T3100045)

textcolor(WHITE); gotoxy(34,5); cprintf("Delete Parts"); gotoxy(10,20); cprintf("Company: "); gotoxy(10,24); cprintf("Model: "); textcolor(YELLOW); gotoxy(25,34); cprintf("Delete"); gotoxy(48,34); cprintf("Cancel"); textcolor(WHITE); gotoxy(20,39); cprintf("Info"); textcolor(YELLOW); gotoxy(23,41); cprintf("Press ENTER to Delete/ C to Cancel"); _setcursortype(_SOLIDCURSOR); gotoxy(25,20); fflush(stdin); scanCompany(input); gotoxy(25,24);

INTRODUCTION TO C (CPG102)

Page

146

BIRAT LAL SHRESTHA (1801T3100045)

fflush(stdin); scanModel(input1);

_setcursortype(_NOCURSOR); add=getch(); if(add=='c' || add=='c') { menu(); }

clrscr(); textcolor(YELLOW); makeBox(20,40,40,5); makeBox(31,4,17,2); makeBox(10,7,60,30);

gotoxy(34,5); textcolor(WHITE); cprintf("Delete Screen"); gotoxy(20,39); textcolor(WHITE); cprintf("Info");

textcolor(YELLOW);

INTRODUCTION TO C (CPG102)

Page

147

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(25,9);//statics tile cprintf("Company");

gotoxy(50,9); cprintf("Model");

fp=fopen("Parts.dat","rb+");//opens Instruments.dat file

if(fp==NULL) //if anycase the file cannot be opened { gotoxy(16,42); textcolor(RED); cprintf("File not found!"); getch(); menu(); exit(0);

while(fread(&part,size,1,fp)!=0)//read file { if((stricmp(input,part.partCompany)==0) (stricmp(input1,part.partModel)==0)) &&

INTRODUCTION TO C (CPG102)

Page

148

BIRAT LAL SHRESTHA (1801T3100045)

{ flag=1;

gotoxy(25,y); cprintf("%s",part.partCompany);

gotoxy(50,y); cprintf("%s",part.partModel);

y++; //print every new records in the new line break; } } if(flag==0) //if the record was not found { //show error message gotoxy(27,43); textcolor(YELLOW); cprintf("Record not found!"); getch(); menu(); } gotoxy(27,42); textcolor(YELLOW);

INTRODUCTION TO C (CPG102)

Page

149

BIRAT LAL SHRESTHA (1801T3100045)

cprintf("Delete the record? (y/n)"); fflush(stdin); yesno=getche(); if(yesno=='y' || yesno=='Y') { ft=fopen("temp.dat","wb+"); //creates a new temp.dat file

rewind(fp); //rewind the original file InsChart.dat

//to copy every record from original to temp except the record to be deleted. while(fread(&part,size,1,fp)!=0) { if(stricmp(part.partModel,input1)!=0) { fwrite(&part,size,1,ft); //write every record into temp.dat } } fclose(fp); fclose(ft);

//delete the original file remove("Parts.dat");

//rename the temp.dat to Instruments.dat rename("temp.dat","Parts.dat");

INTRODUCTION TO C (CPG102)

Page

150

BIRAT LAL SHRESTHA (1801T3100045)

gotoxy(25,43); textcolor(GREEN); cprintf("Record deleted successfully!"); getch(); menu();

} else { gotoxy(27,43); textcolor(YELLOW); cprintf("Record not deleted!"); getch(); menu(); } }

//#########################SCAN COMPANY###############################// void scanCompany(char *Company)//custom scanf function for names { char input[50];

INTRODUCTION TO C (CPG102)

Page

151

BIRAT LAL SHRESTHA (1801T3100045)

char in; int count=0; do { in= getch(); if(in==13 && count>0)//if the user presses enter { break; } else if(in==8 && count>0)//if the user presses backspaces { printf("%c%c%c",8,32,8); count-=2; } else if(in==27)//if user presses escape { splash();

} else if(in!=13 && in!=8 && in!=27 &&(in>=65 && in<=90)) { input[count]=in; cprintf("%c",input[count]); } else

INTRODUCTION TO C (CPG102)

Page

152

BIRAT LAL SHRESTHA (1801T3100045)

{ continue; } count++; }while(count<50); input[count]='\0'; strcpy(Company,input);//copy the value of the input to name }//end of function

//#####################SCAN MODEL##############################//

void scanModel(char *Model)//custom scanf function for names { char input[50]; char in; int count=0; do { in= getch(); if(in==13 && count>0)//if the user presses enter { break; } else if(in==8 && count>0)//if the user presses backspaces {

INTRODUCTION TO C (CPG102)

Page

153

BIRAT LAL SHRESTHA (1801T3100045)

printf("%c%c%c",8,32,8); count-=2; } else if(in==27)//if user presses escape { splash();

} else if(in!=13 && in!=8 && in!=27 && ((in>=46 && in<=57) || (in>=65 && in<=90)))//validation for modelno { input[count]=in; cprintf("%c",input[count]); } else { continue; } count++; }while(count<50); input[count]='\0'; strcpy(Model,input);//copy the value of the input to model }//end of function

INTRODUCTION TO C (CPG102)

Page

154

BIRAT LAL SHRESTHA (1801T3100045)

//###########################SCAN PRICE##################################//

void scanPrice(char *Price)//custom scanf function for names { char input[50]; char in; int count=0; do { in= getch(); if(in==13 && count>0)//if the user presses enter { break; } else if(in==8 && count>0)//if the user presses backspaces { printf("%c%c%c",8,32,8); count-=2; } else if(in==27)//if user presses escape { splash();

INTRODUCTION TO C (CPG102)

Page

155

BIRAT LAL SHRESTHA (1801T3100045)

else if(in!=13 && in!=8 && in!=27 && (in>=47 && in<=57))//validation for date format { input[count]=in; cprintf("%c",input[count]); } else { continue; } count++; }while(count<50); input[count]='\0'; strcpy(Price,input);//co

//###########################SCAN QUANTITY#################################//

void scanQuantity(char *Quantity)//custom scanf function for names { char input[50];

int count=0; do

INTRODUCTION TO C (CPG102)

Page

156

char in;

BIRAT LAL SHRESTHA (1801T3100045)

{ in= getch(); if(in==13 && count>0)//if the user presses enter { break; } else if(in==8 && count>0)//if the user presses backspaces { printf("%c%c%c",8,32,8); count-=2; } else if(in==27)//if user presses escape { splash();

} else if(in!=13 && in!=8 && in!=27 && (in>=47 && in<=57))//validation for date format { input[count]=in; cprintf("%c",input[count]); } else { continue;

INTRODUCTION TO C (CPG102)

Page

157

BIRAT LAL SHRESTHA (1801T3100045)

} count++; }while(count<50); input[count]='\0'; strcpy(Quantity,input);//co

//#########################SCAN USERNAME##########################//

void scanUsername(char *User)//custom scanf function for username { char input[50]; char in; int count=0; do { in= getch(); if(in==13 && count>0)//if the user presses enter { break; } else if(in==8 && count>0)//if the user presses backspaces { printf("%c%c%c",8,32,8);

INTRODUCTION TO C (CPG102)

Page

158

BIRAT LAL SHRESTHA (1801T3100045)

count-=2; } else if(in==27)//if user presses escape { splash();

} else if(in!=13 && in!=8 && in!=27 && ((in>=48 && in<=57) || (in>=65 && in<=90) || (in>=97 && in<=122))) { input[count]=in; cprintf("%c",input[count]); } else { continue; } count++; }while(count<50); input[count]='\0'; strcpy(User,input);//copy the value of the input to user }//end of function

INTRODUCTION TO C (CPG102)

Page

//########################SCAN PASSWORD#######################//

159

BIRAT LAL SHRESTHA (1801T3100045)

void scanPassword(char *pass)//custom scanf function for password { char input[50]; char in; int count=0; do { in= getch(); if(in==13 && count>0)//if the user presses enter { break; } else if(in==8 && count>0)//if the user presses backspaces { printf("%c%c%c",8,32,8); count-=2; } else if(in==27)//if user presses escape { splash();

} else if(in!=13 && in!=8 && in!=27 &&((in>=48 && in<=57)|| (in>=65 && in<=90) || (in>=97 && in<=122)))

INTRODUCTION TO C (CPG102)

Page

160

BIRAT LAL SHRESTHA (1801T3100045)

{ input[count]=in; cprintf("*"); } else { continue; } count++; }while(count<50); input[count]='\0'; strcpy(pass,input);//copy the value of the input to pass }

//#############################MAKE BOX#############################//

void makeBox(int x, int y, int width, int height) { int i,j; //top left corner gotoxy(x,y); cprintf("%c",218);

INTRODUCTION TO C (CPG102)

Page

161

BIRAT LAL SHRESTHA (1801T3100045)

//top right corner gotoxy(x+width,y); cprintf("%c",191);

//bottom left corner gotoxy(x,y+height); cprintf("%c",192);

//bottom right corner gotoxy(x+width, y+height); cprintf("%c",217);

for(i=x+1;i<x+width;i++) { //for top line

gotoxy(i,y); cprintf("%c",196);

//for bottom line gotoxy(i,y+height); cprintf("%c",196); }

for(j=y+1;j<y+height;j++)

INTRODUCTION TO C (CPG102)

Page

162

BIRAT LAL SHRESTHA (1801T3100045)

{ //for left line gotoxy(x,j); cprintf("%c",179);

//for right line gotoxy(x+width, j); cprintf("%c",179); } }

INTRODUCTION TO C (CPG102)

Page

163

BIRAT LAL SHRESTHA (1801T3100045)

TESTING Test Plan

Test Case No: 1.

Description

Test if the authentication screen appears when a key is pressed in the start-up splash screen.

2.

Test if the authentication is denied when username and password entered is incorrect.

3. 4.

Test if the Main Menu appears when the username and password are accepted. Test if the Manage Laptops screen appears when option 1 is entered in the Main Menu.

5.

Test if the Add Laptops screen appears when option 1 is entered in the Manage Laptops Screen and if the details entered are recorded.

6.

Test if the Search/List Laptops screen appears when option 2 is entered in the Manage Laptops screen and the laptop details entered are listed in Show Search screen.

7.

Test if the Update Laptops screen appears when option 3 is entered in the Manage Laptops screen and if the details entered are updated by searching again.

8.

Test if the Delete Laptops screen appears when option 4 is entered in the Manage Laptops screen and if the details entered are listed in Delete Screen for delete confirmation.

9. 10.

Test to confirm that the laptop records are deleted by searching again. Test if the Main Menu appears when option 5 is selected in the Manage Laptops screen.

11.

Test if the Manage Cellphones screen appears when option 2 is entered in the Main Menu.

INTRODUCTION TO C (CPG102)

Page

164

BIRAT LAL SHRESTHA (1801T3100045)

12.

Test if the Add Cellphones screen appears when option 1 is entered in the Manage Cellphones Screen and if the details entered are recorded.

13.

Test if the Search/List Cellphones screen appears when option 2 is entered in the Manage Cellphones screen and the cellphone details entered are listed in Show Search screen.

14.

Test if the Update Cellphones screen appears when option 3 is entered in the Manage Cellphones screen and if the details entered are updated by searching again.

15.

Test if the Delete Cellphones screen appears when option 4 is entered in the Manage Cellphones screen and if the details entered are listed in Delete Screen for delete confirmation.

16. 17.

Test to confirm that the cellphone records are deleted by searching again. Test if the Main Menu appears when option 5 is selected in the Manage Cellphones screen.

18.

Test if the Manage Accessories screen appears when option 3 is entered in the Main Menu.

19.

Test if the Add Accessories screen appears when option 1 is entered in the Manage Accessories Screen and if the details entered are recorded.

20.

Test if the Search/List Accessories screen appears when option 2 is entered in the Manage Accessories screen and the accessory details entered are listed in Show Search screen.

21.

Test if the Update Accessories screen appears when option 3 is entered in the Manage Accessories screen and if the details entered are updated by searching again.

22.

Test if the Delete Accessories screen appears when option 4 is entered in the Manage Accessories screen and if the details entered are listed in Delete Screen for delete confirmation.

23. 24.

Test to confirm that the accessory records are deleted by searching again. Test if the Main Menu appears when option 5 is selected in the Manage Accessories screen.

INTRODUCTION TO C (CPG102)

Page

165

BIRAT LAL SHRESTHA (1801T3100045)

25.

Test if the Manage Parts screen appears when option 4 is entered in the Main Menu.

26.

Test if the Add Parts screen appears when option 1 is entered in the Manage Parts Screen and if the details entered are recorded.

27.

Test if the Search/List Parts screen appears when option 2 is entered in the Manage Parts screen and the part details entered are listed in Show Search screen.

28.

Test if the Update Parts screen appears when option 3 is entered in the Manage Parts screen and if the details entered are updated by searching again.

29.

Test if the Delete Parts screen appears when option 4 is entered in the Manage Parts screen and if the details entered are listed in Delete Screen for delete confirmation.

30. 31.

Test to confirm that the part records are deleted by searching again. Test if the Main Menu appears when option 5 is selected in the Manage Parts screen.

32.

Test if the Authentication screen appears when option 5 is selected in the Main Menu.

33.

Test if the Exit screen when option e is selected in the Main Menu.

INTRODUCTION TO C (CPG102)

Page

166

BIRAT LAL SHRESTHA (1801T3100045)

Test Cases
Test Case 1: Test if the authentication screen appears when a key is pressed in the start-up splash screen. Test Input: Press any key in splash screen. Result Expected: Authentication screen should appear. Result Shown: Authentication screen appears. Conclusion: The result was show as expected.

Test Case 2: Test if the authentication is denied when username and password entered is incorrect. Test Input: Username and password are entered as asd. Result Expected: Authentication must be denied. Result Shown: Authentication is denied. Conclusion: The result was shown as expected.

Test Case 3: Test if the Main Menu appears when the username and password are accepted. Test Input: Username and password are entered as birat. Result Expected: Authentication must be accepted and Main menu should appear. Result Shown: Authentication is accepted and Main menu is shown. Conclusion: The result was shown as expected.

Test Case 4: Test if the Manage Laptops screen appears when option 1 is entered in the Main Menu. Test Input: Option 1 is entered. Result Expected: Manage Laptops screen must appear. Result Shown: Manage Laptops screen appears. Conclusion: The result was shown as expected.

INTRODUCTION TO C (CPG102)

Page

167

BIRAT LAL SHRESTHA (1801T3100045)

Test Case 5: Test if the Add Laptops screen appears when option 1 is entered in the Manage Laptops Screen and if the details entered are recorded. Test Input: Option 1 is entered and details are entered. Result Expected: Add Laptops screen must appear and details must be recorded. Result Shown: Add Laptops screen appears and details are recorded. Conclusion: The result was shown as expected.

Test Case 6: Test if the Search/List Laptops screen appears when option 2 is entered in the Manage Laptops screen and the laptop details entered are listed in Show Search screen. Test Input: Option 2 is entered and details are entered. Result Expected: Search/List Laptops screen must appear and record must be shown in Show Search screen. Result Shown: Search/List Laptops screen appears and records are shown. Conclusion: The result was shown as expected.

Test Case 7: Test if the Update Laptops screen appears when option 3 is entered in the Manage Laptops screen and if the details entered are updated by searching again. Test Input: Option 3 is entered and details are entered. Result Expected: Update Laptops screen must appear and details must be updated. Result Shown: Update Laptops screen appears and details are updated. Conclusion: The result was shown as expected.

Test Case 8: Test if the Delete Laptops screen appears when option 4 is entered in the Manage Laptops screen and if the details entered are listed in Delete Screen for delete confirmation. Test Input: Option 4 is entered and details are entered.

Result Shown: Delete Laptops screen and Delete screen appears. Conclusion: The result was shown as expected.

INTRODUCTION TO C (CPG102)

Page

168

Result Expected: Delete Laptops screen and Delete screen must appear.

BIRAT LAL SHRESTHA (1801T3100045)

Test Case 9: Test to confirm that the laptop records are deleted by searching again. Test Input: Details are entered in Search/List screen. Result Expected: Record not found message should appear. Result Shown: Record not found message appears. Conclusion: The result was shown as expected.

Test Case 10: Test if the Main Menu appears when option 5 is selected in the Manage Laptops screen. Test Input: Option 5 is entered. Result Expected: Main menu should appear. Result Shown: Main menu appears. Conclusion: The result was shown as expected.

Test Case 11: Test if the Manage Cellphones screen appears when option 2 is entered in the Main Menu. Test Input: Option 1 is entered. Result Expected: Manage Cellphones screen must appear. Result Shown: Manage Cellphones screen appears. Conclusion: The result was shown as expected.

Test Case 12: Test if the Add Cellphones screen appears when option 1 is entered in the Manage Cellphones Screen and if the details entered are recorded. Test Input: Option 1 is entered and details are entered. Result Expected: Add Cellphones screen must appear and details must be recorded. Result Shown: Add Cellphones screen appears and details are recorded.

INTRODUCTION TO C (CPG102)

Page

169

Conclusion: The result was shown as expected.

BIRAT LAL SHRESTHA (1801T3100045)

Test Case 13: Test if the Search/List Cellphones screen appears when option 2 is entered in the Manage Cellphones screen and the cellphone details entered are listed in Show Search screen. Test Input: Option 2 is entered and details are entered. Result Expected: Search/List Cellphones screen must appear and record must be shown in Show Search screen. Result Shown: Search/List Cellphones screen appears and records are shown. Conclusion: The result was shown as expected.

Test Case 14: Test if the Update Cellphones screen appears when option 3 is entered in the Manage Cellphones screen and if the details entered are updated by searching again. Test Input: Option 3 is entered and details are entered. Result Expected: Update Cellphones screen must appear and details must be updated. Result Shown: Update Cellphones screen appears and details are updated. Conclusion: The result was shown as expected.

Test Case 15: Test if the Delete Cellphones screen appears when option 4 is entered in the Manage Cellphones screen and if the details entered are listed in Delete Screen for delete confirmation. Test Input: Option 4 is entered and details are entered. Result Expected: Delete Cellphones screen and Delete screen must appear. Result Shown: Delete Cellphones screen and Delete screen appears. Conclusion: The result was show as expected.

Test Case 16: Test to confirm that the cellphone records are deleted by searching again. Test Input: Details are entered in Search/List screen.

Result Shown: Record not found message appears. Conclusion: The result was shown as expected.

INTRODUCTION TO C (CPG102)

Page

170

Result Expected: Record not found message should appear.

BIRAT LAL SHRESTHA (1801T3100045)

Test Case 17: Test if the Main Menu appears when option 5 is selected in the Manage Cellphones screen. Test Input: Option 5 is entered. Result Expected: Main menu should appear. Result Shown: Main menu appears. Conclusion: The result was shown as expected.

Test Case 18: Test if the Manage Accessories screen appears when option 3 is entered in the Main Menu. Test Input: Option 1 is entered. Result Expected: Manage Accessories screen must appear. Result Shown: Manage Accessories screen appears Conclusion: The result was shown as expected.

Test Case 19: Test if the Add Accessories screen appears when option 1 is entered in the Manage Accessories Screen and if the details entered are recorded. Test Input: Option 1 is entered and details are entered. Result Expected: Add Accessories screen must appear and details must be recorded. Result Shown: Add Accessories screen appears and details are recorded. Conclusion: The result was shown as expected.

Test Case 20: Test if the Search/List Accessories screen appears when option 2 is entered in the Manage Accessories screen and the accessory details entered are listed in Show Search screen. Test Input: Option 2 is entered and details are entered. Result Expected: Search/List Accessories screen must appear and record must be shown in

Result Shown: Search/List Accessories screen appears and records are shown. Conclusion: The result was shown as expected.

INTRODUCTION TO C (CPG102)

Page

171

Show Search screen.

BIRAT LAL SHRESTHA (1801T3100045)

Test Case 21: Test if the Update Accessories screen appears when option 3 is entered in the Manage Accessories screen and if the details entered are updated by searching again. Test Input: Option 3 is entered and details are entered. Result Expected: Update Accessories screen must appear and details must be updated. Result Shown: Update Accessories screen appears and details are updated. Conclusion: The result was shown as expected.

Test Case 22: Test if the Delete Accessories screen appears when option 4 is entered in the Manage Accessories screen and if the details entered are listed in Delete Screen for delete confirmation. Test Input: Option 4 is entered and details are entered. Result Expected: Delete Accessories screen and Delete screen must appear. Result Shown: Delete Accessories screen and Delete screen appears. Conclusion: The result was shown as expected.

Test Case 23: Test to confirm that the accessory records are deleted by searching again. Test Input: Details are entered in Search/List screen. Result Expected: Record not found message should appear. Result Shown: Record not found message appears. Conclusion: The result was shown as expected.

Test Case 24: Test if the Main Menu appears when option 5 is selected in the Manage Accessories screen. Test Input: Option 5 is entered. Result Expected: Main menu should appear.

Conclusion: The result was shown as expected.

INTRODUCTION TO C (CPG102)

Page

172

Result Shown: Main menu appears.

BIRAT LAL SHRESTHA (1801T3100045)

Test Case 25: Test if the Manage Parts screen appears when option 4 is entered in the Main Menu. Test Input: Option 1 is entered. Result Expected: Manage Parts screen must appear. Result Shown: Manage Parts screen appears. Conclusion: The result was shown as expected.

Test Case 26: Test if the Add Parts screen appears when option 1 is entered in the Manage Parts Screen and if the details entered are recorded. Test Input: Option 1 is entered and details are entered. Result Expected: Add Parts screen must appear and details must be recorded. Result Shown: Add Parts screen appears and details are recorded. Conclusion: The result was shown as expected.

Test Case 27: Test if the Search/List Parts screen appears when option 2 is entered in the Manage Parts screen and the part details entered are listed in Show Search screen. Test Input: Option 2 is entered and details are entered. Result Expected: Search/List Parts screen must appear and record must be shown in Show Search screen. Result Shown: Search/List Parts screen appears and records are shown. Conclusion: The result was shown as expected.

Test Case 28: Test if the Update Parts screen appears when option 3 is entered in the Manage Parts screen and if the details entered are updated by searching again. Test Input: Option 3 is entered and details are entered.

Result Shown: Update Parts screen appears and details are updated. Conclusion: The result was shown as expected.

INTRODUCTION TO C (CPG102)

Page

173

Result Expected: Update Parts screen must appear and details must be updated.

BIRAT LAL SHRESTHA (1801T3100045)

Test Case 29: Test if the Delete Parts screen appears when option 4 is entered in the Manage Parts screen and if the details entered are listed in Delete Screen for delete confirmation. Test Input: Option 4 is entered and details are entered. Result Expected: Delete Parts screen and Delete screen must appear. Result Shown: Delete Parts screen and Delete screen appears. Conclusion: The result was shown as expected.

Test Case 30: Test to confirm that the part records are deleted by searching again. Test Input: Details are entered in Search/List screen. Result Expected: Record not found message should appear. Result Shown: Record not found message appears. Conclusion: The result was shown as expected.

Test Case 31: Test if the Main Menu appears when option 5 is selected in the Manage Parts screen. Test Input: Option 5 is entered. Result Expected: Main menu should appear. Result Shown: Main menu appears. Conclusion: The result was shown as expected.

Test Case 32: Test if the Authentication screen appears when option 5 is selected in the Main Menu. Test Input: Option 5 is entered. Result Expected: Authentication screen must appear. Result Shown: Authentication screen appears.

INTRODUCTION TO C (CPG102)

Page

174

Conclusion: The result was show as expected.

BIRAT LAL SHRESTHA (1801T3100045)

Test Case 33: Test if the Exit screen when option e is selected in the Main Menu. Test Input: Option e is entered. Result Expected: Exit screen must appear. Result Shown: Exit screen appears. Conclusion: The result was show as expected.

INTRODUCTION TO C (CPG102)

Page

175

BIRAT LAL SHRESTHA (1801T3100045)

Test Log
Test Case No: 1. Test if the authentication screen appears when a key is pressed in the start-up splash screen. 2. Test if the authentication is denied when username and password entered is incorrect. 3. Test if the Main Menu appears when the username and password are accepted. 4. Test if the Manage Laptops screen appears when option 1 is entered in the Main Menu. 5. Test if the Add Laptops screen appears when option 1 is entered in the Manage Laptops Screen and if the details entered are recorded. 6. Test if the Search/List Laptops screen appears when option 2 is entered in Done the Manage Laptops screen and the laptop details entered are listed in Show Search screen. 7. Test if the Update Laptops screen appears when option 3 is entered in the Manage Laptops screen and if the details entered are updated by searching again. 8. Test if the Delete Laptops screen appears when option 4 is entered in the Manage Laptops screen and if the details entered are listed in Delete Screen for delete confirmation. 9. 10. Test to confirm that the laptop records are deleted by searching again. Test if the Main Menu appears when option 5 is selected in the Manage Laptops screen. 11. Test if the Manage Cellphones screen appears when option 2 is entered in Done the Main Menu. Done Done Done Done Done Done Done Done Done Description Outcome

INTRODUCTION TO C (CPG102)

Page

176

BIRAT LAL SHRESTHA (1801T3100045)

12.

Test if the Add Cellphones screen appears when option 1 is entered in the Manage Cellphones Screen and if the details entered are recorded.

Done

13.

Test if the Search/List Cellphones screen appears when option 2 is entered in the Manage Cellphones screen and the cellphone details entered are listed in Show Search screen.

Done

14.

Test if the Update Cellphones screen appears when option 3 is entered in the Manage Cellphones screen and if the details entered are updated by searching again.

Done

15.

Test if the Delete Cellphones screen appears when option 4 is entered in the Manage Cellphones screen and if the details entered are listed in Delete Screen for delete confirmation.

Done

16. 17.

Test to confirm that the cellphone records are deleted by searching again. Test if the Main Menu appears when option 5 is selected in the Manage Cellphones screen.

Done Done

18.

Test if the Manage Accessories screen appears when option 3 is entered in the Main Menu.

Done

19.

Test if the Add Accessories screen appears when option 1 is entered in the Manage Accessories Screen and if the details entered are recorded.

Done

20.

Test if the Search/List Accessories screen appears when option 2 is entered in the Manage Accessories screen and the accessory details entered are listed in Show Search screen.

Done

21.

Test if the Update Accessories screen appears when option 3 is entered in the Manage Accessories screen and if the details entered are updated by searching again.

Done

22.

Test if the Delete Accessories screen appears when option 4 is entered in the Manage Accessories screen and if the details entered are listed in Delete Screen for delete confirmation.

Done

23. 24.

Test to confirm that the accessory records are deleted by searching again. Test if the Main Menu appears when option 5 is selected in the Manage Accessories screen.

Done Done

INTRODUCTION TO C (CPG102)

Page

177

BIRAT LAL SHRESTHA (1801T3100045)

25.

Test if the Manage Parts screen appears when option 4 is entered in the Main Menu.

Done

26.

Test if the Add Parts screen appears when option 1 is entered in the Manage Parts Screen and if the details entered are recorded.

Done

27.

Test if the Search/List Parts screen appears when option 2 is entered in the Manage Parts screen and the part details entered are listed in Show Search screen.

Done

28.

Test if the Update Parts screen appears when option 3 is entered in the Manage Parts screen and if the details entered are updated by searching again.

Done

29.

Test if the Delete Parts screen appears when option 4 is entered in the Manage Parts screen and if the details entered are listed in Delete Screen for delete confirmation.

Done

30. 31.

Test to confirm that the part records are deleted by searching again. Test if the Main Menu appears when option 5 is selected in the Manage Parts screen.

Done Done

32.

Test if the Authentication screen appears when option 5 is selected in the Main Menu.

Done

33.

Test if the Exit screen when option e is selected in the Main Menu.

Done

INTRODUCTION TO C (CPG102)

Page

178

BIRAT LAL SHRESTHA (1801T3100045)

IMPLEMENTATION Hardware & Software Specifications Hardware

Processor: Pentium III or higher Ram: 64 mb or higher Hard disk: 100 mb free space Floppy disk/CD-ROM/USB drive

Software
Operating System: Windows 98 or later (32-bit) Program: Turbo-C Command window must be changed to following properties: Screen Buffer Size: Width-80 and Height-60 Window Size: Width-80 and Height-60

INTRODUCTION TO C (CPG102)

Page

179

BIRAT LAL SHRESTHA (1801T3100045)

User Instruction Manual


Note: Companys name and model must be entered in Uppercase or Capital letters. Lowercase letters are not accepted. Numbers are also not accepted in Companys name. 1. Splash Screen appears when the program is run. Press any key in the splash screen to go to authentication screen.

INTRODUCTION TO C (CPG102)

Page

180

BIRAT LAL SHRESTHA (1801T3100045)

2. Username and Password for authentication are birat and birat respectively. They must be entered with correct cases (Uppercase or Lowercase) to go to main menu.

Incorrect username or password is denied for authentication. And only 3 attempts are provided.

INTRODUCTION TO C (CPG102)

Page

181

BIRAT LAL SHRESTHA (1801T3100045)

3. Choose an option and enter the correct option no. to go through the sub-menu. For example, to manage laptops, enter option no. 1.

INTRODUCTION TO C (CPG102)

Page

182

BIRAT LAL SHRESTHA (1801T3100045)

4. After an option is selected in the main menu, the sub-menu for managing products appears. For example, if option 1 is selected, Manage Laptops screen will appear, if option 2 is selected, Manage Cellphones screen will appear and so on.

INTRODUCTION TO C (CPG102)

Page

183

BIRAT LAL SHRESTHA (1801T3100045)

4. Choose an option to manage the products in the Manage screen and enter the correct option to go to sub-menu. For example, to Add laptops, option no. 1 must be entered, to List/search laptops, option no. 2 must be entered and so on.

INTRODUCTION TO C (CPG102)

Page

184

BIRAT LAL SHRESTHA (1801T3100045)

5. In the Add screen, enter the details required for the record. If the details entered are correct, press Enter to record the details, R to reset the details to enter the details again and C to cancel the record. After a product is recorded, press y to add another record or N to go to the main menu.

INTRODUCTION TO C (CPG102)

Page

185

BIRAT LAL SHRESTHA (1801T3100045)

6. In the Search/list screen, enter the company and model details of the product required for searching and listing. If the details entered are correct, press Enter to search and if details are incorrect, press C to cancel and go to main menu.

INTRODUCTION TO C (CPG102)

Page

186

BIRAT LAL SHRESTHA (1801T3100045)

7. If the details are correct, the show search screen will appear that shows the list of searched products. Otherwise, No record found message will appear.

INTRODUCTION TO C (CPG102)

Page

187

BIRAT LAL SHRESTHA (1801T3100045)

8. In the Update screen, enter the details of the product to be updated. If the details are found in the record, confirmation for update will be asked. To update the record, press Y or press N to cancel the update. After confirming the update, enter new details to update the record and press Enter. If the record is updated, record updated successfully message will appear. Then, press any key to go to main menu.

INTRODUCTION TO C (CPG102)

Page

188

BIRAT LAL SHRESTHA (1801T3100045)

9. To show the updated record, go to the search screen and enter the record details. The record will be shown in Show Search screen.

INTRODUCTION TO C (CPG102)

Page

189

BIRAT LAL SHRESTHA (1801T3100045)

10. In the Delete screen, enter the details of the record to be deleted and press Enter to delete or C to cancel the delete and go to main menu.

INTRODUCTION TO C (CPG102)

Page

190

BIRAT LAL SHRESTHA (1801T3100045)

11. If the details of the record to be deleted are correct, the record will be shown in the Delete sub-screen. To confirm the delete, press Y or to cancel and go to main menu, press N. If the record is deleted, Record deleted successfully message will appear and if not deleted, File not found message appears.

INTRODUCTION TO C (CPG102)

Page

191

BIRAT LAL SHRESTHA (1801T3100045)

12. To go back to main menu from Manage screen press 5.

INTRODUCTION TO C (CPG102)

Page

192

BIRAT LAL SHRESTHA (1801T3100045)

13. In the main menu, press 5 to log out and go to Authentication screen.

INTRODUCTION TO C (CPG102)

Page

193

BIRAT LAL SHRESTHA (1801T3100045)

14. In the main menu, press e to exit from the system. The exit screen will appear with message See you soon where any key can be pressed to exit.

INTRODUCTION TO C (CPG102)

Page

194

BIRAT LAL SHRESTHA (1801T3100045)

CONCLUSION
After the development of the software, following conclusions of its strengths, weaknesses and enhancements were found out from its features:

Strengths
1. Different types of product records can be stored such as Laptops, Cellphones, Accessories and Parts, with details like Company, Model, Price and Quantity. 2. Adding, searching, updating and deleting of records can be easily and efficiently done. 3. Authentication keeps the records safe from loss or theft.

Weaknesses
1. Only one record can be searched and listed at a time. 2. Reset or Cancel cannot function until all the details are entered in the required fields. 3. Option entered in menu cannot be cleared back to enter another option.

Enhancements
1. Search/list feature can be improved for listing more than one product at a time. 2. An addition to print bills and reports can be enhanced.

ACKNOWLEDGEMENT
I, Birat Lal Shrestha, student of Informatics College, am very grateful to the teacher, Sir Prakash Shrestha, for offering me such a great project. He provided us such a huge knowledge that helped to develop this Stock Management System and also helped a lot to clear the confusions and mistakes while doing this project. I am sure that all the knowledge I gained, from him and this work, will be very helpful in our future.

INTRODUCTION TO C (CPG102)

Page

195

Вам также может понравиться