Write a function that returns the average of an array of integers. The function
ID: 666567 • Letter: W
Question
Write a function that returns the average of an array of integers. The function returns an int and is passed an array of ints and it's size as an int.
Write a function that returns the average of a file that contains one integer per line. The function returns as int and is passed a string which contains the filename.
Write a function that counts the number of occurrences of a specific character in a string. The function returns as int and is passed a string which is searched and a char which is searched for.
Create a two dimension array that can be used as a target based on a number that is passed as a parameter (up to 100) ... here's the number 5
555555555
544444445
543333345
543222345
543212345
543222345
543333345
544444445
555555555
Write a function that determines if there are three of the same value in a row in an array. The function returns a bool and is passed an array of ints and it's size as an int.
Write a function that determines if there are three of the same line in a row in a file. The function returns a bool and is passed a string which contains the filename.
Write a function that determines if there are two words that are the same in a row in a string. The function returns a bool and is passed a string.
Explanation / Answer
int average(int arr[], int size){
int avg = 0;
for(int i = 0; i < size; i++) avg += arr[i];
return avg / size;
}
int averageFile(string fileName){
int avg = 0;
ifstream inFile(fileName.c_str());
int temp, count = 0;
while(inFile >> temp){
avg += temp;
count++;
}
return avg / count;
}
int numChar(string str, char ch){
int count = 0;
for(int i = 0; i < str.size(); i++){
if(str[i] == ch) count++;
}
return count;
}
// Didnt understand the question 4 clearly. Please explain a bit. We have to make an array or afunction, what?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.