+1 (845) 317-8489 [email protected]

Learning Goal: I’m working on a c++ question and need the explanation and answer to help me learn.

#include<iostream>

using namespace std;

// Prime Class Declaration

class Prime {

//Member Variable Declaration

private:

int num, k;

public:

// Parameterized Constructor definition

Prime(int x):num(x)

{

k = 1;

for (int i = 2; i <num; i++)

if (num % i == 0)

{

k = 0;

break;}

else

{k = 1;}

}

//Member Function show() for display result.

void show() {

if (k == 1)

cout << num << ” is Prime Number.”;

else

cout << num << ” is Not Prime Numbers.”;

}

};

//Main Function

int main() {

int a;

cout << “Simple Parameterized Constructor For Prime Number Example Program In C++n”;

cout << “nEnter the Number:”;

cin>>a;

// Object Creation For Class and Initiate Value from the user input

Prime obj(a);

// Call Member Function show()

obj.show();

return 0;

}