JT wrote:
i have do some....does it correct way to use it??
can show me next step ?
Coding:-
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
double ISDN ;
char title;
float price;
cout<<"---Welcome To Billy's Bookshop---\n";
cout<<"Please enter the ISDN: ";
cin>>ISDN;
if (ISDN==12)
{
cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM
108.90"<<endl;
}
if (ISDN==98)
{
cout<<"The Title is Introduction to Java Programming"<<endl<<"The
Price is RM 89.60"<<endl;
}
else
{
cout<<"Not Valid"<<endl;
}
return 0;
}
That is *not* what John suggested and his suggestion was a good one.
Start with writing down a data structure, which describes *one* book.
Forget the whole bookstore for the moment, just concentrate on *one* book.
struct Book
{
.... // use whatever data members you need to describe *one* book
};
Then write your first version of main(), which just allocates *one* book
int main()
{
Book TheBook( ..... ); // Initialize it. This depends entirely on the data structure
// you built up earlier
}
Then continue with operations you can already do now.
Eg. print out the complete description for *one* Book. In main() you
currently have *one* Book. Thus you can perfectly test your function:
struct Book
{
.... // use whatever data members you need to describe *one* book
};
void PrintBook( Book& book )
{
cout << ....... // do whatever you need to do to print
// out the description of *one* book that
// is passed to that function
}
int main()
{
Book TheBook( ..... ); // Initialize it. This depends entirely on the data structure
// you built up earlier
// now testing the print function
PrintBook( TheBook );
}
What else can you do with just *one* book? There would be various function
that could be written on just *one*, such as read and save from file. But
honestly I think you should takle the rest, before you even think of dealing
with files. So for now the answer is: nothing more.
OK. Now that everything that can be done with *one* book is finished, you should
think about how you would like to represent a collection of books. You could
use an array or a vector to store *multiple* books. So continue working in
this direction. Instead of *one* you want *multiple*. What to do with them?
Simple: You have a function that prints *one*, so it should be fairly easy
to enclose that function call in a loop and print all of them. This way
you can easily verify that your 'storage' works correctly. The books you
define in your program must be printed with the exact same information. If
it doesn't, you have a bug somewhere.
Only after that, you should start thinking about letting the user enter
a search phrase for a specific book. You then write a function which
loops through all the books and looks for that search string. If it is found,
you use eg. the already tested and working function 'PrintBook" to print out
its values.
So: Start simple and add more complicated things as you go along. Step back
and set some easy to reach goals. There is no point in starting to search
a database, when actually there is no database or you haven't verified that
your database actually works as expected. Otherwise you will never know where
a bug is located: Is it the database itself that is in error, is it the user
input or is the search code wrong?
--
Karl Heinz Buchegger
kb******@gascad.at