Question: c++ Finding the three largest elements in an array The arrays below (singersNames and singersAge) contain the names of some singers and their corresponding ages.
c++
Finding the three largest elements in an array The arrays below (singersNames and singersAge) contain the names of some singers and their corresponding ages. Write a C++ program that will display the names of the three oldest singers in the list. DO NOT SORT THE ARRAYS. DO NOT CREATE A NEW ARRAY. string singersNames[18] = {"Jay Z.", "Eminem Mathers", "Beyonce Knowles", "Cardi B", "Shawn Mendez", "Taylor Swift", "Iggy Azalea", "Drake Graham", "Kanye West", "Chris Martin", "Ariana Grande", "Camila Cabello", "Dr. Dre", "Chance the Rapper", "The Weeknd", "Rihanna", "Bruno Mars", "Billie Eilish"); int singersAges[23] = {52,49,40,28,23,31,31,35,44,44,28,23,56,28,31,33,36,20}; Why this requirement? Is there an easie to do it if we could sort one of the arr first, second, third to Initialize the highest three values as 0 firstName, secondName, thirdName + "" for index first third second, thirdName + secondName second first, secondName + firstName If current element being examined is greater than the highest first { currentAge, firstName + currentName value seen so far, update values accordingly else if currentAge > second third second, thirdName + secondName If current element being examined is greater than the second second + currentAge, secondName + currentName highest value seen so far, update values accordingly else if currentAge > third If current element being examined is greater than the third third { currentAge, thirdName + currentName highest value seen so far, update values accordingly print "Oldest = " + firstName print "Second Oldest = + secondName print "Third Oldest = + thirdName
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
