Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

How flying airoplane?

Answered: 1 week ago