Develop a C++ class called PrimeNumberGenerator. An object of this class will generate successive prime numbers on request. Think of the object as being similar to the digital tasbeeh counter. It has a reset button which makes the counter return to 0. There is also a button to get the next prime number. On the tasbeeh, pressing this button increments the current value of the counter. In your object, pressing this button would generate the next prime number for display. You’ll implement the reset button as a member function reset() and the other button as a function getNextPrime(). When an object is first created and the getNextPrime() function is called, it will return the first prime number, i.e., 2. Upon subsequent calls to the getNextPrime() function, the subsequent prime numbers will be returned. Define any others functions such as constructor and attributes that you need. According to Wikipedia: “a prime number is a natural number greater than 1, that has no positive divisors other than 1 and itself.” Expected Input/Output: Enter 1 if you want to reset Enter 2 if you want to get next prime number Enter -1 to quit: 1 Counter value: 0 Enter 1 if you want to reset And 2 if you want to get next prime number: 2 Counter value: 2 Enter 1 if you want to reset And 2 if you want to get next prime number: 2 Counter value: 3 Enter 1 if you want to reset And 2 if you want to get next prime number: 2 Counter value: 5 Enter 1 if you want to reset And 2 if you want to get next prime number: -1 (Object oriented programming c++ question)
Develop a C++ class called PrimeNumberGenerator. An object of this class will generate successive prime numbers on request. Think of the object as being similar to the digital tasbeeh counter. It has a reset button which makes the counter return to 0. There is also a button to get the next prime number. On the tasbeeh, pressing this button increments the current value of the counter. In your object, pressing this button would generate the next prime number for display. You’ll implement the reset button as a member function reset() and the other button as a function getNextPrime(). When an object is first created and the getNextPrime() function is called, it will return the first prime number, i.e., 2. Upon subsequent calls to the getNextPrime() function, the subsequent prime numbers will be returned. Define any others functions such as constructor and attributes that you need.
According to Wikipedia: “a prime number is a natural number greater than 1, that has no positive divisors other than 1 and itself.”
Expected Input/Output:
Enter 1 if you want to reset
Enter 2 if you want to get next prime number
Enter -1 to quit: 1
Counter value: 0
Enter 1 if you want to reset
And 2 if you want to get next prime number: 2
Counter value: 2
Enter 1 if you want to reset
And 2 if you want to get next prime number: 2
Counter value: 3
Enter 1 if you want to reset
And 2 if you want to get next prime number: 2
Counter value: 5
Enter 1 if you want to reset
And 2 if you want to get next prime number: -1
(Object oriented
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images