8. Program isprime.cpp Write a function read_range() which reads in the minimum
ID: 3732674 • Letter: 8
Question
8. Program isprime.cpp Write a function read_range() which reads in the minimum and maximum values. The function has two parameters listed in the following order: a. i. the minimum value of the range ii. the maximum value of the range. Both parameters should have integer type. Both parameters should be passed by reference. The function does not return any value, but it modifies the two parameters. prompts for the minimum and maximum values. If the minimum or The function maximum values are less than 2, then the program prints an error message and prompts again for the two values. If the minimum value is greater than the maximum value, then the program prints an error message and prompts again for the two values The program prints error messages and prompts for the minimum and maximum values unti it gets two values greater than or equal to 2 and such that the minimum is less than or equal to the maximum b. Write a function is_prime() which determines if a number is prime. The function has meter. The function returns true if the input parameter is prime and one integer para false otherwise A number a is prime if and only if (a mod b0) for b- 2, 3,... (a -1) 9. Be sure to add the header comments "File", "Created by", "Creation Date" and "Synopsis" at the top of the file. Each synopsis should contain a brief description of what the program does 10. Be sure that there is a comment documenting each variable. 11. Check that you did not delete or modify any of the original code in procedure main() 12. Check your output against the output from the solution executables provided. 13. Be sure that your if statements, while loops, and blocks are properly indented. 14. Be sure to add the header comments "Fi d by", "Creation Date" and "Synopsis" at he to of the file. Each synopsis shr 3 of 3 fdescription of what the program doses h synopsiS SExplanation / Answer
a)Function which read rang of max and min value---
void read_range(int &minval,int &maxval)
{
int a,b;
while(true)
{
cin>>a>>b;
if(a<2 || a>b || a==b)
cout<<"Error!! Enter Two Value Again:";
else
{
minval=a;
maxval=b;
break;
}
}
}
b)Function whis find number is prime or not-----
bool is_prime(int num)
{
bool flag=true;
int i;
for(int i = 2; i <= num / 2; i++)
{
if(num % i == 0) {
flag = false;
break;
}
}
return flag;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.