logo CodeStepByStep logo

surveys

Write a function named surveys that finds the sum of unique answers given to a collection of surveys as described below. Your function accepts a string representing a file name as a parameter where the file data consists of groups of lines separated by a blank line. Each non-empty line contains some subset of the lowercase letters a-z. Your goal is to find the total number of distinct letters used by each blank-line-separated group, sum them, and return this sum. For example, if the file named surveys.txt contains the following:

ab
ac

xyz
y
k

The first clump contains 3 unique letters: a, b, and c. The second clump contains 4 unique letters: x, y, z, and k. So the call of surveys("surveys.txt") should return 3 + 4 = 7.

You may assume that the file exists and is readable, that it follows the format described above, and that there will be at least one clump of surveys in the file.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.