Hello, I am just starting to learn about classes and currently am learning about how to declare classes in a separate file though I am having trouble as I keep getting the error code saying No such file or directory. I am using Code::Blocks and I have tried looking this up though I have not seen anything that has been helpful for me. My program works when it is all in one file though when seperated into the different files it will not work, even when I use the default code::blocks class setup. Here is my different code files. I will say what folder everything is in incase that is what is causing the problems

protected:
private:
long long number;
long long sqrt_test;
long long sqrt_int();
};

#endif // PRIME_NUMBER_DETECTOR_H

Does anyone have any idea where I might of made a mistake on creating my class files and headers?

Oh and incase anyone asks I have using long long because I am going to be testing out very large numbers for a problems I want to try, which is to find the largest prime factor of a number.

Edit: If anyone has a suggestion on another method on calculating if a number is prime it would be greatly appreciated as currently this test will take a long time.

05-09-2012

manasij7479

(The code looks okay, without looking minutely)

Make a project in C::B instead of just files, and when adding a new .cpp or .h file, choose the "Add to current project" or something similar option.

05-09-2012

GReaper

My suggestion is that you save in your class a vector of previously found primes, then check them first against the test value. Also remember that you don't need to test it with primes greater than its square root.

What is "sqrt_int()" for? [edit]( Never mind, I found it )[/edit]

05-09-2012

thadis_4

manasij7479:
I thought I added an option that said add to current project though I might of either misremembered or what I clicked just did not do what I expected.

GReaper:
I thought about something like using a list of found primes though I did not know how I would use it as I am not extremely familiar with vectors. And yes the sqrt_int(); is used for finding a number greater than the actual square root saying I was going to try to avoid using float points and couldn't remember if you have a number like 5.3 if it would round to 6 or 5.

05-09-2012

GReaper

Floating point numbers are always truncated when they're converted to integers. That said, I'm not sure whether they round towards zero or towards -INF.

05-09-2012

thadis_4

Yeah I just decided to use my own version of square root to do the part of the built in one though I guess now that I think of it I could of just done the C++ one +1. Also I tried adding my two files for my header(.h and the .cpp) by right clicking on the project and saying "Add File" and add the two files and it still will not work. Any other ideas that might be causing my problems?

05-09-2012

GReaper

Have you added all the files to the same build? Code::Blocks gives two default builds, Debug & Release.

I'd also like to say that this is a bad use of classes. You wont learn how to correctly use them, or understand why they are used, if you use them for inappropriate purposes. Testing for primeness screams of just writing a function that takes a single input and produces a single output, and has no side-effects.
You might learn about prime number determination, but it simply isn't a good idea to combine that with learning how to use classes.
Would you like a suggestion of what would be good to implement to try and learn about classes?

05-10-2012

thadis_4

I believe I added both the .cpp and the .h to the project in both the release and debug though I will check it when I get home.

IMalc:
What would you suggest as a class? I only did it this way because i was learning how to create classes and wanted to try to create the header files.