Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Skeleton Code is given below #include #include using namespace std; bool is_prime( int number) { // Please fill in the function body here. // Return

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Skeleton Code is given below

#include

#include

using namespace std;

bool is_prime(int number)

{

// Please fill in the function body here.

// Return true if the given number is a prime, return false otherwise.

/////////////////////////////

// To be implemented

/////////////////////////////

}

int next_prime(int number)

{

// Please fill in the function body here.

// Call is_prime() to justify whether a given number is a prime

// If the given number is a prime, directly return it. Otherwise, use loop to find the first greater one.

/////////////////////////////

// To be implemented (Should call the function is_prime)

/////////////////////////////

}

int main()

{

// Read integer numbers (>= 1) from a given txt file placed at ./input_cases

// Justify whether a number is a prime. If not, calculate the first prime number that is greater than it.

// Output the results using cout.

cout

char input_case_path[100];

cout

cin >> input_case_path;

ifstream fin(input_case_path);

if (!fin) {

cout

return -1;

}

else {

/////////////////////////////

// To be implemented (Should call the function next_prime)

/////////////////////////////

fin.close();

cout

}

return 0;

}

Please help with lines 13/25/51 where it asks to be implemented, thanks.

Prime numbers play an important role in mathematics and have numerous applications in various fields, including computer science, cryptography, and number theory. They are also used in generating random numbers, which is crucial in many applications, such as encryption and statistical simulations. What is a prime number? : A prime number is a positive integer greater than 1 that has no positive integer divisors other than 1 and itself. In other words, a prime number is a number that is only divisible by 1 and itself. For example, 2,3,5,7,11,13,17,19,23, and 29 are the first ten prime numbers. Skeleton and Task Description In this lab, you are given a skeleton code which contains a main function and two other functions, is_prime() and next_prime() to be implemented. In addition, the main function, you are expected to self-study and use FilelO to read integer numbers from specfic text files. - Please download this zip file containing skeleton code and test cases. - Please read the self-study topic FILE I/O Tasks 1. Complete the implementation of the function, is_prime(), which returns true if a given number is a prime number, and returns false if otherwise. e.g. is_prime(7) returns true. is_prime(9) returns false. 2. Complete the implementation of the function, next_prime(), which returns the first prime number greater or equal to the given number. You can use a loop to find the first prime value (should call is_prime() to justify whether a number is a prime) larger than or equal to this number. e.g. next_prime(7) returns 7. next_prime(9) returns 11. 3. In the main function, add the code to read the integer numbers from an input file line by line. Sample input file: 5 10 37 - Then, for each integer number read, add the code to call next_prime() and outputs the result using cout (Note: no need to do file output). Sample output (for the input file above): 5 11 37 NOTE 1: You can assume the numbers in the input file are always integer numbers larger than or equal to 1 (i.e. number >= 1). NOTE 2: Please note that 1 is neither a prime nor a composite. NOTE 3: Please no not modify the skeleton of the code especially the default output (e.g. Hello, welcome ...). NOTE 4: The input files will contain at least one number. Sample Input and Output The following are some sample output. Note that the user input is in green color. If you run the program, you will be asked to enter the filename (pathname) of the input file: Hello, welcome to lab3 (Function \& FileI0) The path for input cases (e.g./input_cases/case5.txt) : input_cases/case1.txt 2 5 7 11 11 Finish! Please check whether the results are correct :) Hello, welcome to lab3 (Function \& FileI0) The path for input cases (e.g./input_cases/case5.txt) : input_cases/case2, txt 17 29 67 17 37 67 Finish! Please check whether the results are correct :) Hello, welcome to lab3 (Function \& FileI0) The path for input cases (e.g ./input_cases/case5.txt) : input_cases/case3.txt 97 97 97 97 2 Finish! Please check whether the results are correct :) Hello, welcome to lab3 (Function \& FileI0) The path for input cases (e.g./input_cases/case5.txt) : input_cases/case4.txt 2 2 53 17 Finish! Please check whether the results are correct :) Hello, welcome to lab3 (Function \& FileI0) The path for input cases (e.g ./input_cases/case5.txt) : input_cases/case5, txt 3 3 3 3 3 Finish! Please check whether the results are correct :)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

=+and non-compete agreements in three to five different countries.

Answered: 1 week ago