Question: First, write a function called count_QZ that takes in a string and returns the number of times the letters q and z appear in the

First, write a function called count_QZ that takes in a string and returns the number of times the letters q and z appear in the string. For example an input of zap would return 1, quartz would return 2, and quizzical would return 3.

Next write a function called sort_helper_nonQZ that uses your function from part a) so that if a vector of strings v is passed into sort like this:

std::sort(v.begin(), v.end(), sort_helper_nonQZ) 

the vector would be sorted from words with the highest counts of letters that are not q or z to lowest, with ties broken by lexicographical sorting. For example:

Before sorting... apple has 0 Qs and/or Zs. zap has 1 Qs and/or Zs. quizzical has 3 Qs and/or Zs. quartz has 2 Qs and/or Zs. quack has 1 Qs and/or Zs. After sorting... quizzical has 6 non-Qs/Zs. apple has 5 non-Qs/Zs. quack has 4 non-Qs/Zs. quartz has 4 non-Qs/Zs. zap has 2 non-Qs/Zs. 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!