I
ianenis.tiryaki
well i got this assignment which i dont even have a clue what i am
supposed to do. it is about reading me data from the file and load
them into a parallel array here is the question:
Step (1)
Your first task is to write a program which reads this file into two
parallel arrays in memory. One array contains the titles, and the
other array contains the authors. The arrays are 'parallel' in the
sense that the n-th element of the authors array contains the authors
associated with the n-th element of the titles array. Although the
data in the test file describes only a few books you should dimension
your arrays for an arbitrary number of books in the live data file
(which may be different from the test file). The size of the arrays
should be defined in your program by the declaration const int
ARRAY_SIZE = 1000.
For the purpose of this assignment (so as not to make it too
complicated) you should declare your two arrays at file scope (i.e.
outside any function and before the function main()). The declarations
should be as follows:
string bookTitle [ARRAY_SIZE];
string bookAuthor [ARRAY_SIZE];
Write a function whose signature is as follows:
int loadData (string pathname)
The function loadData should open the data file located in the path on
your hard disk specified by pathname. If it cannot open the file for
some reason, it should return a value of -1 as an error result.
Otherwise it should read the data in the file into the two parallel
arrays, and return the number of book records that it read.
Now write a function whose signature is as follows:
void showAll (int count)
The parameter count provides the number of books actually stored in
the database (i.e the value returned by the function loadData()).
showAll() should read the designated number of records in the parallel
arrays and display it on the screen in the order it appears in the
database, in single column format as follows (using the data in the
example file):
Objects First with Java (Barnes and Kolling)
Game Development Essentials (Novak)
The Game Maker's Apprentice (Overmars)
C++ Programming: From Problem Analysis... (Malik)
....
....
Audio for Games (Brandon)
Now test your work so far, by writing a main() function to prompt the
user for the path to the data file, open and read the file to the
parallel arrays using the function loadData() (providing error
messages and recovery as appropriate if the file doesn't exist). Then
display the contents of the file using showAll().
Step (2)
Extend your program into a menu driven application to query the
database. When the program starts it should ask the user for the path
to the data file, and read the data into the parallel arrays, as in
step 1.
Then it should enter a loop, in each iteration of which it prompts the
user for what they want to do. The actions are as follows depending on
how the user responds to the prompt. See the sample dialog below to
see how this works in practice.
Q or q: Quit. The program terminates.
A or a: Search by Author. The program displays all records which
contain the designated text somewhere in the author field. You should
use a function with the following signature for this purpose: int
showBooksByAuthor (int count, string name). This function should
display all books whose author field contains the string passed in the
parameter called name. It returns the number of books displayed. count
specifies the number of books in the database.
T or t: Search by Title. The program displays all records which
contain the designated text somewhere in the title field. You should
use a function with the following signature for this purpose: int
showBooksByTitle (int count, string title). This function should
display all books whose title field contains the string passed in the
parameter called title. It returns the number of books displayed.
count specifies the number of books in the database.
Sample Dialog
Note: In the example below, the user's input is in BOLD. The program
output is not.
Welcome to Colin's Library Database.
Please enter the name of the backup file: C:\library.txt
14 records loaded successfully.
Enter Q to Quit, A to search by Author, T to search by Title: A
Author's Name: Malik
C++ Programming: From Problem Analysis... (Malik)
C++ Programming: Program Design Including... (D. S. Malik)
2 records found.
Enter Q to Quit, A to search by Author, T to search by Title: A
Author's Name: Goble
0 records found.
Enter Q to Quit, A to search by Author, T to search by Title: T
Title: Game
Game Development Essentials (Novak)
The Game Maker's Apprentice (Overmars)
Game Character Development with Maya (Ward)
Developing Games in Java (Brackeen)
Audio for Games (Brandon)
5 records found.
Enter Q to Quit, A to search by Author, T to search by Title: Q
supposed to do. it is about reading me data from the file and load
them into a parallel array here is the question:
Step (1)
Your first task is to write a program which reads this file into two
parallel arrays in memory. One array contains the titles, and the
other array contains the authors. The arrays are 'parallel' in the
sense that the n-th element of the authors array contains the authors
associated with the n-th element of the titles array. Although the
data in the test file describes only a few books you should dimension
your arrays for an arbitrary number of books in the live data file
(which may be different from the test file). The size of the arrays
should be defined in your program by the declaration const int
ARRAY_SIZE = 1000.
For the purpose of this assignment (so as not to make it too
complicated) you should declare your two arrays at file scope (i.e.
outside any function and before the function main()). The declarations
should be as follows:
string bookTitle [ARRAY_SIZE];
string bookAuthor [ARRAY_SIZE];
Write a function whose signature is as follows:
int loadData (string pathname)
The function loadData should open the data file located in the path on
your hard disk specified by pathname. If it cannot open the file for
some reason, it should return a value of -1 as an error result.
Otherwise it should read the data in the file into the two parallel
arrays, and return the number of book records that it read.
Now write a function whose signature is as follows:
void showAll (int count)
The parameter count provides the number of books actually stored in
the database (i.e the value returned by the function loadData()).
showAll() should read the designated number of records in the parallel
arrays and display it on the screen in the order it appears in the
database, in single column format as follows (using the data in the
example file):
Objects First with Java (Barnes and Kolling)
Game Development Essentials (Novak)
The Game Maker's Apprentice (Overmars)
C++ Programming: From Problem Analysis... (Malik)
....
....
Audio for Games (Brandon)
Now test your work so far, by writing a main() function to prompt the
user for the path to the data file, open and read the file to the
parallel arrays using the function loadData() (providing error
messages and recovery as appropriate if the file doesn't exist). Then
display the contents of the file using showAll().
Step (2)
Extend your program into a menu driven application to query the
database. When the program starts it should ask the user for the path
to the data file, and read the data into the parallel arrays, as in
step 1.
Then it should enter a loop, in each iteration of which it prompts the
user for what they want to do. The actions are as follows depending on
how the user responds to the prompt. See the sample dialog below to
see how this works in practice.
Q or q: Quit. The program terminates.
A or a: Search by Author. The program displays all records which
contain the designated text somewhere in the author field. You should
use a function with the following signature for this purpose: int
showBooksByAuthor (int count, string name). This function should
display all books whose author field contains the string passed in the
parameter called name. It returns the number of books displayed. count
specifies the number of books in the database.
T or t: Search by Title. The program displays all records which
contain the designated text somewhere in the title field. You should
use a function with the following signature for this purpose: int
showBooksByTitle (int count, string title). This function should
display all books whose title field contains the string passed in the
parameter called title. It returns the number of books displayed.
count specifies the number of books in the database.
Sample Dialog
Note: In the example below, the user's input is in BOLD. The program
output is not.
Welcome to Colin's Library Database.
Please enter the name of the backup file: C:\library.txt
14 records loaded successfully.
Enter Q to Quit, A to search by Author, T to search by Title: A
Author's Name: Malik
C++ Programming: From Problem Analysis... (Malik)
C++ Programming: Program Design Including... (D. S. Malik)
2 records found.
Enter Q to Quit, A to search by Author, T to search by Title: A
Author's Name: Goble
0 records found.
Enter Q to Quit, A to search by Author, T to search by Title: T
Title: Game
Game Development Essentials (Novak)
The Game Maker's Apprentice (Overmars)
Game Character Development with Maya (Ward)
Developing Games in Java (Brackeen)
Audio for Games (Brandon)
5 records found.
Enter Q to Quit, A to search by Author, T to search by Title: Q