Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you walk through this code and explain step by step? #include #define NAME_LEN 20 #define MAX_ITEMS 3 struct Song { int songID; int artistID;

Could you walk through this code and explain step by step? #include #define NAME_LEN 20 #define MAX_ITEMS 3 struct Song { int songID; int artistID; char name[NAME_LEN + 1]; int durationSec; }; struct Album { int albumID; char name[NAME_LEN + 1]; struct Song songs[MAX_ITEMS]; }; void displayDuration(int duration) { printf("%02d:%02d", duration / 60, duration % 60); } int searchArtists(const struct Song* song, const int artists[]) { int i, duration = 0; for (i = 0; !duration && i < MAX_ITEMS; i++) { if (song->artistID == artists[i]) { displayDuration(song->durationSec); printf(" -> %03d %03d %s ", song->songID, song->artistID, song->name); duration = song->durationSec; } } return duration; } int searchSongs(const struct Album* album, const int artists[]) { int i, duration = 0; printf("Album: %s ", album->name); for (i = 0; i < MAX_ITEMS; i++) { duration += searchArtists(&album->songs[i], artists); } return duration; } int main(void) { struct Album album = { 11111, "Album4", { {100, 124, "Song1", 432 }, {200, 652, "Song2", 263 }, {300, 271, "Song3", 311 } } }; const int artistIDs[MAX_ITEMS] = { 271, 958, 632 }; int time = searchSongs(&album, artistIDs); printf("Total Time: "); displayDuration(time); putchar(' '); return 0; }

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

Step: 3

blur-text-image

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions