0% found this document useful (0 votes)
32 views

Pseudo Code

The document describes a book management system with options to list, search, update, add and delete book records. It includes functions to read book data from a file, search by ISBN or keyword, and update book details. Pseudocode is provided for the various operations on book records stored in an array.

Uploaded by

Saravanan Raj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Pseudo Code

The document describes a book management system with options to list, search, update, add and delete book records. It includes functions to read book data from a file, search by ISBN or keyword, and update book details. Pseudocode is provided for the various operations on book records stored in an array.

Uploaded by

Saravanan Raj
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

{

Book_Data book[100]
character choice[15]
character flag[10]
read_file(book, num)

DO

DO

INPUT choice

WHILE (strlen(choice) > 1 || choice[0] < 1 || choice[0] > 8)

DISPLAY invalid input. Please try again:

DISPLAY please select the option code [1-8]:

INPUT choice

} WHILE (strlen(choice) > 1 || choice[0] < 1 || choice[0] > 8);

SWITCH

CASE 1 : list

BREAK

CASE 2 : search_isbn_number

BREAK

CASE 3 : search_by_keyword

BREAK

CASE 4 : show_low_inventories

BREAK

CASE 5 : update_book

read_file

BREAK

CASE 6 : add_book

read_file
BREAK

CASE 7 : delete_book

read_file

BREAK

CASE 8 : exit

BREAK

DISPLAY Do you wish to continue your program by returning to main menu? ( 1-Yes , 0-No )

INPUT flag

WHILE (flag[0] = 1 && flag[0] = 0 || strlen(flag) > 1)

{
DISPLAY Invalid input. Please Try Again:

DISPLAY Do you wish to continue your program by returning to main menu? (1-Yes , 0-No)

INPUT flag

} WHILE flag = 1

EXIT

DISPLAY WELCOME to book records

DISPLAY Please choose any options below to continue

DISPLAY 1) Display list of records

DISPLAY 2) Search by ISBN number

DISPLAY 3) Search by key word

DISPLAY 4) Show low inventories


DISPLAY 5) Update information

DISPLAY 6) Add book

DISPLAY 7) Delete Book

DISPLAY 8) Exit

DISPLAY Please Select The Option Code [ 1-8 ]:

string line
Set i = 0

ifstream inFile(bookstore.txt)

IF(inFile)

WHILE(getline)

book[i].book_name

book[i].isbn_number

book[i].author

book[i].edition

book[i].year

book[i].quantity.

ELSE

WHILE(inFile)

DISPLAY The text file is missing!

EXIT

inFile close
}

{
DISPLAY Book name
DISPLAY ISBN number
DISPLAY Author
DISPLAY Edition
DISPLAY Year
DISPLAY Quantity

FOR ( i = 1; i < num; i++)


{ DISPLAY book[i].book_name;
DISPLAY book[i].isbn_number;
DISPLAY book[i].author;
DISPLAY book[i].edition;
DISPLAY book[i].year;
DISPLAY book[i].quantity;
}
}

{
file_isbn_number, count = 0, alp = 0
character flag[10], isbn_number[50]
string str_isbn_number

DO

DISPLAY Please enter ISBN number of book


INPUT isbn_number

alp = checking_for_alphabet(isbn_number);

FOR (i = 0; i < num; i++)


{
str_isbn_number = book[i].isbn_number
IF (isbn_number == str_isbn_number)
{
DISPLAY Book name
DISPLAY ISBN number
DISPLAY Author
DISPLAY Edition
DISPLAY Year
DISPLAY Quantity

DISPLAY book[i].book_name
DISPLAY book[i].isbn_number
DISPLAY book[i].author
DISPLAY book[i].edition
DISPLAY book[i].year
DISPLAY book[i].quantity
}
}
IF (count = 0)
{

DISPLAY No record Found


}
count = 0
DISPLAY Do you wish to continue searching the book by using
ISBN number? (1-Yes, 0-No)
INPUT flag

WHILE (flag[0] =1 && flag[0] = 0 || strlen(flag) > 1)


{
DISPLAY Invalid Input. Please Try Again
DISPLAY Do you wish to continue searching the book by
using ISBN number? (1-Yes, 0-No)
INPUT flag
}

} WHILE (flag[0] = 1)
}

{
alp = 0;

FOR ( i = 0; i < strlen(book); i++)


{
IF(isalpha(book[i]))

}
}

Book_Data temp[50]
string keyword
count = 0;
char flag[10];

DO
{
DISPLAY Enter the first keyword that you wish to find
INPUT Keyword

transform(keyword.begin(), keyword.end(), keyword.begin(), tolower)

DISPLAY Book name


DISPLAY ISBN number
DISPLAY Author
DISPLAY Edition
DISPLAY Year
DISPLAY Quantity

FOR (i = 0; i < num; i++)


{
temp[i].book_name.resize(book[i].book_name.size());

temp[i].isbn_number.resize(book[i].isbn_number.size());

temp[i].author.resize(book[i].author.size());

temp[i].edition.resize(book[i].edition.size());

temp[i].year.resize(book[i].year.size());

temp[i].quantity.resize(book[i].quantity.size());

IF (((temp[i].book_name.find(keyword) != string::npos)
(temp[i].isbn_number.find(keyword) != string::npos)
(temp[i].author.find(keyword) != string::npos)
(temp[i].edition.find(keyword) != string::npos)
(temp[i].year.find(keyword) != string::npos)
(temp[i].quantity.find(keyword) != string::npos)))

{
DISPLAY book[i].book_name;
DISPLAY book[i].isbn_number;
DISPLAY book[i].author;
DISPLAY book[i].edition;
DISPLAY book[i].year;
DISPLAY book[i].quantity
}
}
; IF (count = 0)
{
DISPLAY No record found !
}

count = 0

DISPLAY Do you wish to continue searching any keyword from the text
file? (1-Yes, 0-No)
INPUT flag

WHILE (flag[0] = 1 && flag[0] = 0 || strlen(flag) > 1)


{

DISPLAY Invalid Input. Please Try Again: \n";


DISPLAY Do you wish to continue searching any keyword from
the text file? (1-Yes, 0-No)

INPUT flag
}

} WHILE (flag[0] = 1)
}

{
string str_quantity
file_quantity
count = 0

DISPLAY Book name


DISPLAY ISBN number
DISPLAY Author
DISPLAY Edition
DISPLAY Year
DISPLAY Quantity

FOR (i = 1; i < num; i++)


{
str_quantity = book[i].quantity;

IF (file_quantity<10)
{
DISPLAY book[i].book_name
DISPLAY book[i].isbn_number
DISPLAY book[i].author
DISPLAY book[i].edition
DISPLAY book[i].year
DISPLAY book[i].quantity
}
}

IF (count = 0)
{
DISPLAY No records found!
}
}

{
string book_name;
character flag[3]
string answer
bool update = false

DO
{
DISPLAY Do you really want to update book?(1-Yes, 0-No)
INPUT flag

WHILE (flag[0] = ' && flag[0] = 0 || strlen(flag) > 1)


{
DISPLAY Invalid Input. Please Try Again
DISPLAY Do you really want to update book?(1-Yes, 0-No)

INPUT flag
}
IF (flag[0] =1)
{

DISPLAY Enter the book name you wish to update


INPUT book_name
for ( i = 0; i < num; i++)
{
if (book_name == book[i].book_name)
{
DISPLAY Please key in the new data for the book

DISPLAY ISBN number:


INPUT book[i].isbn_number

DISPLAY Author of the book


INPUT book[i].author

DISPLAY Edition of the book


INPUT book[i].edition

DISPLAY Year of the book


INPUT book[i].year

DISPLAY Quantity
INPUT book[i].quantity

update = true
}
}
if (update = true)
{

outFile(bookstore.txt)
FOR ( i = 0; i < num; i++)
{
outFile book[i].book_name
book[i].isbn_number
book[i].author
book[i].edition
book[i].year
book[i].quantity
}
DISPLAY Updated successfully !
outFile close

ELSE
{

DISPLAY No record found!


update = false }
}

} while (flag[0] = 1)

{
Book_Data new_data
new_book
character flag[10]

DO
{
DISPLAY Do you really want to add any book?(1-Yes, 0-No)
INPUT flag

WHILE (flag[0] = 1 && flag[0] = 0|| strlen(flag) > 1)


{

DISPLAY Invalid Input. Please Try Again


DISPLAY Do you really want to add any book?(1-Yes, 0-No)
INPUT flag
}
IF (flag[0] = 1)
{
book += 1
new_book = book;

DISPLAY Enter the book name


INPUT new_data.book_name

DISPLAY Enter the ISBN Number


INPUT new_data.isbn_number
DISPLAY Enter the Author
INPUT new_data.author

DISPLAY Enter the Edittion


INPUT new_data.edition

DISPLAY Enter the Year


INPUT new_data.year

DISPLAY Enter the Quantity


INPUT new_data.quantity

ofstream outFile
outFile open(bookstore.txt)

outFile new_data.book_name
new_data.isbn_number
new_data.author
new_data.edition
new_data.year
new_data.quantity

DISPLAY Added successfully !

DISPLAY Book name


DISPLAY ISBN number
DISPLAY Author
DISPLAY Edition
DISPLAY Year
DISPLAY Quantity

DISPLAY new_data.book_name
DISPLAY new_data.isbn_number;
DISPLAY new_data.author;
DISPLAY new_data.edition;
DISPLAY new_data.year;
DISPLAY new_data.quantity;

outFile close

}
ELSE

DISPLAY Redirecting back to main menu

} WHILE (flag[0] = 1);


}

{
string isbn_number;
bool delete_option = false
count = 0;
character flag[10]

DO
{
ofstream (temp.txt)

DISPLAY Do you really want to delete any book?(1-Yes, 0-No)


INPUT flag

while (flag[0] = 1 && flag[0] = 0 || strlen(flag) > 1)


{
DISPLAY Invalid Input. Please Try Again
DISPLAY Do you really want to delete any book?(1-Yes, 0-No)
INPUT flag
}
if (flag[0] == '1')
{

DISPLAY Enter the ISBN number that you wish to delete


INPUT isbn_number

FOR (i = 0; i < num; i++)


{
IF (isbn_number = book[i].isbn_number)
{
temp book[i].book_name
temp book[i].isbn_number
temp book[i].author
temp book[i].edition
temp book[i].year
temp book[i].quantity
}
ELSE
{
delete_option = true;
}
}

temp close
remove (bookstore2.txt)
rename (bookstore.txt, bookstore2.txt)
rename (temp.txt, bookstore.txt)

IF (delete_option = false)
{
DISPLAY The isbn number is not found!
}
else
{
DISPLAY The isbn number is deleted!
ifstream inFile(bookstore.txt)

IF (inFile)
{
DISPLAY Error opening input file
EXIT
}
ELSE
{
i = 0;

WHILE getline(inFile)
{

book[i].book_name = data;

book[i].isbn_number = data;

book[i].author = data;
book[i].edition = data;

book[i].year = data;

book[i].quantity = data;

inFile close
}
}
}

delete_option = false

} while (flag[0] = 1)

{
DISPLAY THANK YOU
DISPLAY **EXITING THE PROGRAM**

EXIT
}

You might also like