Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions