GIVEN A PROGRAM IN C++: #include <stdlib.h> #include <iostream.h> #include <math
ID: 3678791 • Letter: G
Question
GIVEN A PROGRAM IN C++:
#include <stdlib.h>
#include <iostream.h>
#include <math.h>
#include<conio.h>
//function prototype.
int rand_int(int a, int b);
float rand_float(float f1,float f2);
int main()
{
// declrare objects.
unsigned int seed;
int a, b;
float x,y;
char random_type;
clrscr();
// get seed value and interval limits.
cout << "enter a positive integer seed value : ";
cin >> seed;
//seed the random number generator.
srand(seed);
cout<<"Do you wish to generate integers or floats, enter I or F :";
cin>>random_type;
if((random_type == 'i')||(random_type=='I'))
{
cout << "enter interger limits a and b (a<b): ";
cin >> a >> b;
// generate and print ten random numbers.
cout << " random numbers : ";
for (int k = 1; k <= 10; ++k)
{
cout << rand_int(a, b)<< endl;
}
cout << endl;
}
else if(random_type=='f'|| random_type=='F')
{
cout << "enter float limits a and b (a<b): ";
cin >> x>>y;;
// generate and print ten random numbers.
cout << " random numbers : ";
for (int k = 1; k <= 10; ++k)
{ cout << rand_float(x, y)<< endl;
}
cout << endl;
}
// exit program.
getch();
return 0;
}
/*this program generates a random interger */
/* between specified limits a and b (a<b).*/
int rand_int(int a, int b)
{
return rand() % (b - a + 1) + a;
}
/*this program generates a random float numbers */
/* between specified limits a and b (a<b).*/
float rand_float(float x, float y)
{ float f;
f = fmod(rand() ,(y - x + 1) + x);
return f;
}
QUESTIONS:
A) list the names of the three functions that was created:
Function 1 Name:
Function 2 Name:
Function 3 Name:
B) show the signature for each of the three functions:
Function 1 Signature:
Function 2 Signature:
Function 3 Signature:
For each function, indicate the inputs, outputs, and their corresponding data types:
Function 1:
Item
Is This an Input or Output?
Data Type
Function 2:
Item
Is This an Input or Output?
Data Type
Function 3:
Item
Is This an Input or Output?
Data Type
For each function, indicate all local variables and corresponding data types:
Function 1 Local Variables:
Local Variable Name
Data Type
Function 2 Local Variables:
Local Variable Name
Data Type
Function 3 Local Variables:
Local Variable Name
Data Type
Item
Is This an Input or Output?
Data Type
Explanation / Answer
A) list the names of the three functions that was created:
Function 1 Name:
rand_int
Function 2 Name:
rand_float
Function 3 Name:
main //this function is default but still created by us.
B)
int rand_int(int a, int b);
float rand_float(float f1,float f2);
int main()
Function 1:
Item
Is This an Input or Output?
Data Type
a
input
int
b
input
int
Function 2:
Item
Is This an Input or Output?
Data Type
f1
input
float
f1
input
float
Function 3:
Item
Is This an Input or Output?
Data Type
no input and output for main()
--
--
For each function, indicate all local variables and corresponding data types:
Function 1 Local Variables:
rand_int(a,b)
Local Variable Name
Data Type
a
int
b
int
Function 2 Local Variables:
rand_float(x,y)
Local Variable Name
Data Type
f
float
x
float
y
float
Function 3 Local Variables:
main()
Local Variable Name
Data Type
a
int
b
int
x
float
y
float
Item
Is This an Input or Output?
Data Type
a
input
int
b
input
int
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.