C++ instruction: https://ufile.io/xfgyr 1 #include iostream» | #include iona nip
ID: 3592677 • Letter: C
Question
C++ instruction: https://ufile.io/xfgyr
1 #include iostream» | #include iona nip> L#include 3 4. 5 void seedRNG(int seed); 6 int getRand (int min, int max); 7 int getMin(int a, int b, int c) 8 void getMin(int a, int b, int c, int & min); 9 int getMax(int a, int b, int c); 10 void getMax(int a, int b, int c, int & max) oid getMinMax(int a, int b, int c, int & min, int & max); 12 void formatDouble(double d, int numDecimals); 13 bool isEven(int x); 14 void printchar(char c, int numTimes) 15 double fToc(double f) 16 double cToF (double c); 17 18 DO NOT REMOVE THESE COMMENTScomments that start with@are actually 19 // commands to the assessment tool. 20 21 //@addRule (commentAll) 22 int main() 23 24 // You can do whatever tests you want in here. When we compile 25 26 27 28 29 30 31 32 33 DO NOT REMOVE THESE COMMENTSthese comments are actually 34// commands to the assessment tool 35 L/@removeRule(commentAll) 36 37 // Oops! 1 accidentally did this one for you. 38 1 Don't forget to copy the prototype down here, 39 / remove the semicolon, add the curly braces, 40 41 void seedRNG(int seed) 42 43 //@include (main) /7 your code we are actually going to remove this main function // and substitute our own. Then we are going to test your functions // individually std::coutExplanation / Answer
Hi,
here is the full copyable code of all functions with comments.
int getRand(int min,int max)
{
return rand() % max + min;//random number between min and max
}
int getMin(int a,int b,int c)
{//returning min of 3 numbers
if(a<b && a<c)
return a;
if(b<a && b<c)
return b;
else
return c;
}
void getMin(int a,int b,int c,int &min)
{//returning min of 3 numbers to a pointer variable
if(a<b && a<c)
*min=a;
if(b<a && b<c)
*min=b;
else
*min=c;
}
int getMax(int a,int b,int c)
{//returning max of 3 numbers
if(a>b && a>c)
return a;
if(b>a && b>c)
return b;
else
return c;
}
void getMax(int a,int b,int c,int &max)
{//returning max of 3 numbers via pointer variale
if(a>b && a>c)
*max=a;
if(b>a && b>c)
*max=b;
else
*max=c;
}
void getMinMax(int a,int b,int c,int &min,int &max)
{//get both min and max via pointer variable
if(a>b && a>c)
*max=a;
if(b>a && b>c)
*max=b;
else
*max=c;
if(a<b && a<c)
*min=a;
if(b<a && b<c)
*min=b;
else
*min=c;
}
void formatDouble(double d,int numDecimals)
{
cout << std::fixed;
cout << std::setprecision(numDecimals);//setting precision to given number of decimal places
cout << d;//print double
}
bool isEven(int x)
{
if(x%2==0)//if divisble by 2 return true
return true;
return false;
}
void printChar(char c,int numTimes)
{
int i=0
for(i=0;i<numTimes;i++)//loop to print c, given no of times
printf("%c",c);
}
double fToC(double f)
{
return (f- 32) × 5/9;//farhenheit to celsius conversion
}
double cToF(double c)
{
return c × 1.8 + 32//celsius to farhenheit conversion
}
Thumbs up if this was helpful, otherwise let me know in comments
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.