Thank you! /*Lab 8 : Practicing functions and arrays Purpose: */ #include<iostre
ID: 3740360 • Letter: T
Question
Thank you!
/*Lab 8 : Practicing functions and arrays
Purpose:
*/
#include<iostream>
#include<fstream>
using namespace std;
int read_function(int array[], int, int);
int main()
{
int array[300], numba;
read_function(array[300]);
cout << "Enter a whole number between 2-20: " << endl;
cin >> numba;
read_function(numba);
return 0;
}
int read_funtion (int arr[300], int num, int Values)
{
int sum=0;
ifstream array_file;
array_file.open("Lab8.dat");
for(int i=0; i < 300; i++)
{
array_file >> arr[i];
cout << arr[i];
sum += i;
}
cout << sum;
for(int j=0; j < sum; j++)
{
int div_by, count;
if(arr[j]/num == 0)
{
count += j;
cout << count;
}
cout << "Out of " << sum << " values " << count
<< " are divisible by " << num << " ." << endl;
}
return sum;
}
This is what I am working with at the moment. I am not sure how the function is to have 3 parameters but then it says to call the function seperately for reading the array and calculating the numbers divisible by the whole number entered by the user.
Goals: Practicing arrays and functions into an array using a function other than main. The number of values in the file is less than 300 and all the values are whole Create a program that will read values from a file called Lab8.dat (posted on Canvas) and store it numbers. The actual number of values stored in the file should be returned to the function call Your program should contain another function that accepts the array, the number of values in the array, and a whole number array are evenly divisible by the whole number and return this count to the function call The loop should not contain more than 3 arithmetic operators ++ and + count as arithmetic operators, but = does not). ount how many values in the s function should use a loop to c The main function should call the function to read the data from the file. Next, ask the user to enter a whole number between 2 and 20 (you may assume the user enters a correct value). This whole number is the value to divide each element in the array. Next, call the function to how many values in the file are eveniy divisible by the entered whole number and output the returned count. The message should be something like 35 of the 189 values in the file were evenly divisible by 12 with the underlined values replaced by the your calculated values and the user's input.Explanation / Answer
/*Lab 8 : Practicing functions and arrays
Purpose:
*/
#include<iostream>
#include<fstream>
using namespace std;
int read_function(int arr[]);
int countDivisible (int arr[], int, int);
int main()
{
int array[300], numba, count;
count = read_function(array);
cout << "Enter a whole number between 2-20: " << endl;
cin >> numba;
int divisible = countDivisible(array, count, numba);
cout << divisible << " of the " << count << " values in the file were evenly divisible by " << numba << " ";
return 0;
}
int read_function (int arr[])
{
ifstream array_file("Lab8.dat");
int num = 0;
while(array_file >> arr[num])
{
num++;
}
return num;
}
int countDivisible (int arr[], int num, int value)
{
int count = 0;
for(int i = 0; i < num; i++)
{
if (arr[i] % value == 0)
{
count++;
}
}
return count;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.