Ask someone over 40 what a “Compact Disc” is, and then write a function with the
ID: 3714014 • Letter: A
Question
Ask someone over 40 what a “Compact Disc” is, and then write a function with the header:
function [CD] = myMusicCollection(genre, title, artist, year, stars, CD)
which adds a new CD to an existing data structure with fields “genre” (a string), “title” (a string), “artist” (a string), “year” (a double), and “stars” (a double) and returns the updated data structure. This function will only work if CD already has at least one album.
Test Cases:
>> CD.genre = 'Classical';
>> CD.title = 'Mass in G';
>> CD.artist = 'Bach';
>> CD.year = 2004;
>> CD.stars = 3.5;
>> CD = myMusicCollection('Classical', 'Symphony 40', 'Mozart', 2015, 4, CD);
>> CD
CD =
1x2 struct array with fields:
genre
title
artist
year
stars
>> CD(1).title
ans =
Mass in G
>> CD(2).year
ans =
2015
>> CD = myMusicCollection('Baroque', 'Rosary Sonatas', 'Biber', 2012, 4, CD);
>> CD
CD =
1x3 struct array with fields:
genre
title
artist
year
stars
>> CD(3).title
ans =
Rosary Sonatas
Deliverables: Submit the above m-files (separately, not zipped) onto Blackboard.
• Be sure that the functions are named exactly as specified, including spelling and case.
• You will get zero credit for a function if it is named wrong, even if
Explanation / Answer
function [CD] = myMusicCollection(genre, title, artist, year, stars, CD)
CD.genre = genre;
CD.title = title;
CD.artist = artist;
CD.year = year;
CD.stars = stars;
end
CD.genre = 'Classical';
CD.title = 'Mass in G';
CD.artist = 'Bach';
CD.year = 2004;
CD.stars = 3.5;
CD = myMusicCollection('Classical', 'Symphony 40', 'Mozart', 2015, 4, CD);
CD(1).title
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.