Write a function bestCD(cds) that returns the CD structure with the highest numb
ID: 656488 • Letter: W
Question
Write a function bestCD(cds) that returns the CD structure with the highest number of stars. This function will take an array of CD structures, cds (use the 10 you create in your test function for example), and return the highest rated CD.Here are 9 examples to use. Create two more in your test function to have a total of 10 CDs to experiment with. makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Classical', ... 'Bocelli, Andrea', 'Andrea', 2004, 4.6, 14.89 ); makeCD( 'Country', 'Twain, Shania', ... 'Greatest Hits', 2004, 3.9, 13.49 ); makeCD( 'Latin', 'Trevi, Gloria', ... 'Como Nace El Universo', 2004, 5, 12.15 ); makeCD( 'Rock/Pop', 'Ludacris', ... 'The Red Light District', 2004, 4, 13.49 ); makeCD( 'R & B', '2Pac', ... 'Loyal To The Game', 2004, 3.9, 13.49 ); makeCD( 'Rap', 'Eminem', ... 'Encore', 2004, 3.5, 15.75 );
Write a function bestCD(cds) that returns the CD structure with the highest number of stars. This function will take an array of CD structures, cds (use the 10 you create in your test function for example), and return the highest rated CD.
Here are 9 examples to use. Create two more in your test function to have a total of 10 CDs to experiment with. makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Classical', ... 'Bocelli, Andrea', 'Andrea', 2004, 4.6, 14.89 ); makeCD( 'Country', 'Twain, Shania', ... 'Greatest Hits', 2004, 3.9, 13.49 ); makeCD( 'Latin', 'Trevi, Gloria', ... 'Como Nace El Universo', 2004, 5, 12.15 ); makeCD( 'Rock/Pop', 'Ludacris', ... 'The Red Light District', 2004, 4, 13.49 ); makeCD( 'R & B', '2Pac', ... 'Loyal To The Game', 2004, 3.9, 13.49 ); makeCD( 'Rap', 'Eminem', ... 'Encore', 2004, 3.5, 15.75 );
Write a function bestCD(cds) that returns the CD structure with the highest number of stars. This function will take an array of CD structures, cds (use the 10 you create in your test function for example), and return the highest rated CD.
Here are 9 examples to use. Create two more in your test function to have a total of 10 CDs to experiment with. makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Blues', 'Clapton, Eric', ... 'Sessions For Robert J', 2004, 2, 18.95 ); makeCD('Classical', ... 'Bocelli, Andrea', 'Andrea', 2004, 4.6, 14.89 ); makeCD( 'Country', 'Twain, Shania', ... 'Greatest Hits', 2004, 3.9, 13.49 ); makeCD( 'Latin', 'Trevi, Gloria', ... 'Como Nace El Universo', 2004, 5, 12.15 ); makeCD( 'Rock/Pop', 'Ludacris', ... 'The Red Light District', 2004, 4, 13.49 ); makeCD( 'R & B', '2Pac', ... 'Loyal To The Game', 2004, 3.9, 13.49 ); makeCD( 'Rap', 'Eminem', ... 'Encore', 2004, 3.5, 15.75 );
Explanation / Answer
//Structure cdinfo definition//
Struct cdinfo
{
char[10] music;
char[30] Singer;
Char[30] NameofCd;
int Year; int Star; Float Price;
} cds[10];
// Function bestCD definition//
BestCD(cds)
{
int i; int best = cds[0].star;
for (i=0; i<10; i++)
{
if (best <cds[i].star)
best= cds[i].star;
return best;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.