Sign in to follow this  

Visual C++ records

This topic is 3629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What I'm looking for is a sample of how to keep track of records. And save them to a file. So that I can, add,edit,delete, and search threw the records. I been doing some searching on google. just haven't fount any thing that I'm looking for I did find some address book samples. Its just that they have limits of 5 or less and they write to more then one file.

Share this post


Link to post
Share on other sites
You simply need to define some format that you can easily parse from a file. This might be something as simple as a tab- or comma-delimited list or something more complex such as a hierarchical structure (eg xml) or some custom block format.

To store an arbitrary amount of records, look into std::vector, std::multi_set or std::multi_map where the primary identifying field (say, last name) is used as the sorting key.

You could also use a hierarchy of these containers to allow, for example, an arbitrary number of addresses or phone numbers on a person-by-person basis.

Share this post


Link to post
Share on other sites
ravyne2001 has the right information, but I figured I might as well throw an example out there:


#include <stream>
#include <string>
#include <vector>

struct Record
{
int id;
std::string name;
int zip;
std::string address;
};

std::vector<Record> records;

void SaveRecords( std::string fileName )
{
std::ofstream out( fileName.c_str() );

for( int i = 0; i < records.Count; i++ )
{
Record record = records.at( i );

out << record.id;
out << record.name;
out << record.zip;
out << record.address;
}
}

void LoadRecords( std::string fileName )
{
std::ifstream in( fileName.c_str() );

while( !in.eof() )
{
Record record;

in >> record.id;
in >> record.name;
in >> record.zip;
in >> record.address;

records.push_back( record );
}
}



Note: It's been a long time since I've used C++ and STL. If I mucked something up, let me know.

Share this post


Link to post
Share on other sites
Mike's example is the most basic form (essentially a return-delimited list) which works well with stream behavior, so its an excellent starting point for you.

Unfortunately, its not terribly extensible and the file (should you ever need to read it with an external program) is just a great big dumb list. If you were to add or remove a line, you might suddenly have "people" whose names are addresses, addresses are phone numbers, and phone numbers are the names of other people.

Again, its a great starting point and may meet your needs, but its not robust (just like any delimited-list style approach) which has no reliable implicit or explicit type information.

Share this post


Link to post
Share on other sites
Adding to what the others said here is another couple of options.
If you don't want to load all the records into memory at once but read/edit/write one at a time from file, you could use a hashing function.
Advantages of using hashing:

1. Finding the position and reading a record from file is fast (constant time)
2. You don't need to load more than one record from the file into memory.

Limitations:

1. Each record must have a unique key used to calculate the records position in the file. Without knowing the key you won't be able to retrieve the record.
2. The max number of records must be known from the start.

Examples of such a key could be a string containing a bank account number, or a string containing firstname, lastname and street address concatenated together.

If your record has a fixed size, implementing this scheme is quite easy. The hashing function used to calculate the file position could look something like this (taken from Data Structures & Algorithm Analysis in C++ by Mark Allen Weiss):

unsigned long hash(const string& key, unsigned long maxRecordsTimesTwo)
{
unsigned long hashVal = 0;

for(int i = 0; i < key.length(); i++)
hashVal = 37 * hashVal + key[ i ];

hashVal %= maxRecordsTimesTwo;

return hashVal * sizeof(RECORD);
}

Note that the maxRecordsTimesTwo should be at least twice as big as maxRecords to reduce the chance of generating the same position twice.
In other words, there is a chance that hashing algorithms like this will generate the same position based on two different keys!, even though this chance is supprisingly low as long as maxRecordsTimesTwo is big enough and the key contains *random* items.

Depending on the records and application, there is a good chance that the best choice is to use a database like sqlite. If searching among the records and record entries is a biggie, its hard to beat a SQL database.

edit:
Modified the hashing algorithm to align hashVal to recordSizes

[Edited by - pulpfist on January 4, 2008 3:19:12 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike.Popoloski
ravyne2001 has the right information, but I figured I might as well throw an example out there:

*** Source Snippet Removed ***

Note: It's been a long time since I've used C++ and STL. If I mucked something up, let me know.


Mike, thanks for the sample. Any chance I can talk you in to adding the rest of it. I been playing with some options and well as all ways having a hard time with it.

Ask for the input, Name address and so on.

Then display the records back;

Oh, and before I forget you don't need to add the std. I use using namespace std; at the top of my project.

And I do have a menu system setup in my project


Share this post


Link to post
Share on other sites
For a small exercise program, saving to a file is fine. For large amounts of data and modifications, a database would be a more suitable approach. SQLite comes to mind, being a small and light-weight database engine. It still uses files under the hood, but you don't have to worry about that, because SQLite takes care of that, and you get to play with a high-level interface that allows easy adding, modification and searching.

Not that SQLite is the only solution for situations like this, and perhaps it's overkill for your situation, but I thought it wouldn't hurt to make you aware of other approaches. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Captain P
For a small exercise program, saving to a file is fine. For large amounts of data and modifications, a database would be a more suitable approach. SQLite comes to mind, being a small and light-weight database engine. It still uses files under the hood, but you don't have to worry about that, because SQLite takes care of that, and you get to play with a high-level interface that allows easy adding, modification and searching.

Not that SQLite is the only solution for situations like this, and perhaps it's overkill for your situation, but I thought it wouldn't hurt to make you aware of other approaches. :)


Captain P. Thanks. I'll have to look in to that. One question. How hard is it to install and can you give me a sample of the code. Just make it simple

Joe

Share this post


Link to post
Share on other sites
Quote:
Original post by Mike.Popoloski
ravyne2001 has the right information, but I figured I might as well throw an example out there:

*** Source Snippet Removed ***

Note: It's been a long time since I've used C++ and STL. If I mucked something up, let me know.


Mike, I spent some time playing with it. Is this right.
************************************************************

void add() {
char ch;

system("cls");
cout<<"Person Information required"<< endl;
cout<<"*******************************************\n";

cout<<"Your Name ";
cin >> record.name;

cout<<"Your Address : ";
cin >> record.address;

cout<<"Your Zip Code : ";
cin >> record.address;

cout<<" Is this Correct Y/N : "; // This doesn't work
cin >> ch;
if (ch == 'n') goto stop;

SaveRecords("records.dat");

stop:
;} // Ends add()
******************************************************

void SaveRecords( string fileName )
{
ofstream out( filename.c_str() );

for( int i = 0; i < records.Count; i++ )
{
Record record = records.at( i );

out << record.id;
out << record.name;
out << record.zip;
out << record.address;
}
}

Thanks

Joe


Share this post


Link to post
Share on other sites
Joe, when you add the record, create the new record object, fill it with data, and then add it to the vector to store it. Also, I always put "std::" before the appropriate objects instead of "using namespace std;" for several different reasons, the main one being that it keeps the namespaces clean and separate.

I will show you a cleaned up version of the code, which appends the new record to the file instead of saving them all at once.


void add()
{
Record record;
char ch;

system( "cls" );

cout << "Person Information required" << endl;
cout << "*******************************************\n";

cout << "Your Name ";
cin >> record.name;

cout << "Your Address : ";
cin >> record.address;

cout<<"Your Zip Code : ";
cin >> record.address;

cout <<" Is this Correct Y/N : ";
cin >> ch;

if( ch == 'n' || ch == 'N' )
return;

SaveRecord( record, "records.dat" );
}

void SaveRecord( const Record &record, std::string fileName )
{
std::ofstream out( fileName.c_str(), std::ios_base::app );

out << record.id;
out << record.name;
out << record.zip;
out << record.address;
}

Share this post


Link to post
Share on other sites
Its fine to ask for direction and help, but its generally frowned upon to ask people to provide you with complete solutions. Not only that, but its also usually a sign that you're trying to grasp further than your reach. In other words, if you have to ask someone to do it all for you, you're not ready to be doing it in the first place.

There's also some concern over those who come here asking for solutions to homework assignments, and a policy against providing solutions when that scenario is apparent. Forum goers are typically weary of providing complete solutions due to the possibility of a poster lying about whether it is homework or not.

Share this post


Link to post
Share on other sites
Quote:
Original post by ravyne2001
Its fine to ask for direction and help, but its generally frowned upon to ask people to provide you with complete solutions. Not only that, but its also usually a sign that you're trying to grasp further than your reach. In other words, if you have to ask someone to do it all for you, you're not ready to be doing it in the first place.

There's also some concern over those who come here asking for solutions to homework assignments, and a policy against providing solutions when that scenario is apparent. Forum goers are typically weary of providing complete solutions due to the possibility of a poster lying about whether it is homework or not.


ravyne, Sorry theres nothing I can do about that problem. If kids want to cheat then theres nothing you or I can do.

The only reason I'm here is to learn C++., Mike sample doesn't work. any way. I getting more errors then before. It telling me that a missing ; is needed and the demo I saw didn't say to put one there. Where Mike didn't put them it's telling me to add one there. So right now I don't know what to do. I'm 48 Years old and disabled. I have nothing else to do.





Share this post


Link to post
Share on other sites
Apologies for the assumption then. We don't get many 48 year olds who are here to learn C++, usually the one's we deal with that are new to programming here are 12 year olds who discovered this site, then jump way too far ahead of themselves because they suddenly think they can write the next big MMO, when they should be learning for loops.

Anyhow, Mike did update his sample while I was making the last post, so hopefully that has helped.

If you'd like some good, free, online resources I can recommend Thinking in C++ and Thinking in Patterns by Bruce Eckel who is one of the foremost authors on C++ and programming. Both come with PDF and Source code, and a list of download mirrors is here!

Share this post


Link to post
Share on other sites
Quote:
Original post by ravyne2001
Apologies for the assumption then. We don't get many 48 year olds who are here to learn C++, usually the one's we deal with that are new to programming here are 12 year olds who discovered this site, then jump way too far ahead of themselves because they suddenly think they can write the next big MMO, when they should be learning for loops.

Anyhow, Mike did update his sample while I was making the last post, so hopefully that has helped.

If you'd like some good, free, online resources I can recommend Thinking in C++ and Thinking in Patterns by Bruce Eckel who is one of the foremost authors on C++ and programming. Both come with PDF and Source code, and a list of download mirrors is here!


Well I sorry, too. I guess I'm just getting too old. any way like I said I all ready tried mike's update one and well it's giving me all kinds of errors. Right now at this time I have no idea what to do.

Any way I downloaded some of the tutorials and well I just don't under stand them. I wish I had a tutor.

Share this post


Link to post
Share on other sites
Here is a slightly different example of a phone book skeleton.
There is still a lot more to do, and its not the most efficient phone book on the planet, in particular:
-There is other data structures better suited for searching than the vector.
-It will not allow you to use multiple words in names and addresses.
-Its case sensitive.
-There is no edit function. Its quite easy to write it though. Pretty much the same as the findEntry function, except rather than printing the items in the entry one would modify them based on user input


#include <vector>
#include <string>
#include <sstream> // stringstream
#include <fstream> // ifstream, ofstream
#include <iostream>
#include <cstdlib> // system
using namespace std;

struct Entry // The record struct
{
string name, address, phone;
};

vector<Entry> book; // The phone book

// This function will create a new entry based on user input and add it to the phone book
void createEntry()
{
Entry entry;

cout << "Name: ";
getline(cin, entry.name);
cout << "Address: ";
getline(cin, entry.address);
cout << "Phone: ";
getline(cin, entry.phone);

book.push_back(entry);
}

// Function to find and delete an entry in the book
void deleteEntry()
{
string name;

cout << "Name to delete: ";
getline(cin, name);

for(vector<Entry>::iterator i = book.begin(); i != book.end(); i++)
{
if(i->name == name)
{
book.erase(i);
break;
}
}
}

// Function to find and display an entry
void findEntry()
{
string name;

cout << "Name to find: ";
getline(cin, name);

for(vector<Entry>::iterator i = book.begin(); i != book.end(); i++)
{
if(i->name == name)
{
cout << "Name: " << i->name << " Address: " << i->address << " Phone: " << i->phone << endl;
break;
}
}
}

// Function to list all entries in the phone book
void listBook()
{
for(vector<Entry>::iterator i = book.begin(); i != book.end(); i++)
cout << i->name << " " << i->address << " " << i->phone << endl;
}

// Function to load entries from file into the phone book
void loadBook()
{
string line; // working string
Entry entry; // working entry

ifstream fin("phonebook.txt");
if(fin.is_open()) // if file exists...
{
while(fin.good()) // loop until error or end of file...
{
getline(fin, line); // get next line from file
stringstream ss(line); // fill a stringstream with the line
ss >> entry.name >> entry.address >> entry.phone; // parse the line into the working entry
book.push_back(entry); // store the entry in the book
}
}
}

// Function to store entries from the phone book into file
void saveBook()
{
ofstream fout("phonebook.txt");

// Iterate through each entry in the book and save it on a single line
for(vector<Entry>::iterator i = book.begin(); i != book.end(); i++)
fout << i->name << " " << i->address << " " << i->phone << endl;
}

int main()
{
string input; // working string

loadBook(); // Load the phone book at startup...

while(1) // loop forever...
{
system("cls");

cout << "Commands: create, delete, find, list, quit" << endl;
getline(cin, input);

// Execute our functions based on what command the user typed
if(input == "quit")
break; // break out of the loop and quit program
else if(input == "create")
createEntry();
else if(input == "delete")
deleteEntry();
else if(input == "find")
findEntry();
else if(input == "list")
listBook();
else cout << "Unknown command" << endl;

system("pause");
}

saveBook(); // Store the current phone book to file before we exit

return 0;
}






edit:
Each entry is represented in the file by a single line, and each item on that line is separated by a whitespace. However, I noticed a bug, since each line written to file ends with a newline, the code above will read one line at the end containing only a newline, resulting in an extra entry being added to the book.
Here is a dirty fix:

...
// Function to load entries from file into the phone book
void loadBook()
{
string line; // working string
Entry entry; // working entry

ifstream fin("phonebook.txt");
if(fin.is_open()) // if file exists...
{
while(!fin.eof()) // loop until end of file...
{
getline(fin, line); // get next line from file
if(line.length() < 2) // dirty fix to skip the last newline
break;
stringstream ss(line); // fill a stringstream with the line
ss >> entry.name >> entry.address >> entry.phone; // parse the line into the working entry
book.push_back(entry); // store the entry in the book
}
}
}
...





[Edited by - pulpfist on January 5, 2008 4:00:40 AM]

Share this post


Link to post
Share on other sites
By changing loadBook and saveBook slightly it will work with multiple words.
The separators in the file is now a : rather than whitespace

// Function to load entries from file into the phone book
void loadBook()
{
char cbuf[128];
string line; // working string
Entry entry; // working entry

ifstream fin("phonebook.txt");
if(fin.is_open()) // if file exists...
{
while(!fin.eof()) // loop until error or end of file...
{
getline(fin, line); // get next line from file
if(line.length() < 2) // dirty fix to skip the last newline
break;
stringstream ss(line);

// extract three items from the stream separated by :
ss.getline(cbuf, 128, ':');
entry.name = cbuf;

ss.getline(cbuf, 128, ':');
entry.address = cbuf;

ss.getline(cbuf, 128, '\n');
entry.phone = cbuf;

book.push_back(entry); // store the entry in the book
}
}
}

// Function to store entries from the phone book into file
void saveBook()
{
ofstream fout("phonebook.txt");

// Iterate through each entry in the book
for(vector<Entry>::iterator i = book.begin(); i != book.end(); i++)
fout << i->name << ':' << i->address << ':' << i->phone << endl;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by pulpfist
By changing loadBook and saveBook slightly it will work with multiple words.
The separators in the file is now a : rather than whitespace
*** Source Snippet Removed ***


Any way I tried your sample and well I'm getting errors on your sample too.

Heres a list of the errors

c:\documents and settings\joe\my documents\visual studio 2008\projects\phone book\phone book\phone book.cpp(135) : error C2084: function 'void loadBook(void)' already has a body
c:\documents and settings\joe\my documents\visual studio 2008\projects\phone book\phone book\phone book.cpp(71) : see previous definition of 'loadBook'
c:\documents and settings\joe\my documents\visual studio 2008\projects\phone book\phone book\phone book.cpp(187) : error C2084: function 'void saveBook(void)' already has a body
c:\documents and settings\joe\my documents\visual studio 2008\projects\phone book\phone book\phone book.cpp(90) : see previous definition of 'saveBook'
Build log was saved at "file://c:\Documents and Settings\Joe\My Documents\Visual Studio 2008\Projects\Phone Book\Phone Book\Debug\BuildLog.htm"
Phone Book - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I don't get any of this. I was hoping it would be easy to write program in C++ and I guess not. Until I can get it to work. Then I can take time out to study the lines and find out what each line does and how it works


Share this post


Link to post
Share on other sites
Oh yea the first code example is the complete source.
The next two is just newer versions of the loadBook and saveBook functions.
Try to compile the first example first. If that works you can replace the loadBook and saveBook functions with those in the last code example.

Programming C++ is not exactly easy. I did a lot of hair pulling myself the first years =)

Share this post


Link to post
Share on other sites
Quote:
Original post by pulpfist
Oh yea the first code example is the complete source.
The next two is just newer versions of the loadBook and saveBook functions.
Try to compile the first example first. If that works you can replace the loadBook and saveBook functions with those in the last code example.

Programming C++ is not exactly easy. I did a lot of hair pulling myself the first years =)


Cool, That works. Thanks. Now I have some reading to do. some questions. Your ample doesn't required an record ID. Like the others were saying. Can I ask why you didn't add one. Or is there some thing else that I missed.

Some of the other members have been trying to help me add some colors to my work. Like adding colors to my prompts and so on.
This is what I was told to use. I just have no idea on how to use it.
They all tried to help witha gotoXY() command. and I can that to work too

void gotoxy(SHORT X, SHORT Y)
{
COORD position = {X, Y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position);
}

// Change cursor position to overwrite some of the previous text
COORD cursorPosition;
cursorPosition.X = 9;
cursorPosition.Y = 0;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cursorPosition);
std::cout << " Overwriting text..." << std::endl;

//Change text to base colours
WORD textAttribute = FOREGROUND_RED;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), textAttribute);
std::cout << "Red! ";

textAttribute = FOREGROUND_BLUE;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), textAttribute);
std::cout << "Blue! ";

textAttribute = FOREGROUND_GREEN;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), textAttribute);
std::cout << "Green! ";

// Text can be made into other colours by combining the base colours
textAttribute = FOREGROUND_BLUE | FOREGROUND_GREEN;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), textAttribute);
std::cout << "Cyan!" << std::endl;
}


Any ideas form you would be great and again thanks for your sample.

Share this post


Link to post
Share on other sites
Quote:

Your ample doesn't required an record ID. Like the others were saying. Can I ask why you didn't add one. Or is there some thing else that I missed.

Well I didn't see any need for it in a simple phone book like this, and as everything else in programming, if you don't use it, skip it.

The gotoxy function looks ok. You can use it anywhere in your code to position the cursor. Printing of text will continue from there as normal. Note that the X and Y arguments represent rows and columns, not pixels.

Its pretty much the same with colors. You can change the text color anywhere in the code like this:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);

From then on the text will be green.
Personally I think the colors is a bit dark so I usually add some intensity to them:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);


The functions used to change colors and cursor position is part of the windows console functions more info on those
Note that you will have to include the windows header at the top of your code to use these functions.

#include <windows.h>


Quote:

Any ideas form you would be great and again thanks for your sample.

Your welcome

Share this post


Link to post
Share on other sites
[quote]Original post by pulpfist
Quote:

Your ample doesn't required an record ID. Like the others were saying. Can I ask why you didn't add one. Or is there some thing else that I missed.

Well I didn't see any need for it in a simple phone book like this, and as everything else in programming, if you don't use it, skip it.

Ok, Thats find. I thought it was required

Quote:

The gotoxy function looks ok. You can use it anywhere in your code to position the cursor. Printing of text will continue from there as normal. Note that the X and Y arguments represent rows and columns, not pixels.


Ok, any way no. sorry that not what I was trying to say. I mean is that I can't get it to work. All I get is errors. If you wanted a list of the errors. I can paste then for you.

Quote:

Its pretty much the same with colors. You can change the text color anywhere in the code like this:[code]
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
From then on the text will be green.
Personally I think the colors is a bit dark so I usually add some intensity to them:[code]
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);

The functions used to change colors and cursor position is part of the windows console functions more info on those
Note that you will have to include the windows header at the top of your code to use these functions.

#include <windows.h>




Ok. I keep for getting that I have to state just what I want. How about an easy way to add colors.

instead of this line
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);

how about using some thing like this
TextColor(#) // The # refers to a number of the color.
TextBackGround(#) // same as above

It would be hard for me to remember a line that long and it would make a mess of things.





Share this post


Link to post
Share on other sites
Quote:

Ok, Thats find. I thought it was required

Its all up to you really. You are the one putting the stakes here.

If you look at the deleteEntry function you will see that it iterates through the book and deletes the first entry it finds that matches the name and bails out after that. So the questions arises; what if there are more entries with the same name? Should they be deleted? Did we intend to delete the last entry and not the first?
When trying to solve these issues, having a unique ID for each entry could come in handy.

While I'm at it, the findEntry function has a break statement in the loop that will make it bail out after finding an entry. This was a bad idea. If we simply remove the break statement it will continue to list more entries that matches the name.


Quote:

All I get is errors. If you wanted a list of the errors. I can paste then for you.

Yes always do that. Thats the best way to get answers around here =)


Quote:

Ok. I keep for getting that I have to state just what I want. How about an easy way to add colors.

instead of this line
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);

how about using some thing like this
TextColor(#) // The # refers to a number of the color.
TextBackGround(#) // same as above

Well Microsoft decided that it should look like this
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN);
However, C++ has a lot of ways for us to make shortcuts ourself.

You could for example make a wrapper function at the top of your code somewhere
void TextColor(short color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}

From then on you could change the color like this
TextColor(FOREGROUND_GREEN);

It turns out that FOREGROUND_GREEN is a synonym for a number.
You can try replacing it with a number and see what color you get, eg.
TextColor(5); should work.



I did write an overloaded operator once to make switching between colors easy with the cout object.
It looks like this:

First we create a new data type to represent the colors

enum ConsoleColor
{
fgGreen = FOREGROUND_GREEN,
fgRed = FOREGROUND_RED
// more colors...
};


Then we overload the << operator for our new data type

ostream& operator << (ostream& out, ConsoleColor& color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
return out;
}


Now, we can switch colors *on the fly* like this
cout << fgGreen << "This line is green " << fgRed << "This line is red" << endl;


Just a funny little thing =)

Anyway, the bottom line is that we can make wrapper functions or macros to make things easier, but we can't avoid using the SetConsoleTextAttribute function all together. At least not that I know of.

Share this post


Link to post
Share on other sites
[quote]Original post by pulpfist
Quote:

Ok, Thats find. I thought it was required

Its all up to you really. You are the one putting the stakes here.

If you look at the deleteEntry function you will see that it iterates through the book and deletes the first entry it finds that matches the name and bails out after that. So the questions arises; what if there are more entries with the same name? Should they be deleted? Did we intend to delete the last entry and not the first?
When trying to solve these issues, having a unique ID for each entry could come in handy.

While I'm at it, the findEntry function has a break statement in the loop that will make it bail out after finding an entry. This was a bad idea. If we simply remove the break statement it will continue to list more entries that matches the name.


Ok, I will. any if it's a option to have records setup with an id number that would be ok. When ever you have time.

Any way I wanted to tell you that your color idea works like a charm.
TextColor(15); // = High while.

Oh, and I took out an line that I wasn't using and gotoxy(x,y) works great.
Now my menu looks better.

Any way, Thanks again. I owe you one. and now to move things a long.

Does C++ support Random access files too. I have done programing in pascal. I have all ways like that option.


Look, If theres any thing I can do for you. Let me know. I have a web site and run a BBS too. I guess thats why I want to learn C++. To Replace the BBS software I'm running now. With my Own project.

http://topersbbs.dtdns.net
telnet://topersbbs.dtdns.net





Share this post


Link to post
Share on other sites
Quote:

Does C++ support Random access files too. I have done programing in pascal. I have all ways like that option.

I see. I never used pascal myself.
I'm not 100% sure I know what random access is but I think C++ has it.
Basically you can save anything anywhere in a file. No need to use records or IDs or anything like that. You decide how to organize data in the files.

Quote:

Look, If theres any thing I can do for you. Let me know. I have a web site and run a BBS too. I guess thats why I want to learn C++. To Replace the BBS software I'm running now. With my Own project.

Thanks mate, and good luck with the project :D

Share this post


Link to post
Share on other sites

This topic is 3629 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this