Note: The code is written you can just tell the explanation what is happening in the code Explain in English.Just explain the whole code.
#include <iostream>
using namespace std;
class PrimeNumberGenerator{
private:
int counter;
public:
//Constructor
PrimeNumberGenerator() : counter(0){}
//Function to reset counter
void reset(){
counter = 0;
}
int getCounter(){
return counter;
}
//Function to return next prime number after currentPrime
int getNextPrime(){
if(counter == 0){
counter = 2;
}
else{
for(int i = counter + 1; ; i++){
if(isPrime(i)){
counter = i;
break;
}
}
}
return counter;
}
//Function to check if a number is prime or not
bool isPrime(int num){
for(int i = 2; i <= num/2; i++){
if(num % i == 0)
return false;
}
return true;
}
};
int main() {
int option;
PrimeNumberGenerator gen;
cout << "Enter 1 if you want to reset\n";
cout << "Enter 2 if you want to get next prime number\n";
cout << "Enter -1 to quit: ";
cin >> option;
while(option != -1){
if(option == 1){
gen.reset();
cout << "Counter value: " << gen.getCounter() << endl;
}
else
cout << "Counter value: " << gen.getNextPrime() << endl;
cout << "Enter 1 if you want to reset\n";
cout << "And 2 if you want to get next prime number: ";
cin >> option;
}
}
Step by stepSolved in 3 steps with 1 images
- public class SeperateDuplicates { public static void main(String[ args) { System.out.printIn(seperateDuplicatesChars("Hello")); System.out.printin(seperateDuplicatesChars ("Bookkeeper"')); System.out.printin(seperateDuplicatesChars("Yellowwood door"')); System.out.printin(seperateDuplicatesChars("Chicago Cubs")); */ public static String seperateDuplicatesChars(String str) { //To be completed } }arrow_forwardNEED HELP WITH JAVA PROGRAM ERROR PLEASE HELP THANK YOU CODE: class quad{public static void main(String args[] ){Quadrilateral quadrilateral = new Quadrilateral( 1.1, 1.2, 6.6, 2.8, 6.2, 9.9, 2.2, 7.4 );Trapezoid trapezoid = new Trapezoid (0.0, 0.0, 10.0, 0.0, 8.0, 5.0, 3.3, 5.0 );Parallelogram parallelogram = new Parallelogram (5.0, 5.0, 11.0, 5.0, 12.0, 20.0, 6.0, 20.0 );Rectagle rectagle = new Rectagle(17.0, 14.0, 30.0, 14.0, 30.0, 28.0, 17.0, 28.0 );Square square = new Square( 4.0, 0.0, 8.0, 0.0, 8.0, 4.0, 4.0, 4.0 );System.out.printf("%s %s %s %s %s\n", quadrilateral, trapezoid, parallelogram, rectagle, square );}}class Point{private double x;private double y;public Point(double xCoordinate, double yCoordinate){x = xCoordinate;y = yCoordinate;}public double getX(){return x;}public double getY(){return y;}public String toString(){return String.format( "( %.1f, %.1f)", getX(), getY() );}}class Quadrilateral {private Point point1;private Point point2;private Point point3;private…arrow_forwardNote: It`s python codingarrow_forward
- Lab 9 C balance the same, y, n, why? class CheckingAct { . . . . private int balance; public void processCheck( int amount ) { int charge; if ( balance < 100000 ) charge = 15; else charge = 0; balance = balance - amount - charge ; // change the local copy of the value in "amount" amount = 0 ; } } public class CheckingTester { public static void main ( String[] args ) { CheckingAct act; int check = 5000; act = new CheckingAct( "123-345-99", "Your Name", 100000 ); System.out.println( "check:" + check ); // prints "5000" // call processCheck with a copy of the value 5000 act.processCheck( check ); System.out.println( "check:" + check ); // prints "5000" --- "check" was not changed } }arrow_forwardComputer Science c++ help comment code please. Complex has multiple parameters to overload i think. class Complex{public: Complex(); //There are no parameters because... Complex(double); //There is one parameter because... Complex(double, double);//There are two parameters because... double get_Real(); void set_Real(double); double get_Imaginary(); void set_Imaginary(double); friend ostream& operator << (ostream& out, Complex& r); //explain friend istream& operator >> (istream& in, Complex& r);//explainprivate: double real; double imaginary;}; ostream& operator << (ostream& out, Complex& r) //{ double a = r.get_Real(); double b = r.get_Imaginary(); if (a != 0)out << a; if (b < 0) out << "-" << abs(b) << "i"; if (b > 0 && b != 1) out << "+" << b << "i"; if (b == 0) out << "0"; if (b == 1 && a != 0) out << "+" <<…arrow_forwardStatement that increases numPeople by 5. Ex: If numPeople is initially 10, the output is: There are 15 people.arrow_forward
- C programming #include <stdio.h>int main() {int i, j, n ;printf("height? ") ;scanf("%2d", &n) ;for (i = 1 ; i <= n ; i++) {// printf("%d: ", i) ;for (j = 1 ; j <= i ; j++) {// Pick *one* of the following// printf("%d", j % 10) ;printf("*") ;}printf("\n") ;}return 0 ;} How can I get output like this by editing the given programming -- height? 5************************* and then how can I get the following?- height? 7 1 123 12345 1234567 123456789 12345678901 1234567890123arrow_forwardQ1. amount the same, y, n, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { balance = balance + amount ; } // modified toString() method public String toString() { return "Account: " + actNum + "\tName: " + nameOnAct + "\tBalance: " + amount ; } } Q2. amount the same, y, n, why? public class CheckingAct { private String actNum; private String nameOnAct; private int balance; . . . . public void processDeposit( int amount ) { // scope of amount starts here balance = balance + amount ; // scope of amount ends here } public void processCheck( int amount ) { // scope of amount starts here int charge; incrementUse(); if ( balance < 100000 ) charge = 15; else charge = 0; balance = balance - amount - charge ; // scope of amount ends here }…arrow_forwardPROBLEM STATEMENT: Use string concatenation to append the "dogs" string to the parameter str. public class StringConcatAppend{public static String solution(String str){// ↓↓↓↓ your code goes here ↓↓↓↓return null; Can you help me with this question The language is Javaarrow_forward
- Kindly solve this C++ program and follow all the instructions! Please let me know how should I contact you for further assistance. Thank you for your help!arrow_forwardX3: inlTo10 Write a function in Java that implements the following logic: Given a number n, return true if n is in the range 1..10, inclusive. Unless "outsideMode" is true, in which case return true if the number is less or equal to 1, or greater or equal to 10.arrow_forwardcorrect the codearrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY