Answered step by step
Verified Expert Solution
Link Copied!

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.

image text in transcribedc++

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

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

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago

Question

Explain Industrial market segment.

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago