include <iostream>
using std::cout;
using std::endl;

#include <cmath>
#include "number.h"

#include<iomanip>
using std::setw;

number::number()
{
}

// constructor initializes PrimeNumberwith bool as arugment
number::number(bool prime) 
{
	setPrimeName(prime);

}// end function setPrimeNumber
void number::setprimeNumber()
{
	primeNumber=number;
}

bool number::getPrimeNumber()
{
	return prime;
}// end function getPrimeNumber

void number::displayOn()
{
	cout << "The prime numbers from 2 to 10000 are:\n\n";
}

void number::useDivisionFunction()
{
	int count=0;

	for (int x = 2; x <= 10000; ++x )  //loop
		if (prime(x)) 
		{
			++count;
			
			cout << setw( 6 ) << x;

			if ( count % 5 == 0)

				cout << endl; 
		}
}
		
 return 0;
 
 bool prime (int n)
 {
	 for ( int z = 2; (n/2) + 1 > z; z++ )

		 if( n % z == 0 ) 

			 return false;

	 return true;
 }   // end useDivisionFunction

  void number::useSquareFunction()
  {
	  int count=0;
	  bool prime (int x);

	  for (int x = 2; x <= 10000; ++x )

		  if (prime(x)) 
		  {
			  ++count;

			  cout << setw( 6 ) << x;
		
		  if ( count % 5 == 0)

			  cout << endl << endl;
		  }

  return 0;

  }

  bool prime (int n)
  {
	  if(n < 2)  

		  return false;

	  if(n == 2) 

		  return true;

	  if (n % 2 == 0) 

		  return false;

	  double root = sqrt(double(n))+ 1;

	  for ( int z = 3; z <= root; z += 2)

		  if( n % z == 0 ) 

			  return false;

	  return true;

  } // end UseSquareFunction

number.cpp

h file
#ifndef NUMBER_H
#define NUMBER_H

class number
{
public:
	number();
	number(bool prime);
	void displayOn();
	void useDivisionFunction();
	void useSquareFunction();
	void setprimeNumber(bool);
	bool getprimeNumber();
private:
	bool primeNumber; // data member 
};
#endif   //ends the class declaration

I have a return of 10 errors.

------ Build started: Project: Rho_7 6-30c, Configuration: Debug Win32 ------
Compiling...
number.cpp
number.cpp(38) : error C3861: 'setPrimeName': identifier not found
\number.cpp(42) : error C2511: 'void number::setprimeNumber(void)' : overloaded member function not found in 'number'
number.h(25) : see declaration of 'number'
number.cpp(46) : error C2039: 'getPrimeNumber' : is not a member of 'number'
number.h(25) : see declaration of 'number'
number.cpp(48) : error C2065: 'prime' : undeclared identifier
number.cpp(61) : error C3861: 'prime': identifier not found
number.cpp(73) : error C2059: syntax error : 'return'
number.cpp(76) : error C2365: 'prime' : redefinition; previous definition was 'formerly unknown identifier'
number.cpp(89) : error C2373: 'prime' : redefinition; different type modifiers
number.cpp(104) : error C2562: 'number::useSquareFunction' : 'void' function returning a value
number.h(31) : see declaration of 'number::useSquareFunction'
number.cpp(109) : error C2365: 'prime' : redefinition; previous definition was 'formerly unknown identifier'
Build log was saved at - 10 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I think it's going to get pretty confusing if you don't declare "value" as a data member in addition to "primeNumber", and possibly change the name "primeNumber". Case in point, your function called "setPrimeNumber". You always want to have the word after "Set" be the name of the data member in question. You have a data member called "primeNumber", but it's a boolean variable. Then you have a function called "setPrimeNumber" that assigns primeNumber to the name of your class. You need a different name for the parameter than the name of the class. I personally like the name "isPrime" for the data member since I think it's more obvious that it is a boolean. The compiler could not care less as long as you keep them straight.

You have a function call to "setPrimeName", which doesn't exist. I imagine that's a typo and you meant "setPrimeNumber". However, setPrimeNumber takes no parameters in your function. It needs to. "Set" functions always do. "Get" functions usually do not.

// constructor initializes PrimeNumberwith bool as arugment
number::number(bool prime) 
{
	setPrimeName(prime);

}// end function setPrimeNumber
void number::setprimeNumber()
{
	primeNumber=number;
}

You still have two functions called:

bool prime (int n)

You can only have one. The compiler is getting confused. That's what the error is there. Also, do you want:

bool prime (int n)

to be a class function? It currently is not. If you do, you need to put it in the .h file and change it to:

bool number::prime (int n)

in number.cpp. Regardless, you need to get rid of one of those two functions because you can't have two functions with the same name and that take the same parameters.

Thanks for all your help! I must turn this in with just the the very first codes I did. I do not understand data members, constructors, functions or how I am going to have just one bool prime(int n) function. I am a mess!

Thanks again,
M

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.