Question: please finish the tasks in C + + , thanks Task 1 : Checks if a number is prime or not. bool isPrime ( int

please finish the tasks in C++,thanks
Task 1: Checks if a number is prime or not.
bool isPrime(int n)
{
//-------------------------------------------------------
// This function checks if a number is prime or not
// Input: n, an integer
// Output: true if n is prime, false otherwise
// For example, isPrime(5) returns true
// NOTE: 1 is not a prime number
//** Your TODO: Implement this function **
//-------------------------------------------------------
}
Task 2: Find all pairs of prime numbers that sum up to a given even number.
void findPrimePair(int n)
{
//-------------------------------------------------------
// This function finds all pairs of prime numbers that sum up to n
// Input: n, an integer
// Output: the pairs of prime numbers (p, q) such that n = p + q
// For example, findPrimePair(10), outputs: "10=3+7=5+5"
// NOTE: you should output all pairs of prime numbers that sum up to n, and then print them in ascending order of p
// NOTE: please DO NOT print the same pair twice, e.g.,3+7 and 7+3 are the same pair, only print the first one
// NOTE: if n is not an even number, print "n is not an even number" and return
//** Your TODO: Implement this function **
//-------------------------------------------------------
cout << endl;
}
Task 3: Find all even numbers in the range [lower, upper] that can be expressed as the sum of two prime numbers in at least two different ways.
void findPrimePairInRange(int lower, int upper)
{
//-------------------------------------------------------
// This function finds all even numbers in the range [lower, upper] that can be expressed as the sum of two prime numbers in at least two different ways
// Input: lower bound, an integer (include this number)
// Input: upper bound, an integer (include this number)
// Output: a list of even numbers in the range [lower, upper] that can be expressed as the sum of two prime numbers in at least two different ways
// For example, findPrimePairInRange(1,20), outputs: "1014161820"
// NOTE: 8=3+5 and 8=5+3 are considered as one way, not two ways. 10=3+7 and 10=5+5 are considered as two ways.
//** Your TODO: Implement this function **
//-------------------------------------------------------
cout << endl;
}
Task 4: Find all even numbers in the range [1,100] that can be expressed as the sum of the given prime number and another prime number.
The given prime number is read from ./files/primeX.txt, where X is the number of test cases and the folder ./files is provided in the zip file.
The outputs should be split by a space, such as "1014161820".
void findEvenNumbers(string path)
{
//-------------------------------------------------------
// This function finds all even numbers in the range [1,100] that can be expressed as the sum of the given prime number and another prime number
cout << "Reading prime number from "<< path << endl;
ifstream fin(path); // read prime number from this file
int prime;
fin >> prime;
cout << "Prime number: "<< prime << endl;
//** Your TODO: Implement this function **
//-------------------------------------------------------
cout << endl;
fin.close();
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!