Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 52 Lab 4 Savitch has a good description of strings and vectors in chapter 8. In this lab we would fill a vector with

CS 52 Lab 4

Savitch has a good description of strings and vectors in chapter 8. In this lab we would fill a vector with first names (in all upper case), and print the as filled vector. Then using a function SortNames, this names vector is sorted in ascending alphabetical order. Finally sorted vector is printed as well. Apart from main function, this lab should have two more function, whose proto-types are given below. [These proto-types cannot be altered. You must use them as is].

Function 1

void FillNames(vector & vecNames);This function takes an empty vector of string type, and fills with user entered first names only. User is required to enter first names in all caps. (We will assume that user would do that). Since vector is being passed by reference, the vector populated with name would be returned to the main function modified and populated with first names. [See output example later to see an example of names being added to this vector].

Function 2

void SortNames(vector & vecNames);This function takes a vector containing unsorted first names in all capital letters, and sorts them (in place), and returns the vector by reference after sorting in ascending order alphabetically.

Main Function

The function calls FillNames function, prints the as filled vector. Then it calls SortNames function and finally prints the vector that has names sorted in ascending order alphabetically.Please see output example from my program below. The output example is part of specifications that your program must meet. Thus, review it carefully:

Intended output example

Information:

EOF character in windows is Control +Z

and EOF character on Mac is Control + D :

-----------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: JOHN

-------------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: TIM

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: ZACK

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: BERTHA

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: LISA

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: ADAM

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: BOB

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: KORINE

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: JILL

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: WILLY

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: NILLY

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry: GENIUS

---------------------------------------------

Enter first name only in all caps (example: JOHN)

Enter EOF character to exit name entry:

---------------------------------------------

The original names in the vector are:

JOHN TIM ZACK BERTHA LISA ADAM BOB KORINE JILL WILLY NILLY GENIUS

After sorting alphabetically in ascending order

the names in the vector are:

ADAM BERTHA BOB GENIUS JILL JOHN KORINE LISA NILLY TIM WILLY ZACK

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

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