Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 = + thirdNameStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started