C++ Programming

C++ Programming

At this point in the course we’ve studied both vectors and arrays, and have had some exposure to sort algorithms.

Assignment

Write a program that reads a list of names from the provided file in this module — allNames.txt — and stores them into a vector of strings. The file contains randomly generated last names only.

Using one of the sort algorithms we discussed in Chapter 8 — selection sort or bubble sort, your choice — sort the vector in ascending order. No special comparisons are needed for strings, you can simply use the ‘>’ or ‘<‘ operator to compare (for example, the string “abc” will be less than (<) “def” when compared).

After sorting the vector, output the first 5 and last 5 names in the sort.

For a review of how vectors work, read Section 7.11 of the text (p. 435 – 448, with a good reference table on page 448).

Output

Your program should output exactly the following:

First 5 names: 
Abelardo
Agnes
Alexander
Alexandra
Alexandria

Last 5 names:
Zacaras
Yolanda
Yara
Xavier
Witold

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper