Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions