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

Write a program using Microsoft Visual Studios with two functions. The main func

ID: 3677753 • Letter: W

Question

Write a program using Microsoft Visual Studios with two functions. The main function will just define and initialize the variables and call the user functions. All the work will be done by the user functions. The size of the array is 80.

Function #1: this function will be passed a float array and its size and return nothing. The function will fill the array with random floats between 0 and 1 (exclusive). Use the formula below:

x[i] = (float) rand() / (float) (RAND_MAX + 1);

Function #2: Print the array to the screen. Print 8 numbers on a line across the screen. The numbers should be aligned vertically. Examle:

xxxxx xxxxx …

xxxxx xxxxx …

xxxxx xxxxx …

Explanation / Answer

This below program will generate the random float numebrs between 0 and 1 with the help of

1. Function floatArray

2. Print the array

#include<iostream>
#include<cstdlib>
const int MAX = 80;
using namespace std;

void floatArray(float array[], int length)
{
   int i;
   for(i =0;i<length;i++)
       array[i] = x[i] = (float) rand() / (float) (RAND_MAX + 1);
}

void print(float array[], int length)
{
   int i;
   int count = 0;
   for(i=0;i<length;i++)
   {
       if(count <8)
       {
           cout<<array[i]<<" ";
           count++;
       }
       else
       {
           cout<<endl;
           count = 0;
       }
      
   }  
}

int main()
{
   float array1[MAX];
   floatArray(array1, MAX);
   print(array1,MAX);
   return 1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote