Problems with Header Files in CB
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
In my main.cpp(which is found in my sources folder) I have
Code:
#include <iostream>
#include "Prime_Number_Detector.h"
using namespace std;
int main()
{
cout << "Enter a number!" << endl;
Prime_Number_Detector test;
long long H;
cin>> H;
test.number_input(H);
cout<<"Testing if prime number.\n";
bool T;
T = test.prime_test();
if(T == true){
cout<<H << " is a prime number!\n";
}
else{
cout<<H <<" is not a prime number. =(\n";
}
return 0;
}
In my file Prime_Number_Detector.cpp(Found in the src folder which is in the Sources Folder) I have
Code:
#include <iostream>
#include "Prime_Number_Detector.h"
using namespace std;
Prime_Number_Detector::Prime_Number_Detector()
{
//ctor
}
Prime_Number_Detector::~Prime_Number_Detector()
{
//dtor
}
void Prime_Number_Detector::number_input(long long y){
number = y;
}
long long Prime_Number_Detector::sqrt_int(){
long long x;
long long z;
for(long long i = 1; z < number; i++){
z = i*i;
x = i;
}
return x;
}
bool Prime_Number_Detector::prime_test(){
long long x = sqrt_int();
long long y = 0;
bool test = true;
while(test == true && y <= x){
if(number % 2 != 0){
for( y = 3; y <= x; y += 2){
if(number%y == 0){
test = false;
}
}
}
else{
test = false;
}
}
return test;
}
And Finally in my Prime_Number_Detector.h(Found in the include folder which was in the Headers folder) I have
Code:
#ifndef PRIME_NUMBER_DETECTOR_H
#define PRIME_NUMBER_DETECTOR_H
class Prime_Number_Detector
{
public:
Prime_Number_Detector();
virtual ~Prime_Number_Detector();
void number_input(long long);
bool prime_test();
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.