Question
C++ Average number of characters in an array of strings Given a function average_length(string * words) This function should calculate the average number of characters
C++ Average number of characters in an array of strings
Given a function average_length(string * words)
This function should calculate the average number of characters in an array of strings. The sentinel value "" (empty string) marks the end of the array.
Where words is a pointer to an array of non-empty strings and this function should return the average string length of the elements in the array or 0 if there are no elements.
I know that the average word length is the total number of characters in all the words, divided by the number of words in the array. Assuming that the number of words in the array is never going to be zero, but never want to divide by 0. I'm confused how do this this with an array of strings instead of integers.
I can't use built-in functions/vectors except for length() which I can use.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started