classes dont havta be in seperate files
classes dont havta be in seperate files
Which is better tho, i want this code well documented and easily readable, and i would think a few different cpp's would make this easier then just one.
Well, if you place them into separate .cpp files, you'll have to compile them separately, then link the .obj files when building the program. A good newbie way is to place the functions in separate header files, and just #include them with your program. Cheap and easy
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
so like this?
openfile.h
readfile.h
searchfile.h
So then how do i call the functions when i need them?Code:#include "openfile.h" #include "readfile.h" #include "searchfile.h"
In the header, just do:
char * GetBytes( const char filename[], int * num_bytes) {
//...code
}
Then in the main.cpp file:
int main() {
char * bytes;
int amount;
bytes = GetBytes("response.txt", &amount);
bytes[amount-1] = '\0';
//...code...
}
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Ok i'm sure that will make sense once i get going haha.
thnx
Okee... Well, from what I know, these are the main purposes of headers:
-For classes:
-put the class declaration (or whatever you call it) in (classname).h
-put the implementation (or whatever you call it) in (classname).cpp
i.e.
Code://this is classname.h class Classname { public: void changeData(int n); int getData(); protected: int data; }; //this is classname.cpp #include "classname.h" void Classname::changeData(int n) { data = n; } int Classname::getData() { return data; }
Then in main.cpp (or whatever you call it)
Another purpose is to stick related functions/macros together:Code:#include "classname.h" int main() { Classname myObject; myObject.changeData(5); cout << "myObject.data = " << myObject.getData(); return 0; }
The last (I think) reason for using separate headers is, of course, just to confuse people and make the code impossible to understand. As for how the multiple-cpp's work, look at the classes example ;) They're for if you have the function prototype in a header and the definition in a cpp file.Code://this is anglestuff.h #define PI 3.1415926535897932384626 #define DEGREES_TO_RADIANS(degrees) ((degrees) * (PI / 180)) #define RADIANS_TO_DEGREES(radians) ((radians) * (180 / PI)) float getRefAngle(float angle) { if(angle >= 0 && angle < 90) return angle; else if(angle < 180) return (180 - angle); else if(angle < 270) return (angle - 180); else return (360 - angle); }
**EDIT**
No, that is probably not a good idea :) Instead, you'd probably want to do this:#include "openfile.h"
#include "closefile.h"
#include "readfile.h"
Or, on the other hand, you could just do file i/o like normal people do it, and do the opening and stuff manually :PCode:#include "myfilestuff.h"
Last edited by Hunter2; 10-13-2002 at 01:53 PM.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
wow this thread is loaded....
ok hunt thnx for the help(?) lol.
No prob(?) lol.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
I have been thinking about how one could implement my previous idea. Here is what i have come with (scrawled on the back of a geography worksheet).
When the user asks a question, do the following:
change the case
filter out uneeded words and characters (articles, punctuation, etc.)
try to find a match.
If you find a match, feed back the related answer.
if you don't:
-counter it (as before described)
-write it into the file
-write the user's response to the file
reply.
To distinguish the questions from other statements and related words, questions could either have a separate file (questions.txt) or have a separate range of id's. The related answer(s) would have the same ID and probably be in a different file (answers.txt) or another section of the main file.
The bot should also randomly ask the user a question and record the feedback so the bot can fuel it's own answer-repository.
When the bot is parsing the input, the bot could have a list of names (which are added to every time the user logs in) that it replaces with %s for subject if it finds them.
Also, to make the conversation more interesting, the bot could have a long list of generic starements and replies that have a %o in then (for object) that it uses to keep the conversation going. This (along with a variable containing the object and some way to filter out the object of conversation) would make the bot seem more coherent and intelligent.
That's all for now,
~Inquirer
Compilers:
GCC on Red Hat 8.1 (Primary)
GCC on Mac OS X 10.2.4 (Secondary)
Others:
MinGW on XP
as much as i love your idea, i haven't even got past the opening of the file, the checking of the file for a match, the opening the reply file, and replying.
You haven't gotten past opening the file yet?? Psst... try #include <fstream> And then look into std::ifstream and std:fstream.
P.S.
I hope I'm not slighting your intelligence; if you already knew the stuff very well, feel free to ignore me
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
i'm mostly just putting the ideas out there for when i get around to making my own. I like getting my ideas out there to be chewed up, mixed around, and spat back out (pardon the metaphor) just to see if they get improved anyo or if it is possible or a waste of time, etc.
P.S. an O.K. tutorial on file opening and stiff i found at http://www.cpp-home.com/FileIO_tutorial.php . The one i learned from isn't online anymore, and i don't know where it went.
//edit
P.P.S. In the tutorial i gave you, beware of the bad programming practices he uses (void main() etc.) and the fact that he calls quotes inverted commas. good luck!
edit//
~Inquirer
Last edited by Inquirer; 10-13-2002 at 03:30 PM.
Compilers:
GCC on Red Hat 8.1 (Primary)
GCC on Mac OS X 10.2.4 (Secondary)
Others:
MinGW on XP
Wasn't there supposed to be an online "Sam's teach yourself c++ in 21 days"? That's a good place to look.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.
Ok i got the open/close file down. I open it at the very start of the program, now how would i search the text enterd by the user for keywords that match words in the keywords.txt i opend?
Like this idea:
If word matches
goto appropriate response in response.txt (also oepnd)
Output the answer.
if not
Add question to Addquestion.txt
tell user you don't know.