Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This a question from Attaway Matlab Practical Introduction to Programming and Problem Solving 3rd Edition, it is question 47 on chapter 5... A CD changer

This a question from Attaway Matlab Practical Introduction to Programming and Problem Solving 3rd Edition, it is question 47 on chapter 5... A CD changer allows you to load more than one CD. Many of these have random buttons, which allow you to play random tracks from a specified CD or play random tracks from random CDs. You are to simulate a play list from such a CD changer using the randi function. The CD changer that we are going to simulate can load three different CDs. You are to assume that three CDs have been loaded. To begin with, the program should decide how many tracks there are on each of the three CDs by generating random integers in the range from MIN to MAX. You decide on the values of MIN and MAX. (Look at some CD. How many tracks do they have? Whats a reasonable range?). The program will print the number of tracks on each CD. Next, the program will ask the user for his or her favorite track; the user must specify which track and which CD its on. Next, the program will generate a playlist of the N random tracks that it will play, where N is an integer. For each of the N songs, the program will first randomly pick one of the three CDs and then randomly pick one of the tracks from that CD. Finally, the program will print whether the users favorite track was played or not. The output from the program will look something like this depending on the random integers generated and the users input There are 15 tracks on CD 1. There are 22 tracks on CD 2. There are 13 tracks on CD 3. What's your favorite track? Please enter the number of the CD: 4 Sorry, that's not a valid CD. Please enter the number of the CD: 1 Please enter the track number: 17 Sorry, that's not a valid track on CD 1. Please enter the track number: xyz Sorry, that's not a valid track on CD 1. Please enter the track number: 11 Play List: CD 2 Track 20 CD 3 Track 11 CD 3 Track 8 CD 2 Track 1 CD 1 Track 7 CD 3 Track 8 CD 1 Track 3 CD 1 Track 15 CD 3 Track 12 CD 1 Track 6 Sorry, your favorite track was not played.

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

More Books

Students also viewed these Databases questions