Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Write a function called TwoRand that generates two random numbers (ints) betw

ID: 3778596 • Letter: 1

Question

1) Write a function called TwoRand that generates two random numbers (ints) between 1 and 25 and returns them to the calling function. Now show how TwoRand would be called: write a small driver program that calls the function and prints the result. 2) Write a function Multiplylt that takes two int parameters and multiplies all the numbers together that include and are between the two parameter values. The function should return the end product to the main program. (Ex. Multiplylt(4,6) would return the product of 4 5 6) Chapter 7 2. Look at the following array definition: int values a) How many elements does the array have? b) What is the subscript of the first element in the array? c) What is the subscript of the last element in the array? d) Assuming that an intuses four bytes of memory, how much memory does the array use? 6. int numbers (5, 10, 15, 20); a. What value is stored in numbers/2)? b. What value is stored in numbers 2? c What value is stored in numbers/2) after the following: numbers12) numbers numbers(oj Write a function called Fill that prompts the user to enter in characters to fill a one dimension char array. Pass the number of elements in the array and the array to the function. The filled array should be returned back to the calling function.

Explanation / Answer

#include <iostream>
#include <ctime>
#include<cstdlib>

using namespace std;

// function to generate and retrun random numbers.
int * TwoRandom( ) {//1)
   static int r[2];

   // set the seed
   srand( (unsigned)time( NULL ) );
  
   for (int i = 0; i < 2; ++i) {
      r[i] = (rand()%25)+1;
      //cout << r[i] << endl;
   }

   return r;
}

int MultiplyIt(int x,int y)
{
   int mul=x;
   for(x=x+1;x<=y;x++)
       mul=mul*x;
       return mul;
}

// main function to call above defined function.
int main () {
   // a pointer to an int.

   //1)driver function
   int *p;

   p = TwoRandom();
   cout<<"Two random numbers:";
   for ( int i = 0; i < 2; i++ ) {
    
      cout << *(p + i) <<" ";
   }
   cout<<" ";
//

//2)driver program
cout<<"Product result :"<<MultiplyIt(4,6)<<" ";

   return 0;
}

ouput:-

Two random numbers:11 25
Product result :120


Process exited normally.
Press any key to continue . . .

chapter 7:

2)

a)8

b)0

c)7

d)32 bytes(8*4)

6)

a)15

b)20

c)102