首页 > > 详细

辅导DPST1091编程设计、辅导C++程序、辅导C++程序解析Haskell程序|辅导Web开发

DPST1091 21T1 - Assignment 2 - CSpotify
Assignment 2 - CSpotify
Introduction
We consider music streaming to be a normal thing that we use regularly . . . but it wasn't always this way. In the late 1990s, a new file format
called the MP3 appeared. Its ability to compress audio coupled with the rise of the internet lead to a new era in the music industry. Napster
(and a new generation of music pirates) brought this into the spotlight when they launched in 1999.
Nowadays, with services like Spotify, we have access to a massive library of music (and other audio) content from nearly any device with an
internet connection.
In this assignment, you'll be looking at some of the coding work that goes into organisation of music with things like song information,
playlists and personal music libraries. CSpotify is our implementation of a song library using linked lists as the primary data structure.
Your Goal
The assignment is divided into two parts:
Part A - Implementation (5 Stages)
Your task here is to write the functions that will manage your music Library of Playlists which contain Tracks. All of these functions
are contained inside the file cspotify.c.
Part B - Testing
Your task here is to write functions in test_cspotify.c to check that your code works.
Please note that you do not need to scan in any inputs from the user, this is already completed for you in the given starter code.
The Overall Picture - Your Library
The Library is the overall struct which contains all the objects you will need for the assignment. The Library contains a list of Playlists. In
each of the Playlists, there is a list of Tracks. At the start of the program, the Library starts off as an empty Library containing no
Playlists and hence no Tracks.
As you progress through Stage 1 of the assignment to manage Playlists to your Library, your Library might start to look like this, where
there are Playlists in the Library but not Tracks in any of the Playlists:
Note: You should refer to cspotify.h for more technical and detailed instructions in regards to each function’s implementation.
2021/3/30 DPST1091 21T1 - Assignment 2 - CSpotify
https://cgi.cse.unsw.edu.au/~dp1091/21T1/assignments/ass2/index.html 2/13
Stage 2 will then allow you to navigate around your Library Playlists and add Tracks to each Library, resulting in a Library that could look
like this:
Each Track will store information about the title, artist and the trackLength in addition to a next pointer.
Stage 3 will focus on removing certain objects from your Library.
Stage 4 and 5 will be more challenging manipulations of your Library.
The assignment breaks up the above further into smaller tasks to help you build and navigate around your Library. It is strongly
recommended that o begin from Stage 1 and progress in the gi en order
2021/3/30 DPST1091 21T1 - Assignment 2 - CSpotify
https://cgi.cse.unsw.edu.au/~dp1091/21T1/assignments/ass2/index.html 3/13
recommended that you begin from Stage 1 and progress in the given order.
Getting Started
Starter Code
The starter code consists of the following files:
main.c contains the main function for the assignment. It will scan the program's input, then call the functions you will write.
You must not change this file.
cspotify.h contains the definitions of all the functions you will be writing. It also contains useful constants and type definitions.
You must not change this file.
cspotify.c contains empty functions which you will need to implement. It already contains some functions. It is strongly recommended that
you use these.
This file is where you will write your own code.
test_main.c contains a main function and other functions that allow you to run the tests you create in test_cspotify.c.
You must not change this file.
test_cspotify.h contains the prototypes of the testing functions in test_cspotify.c.
You must not change this file.
test_cspotify.c contains an alternative main function as well as template code that you will modify to make your own tests.
This file is where you will write your own test cases.
capture.h contains the definition of a function that allows you to capture the output of your own code, to use in testing. It can only be used
in test_cspotify.c, and will not be available in cspotify.c .
You must not change this file.
capture.c contains the implementation of functions that allow you to capture the output of your own code, to use in testing.
You must not change this file.
To run your code interactively, you should use the command:
$ dcc -o cspotify cspotify.c main.c
$ ./cspotify
To run your tests (written in test_cspotify.c), you should use the command:
$ dcc -o test_cspotify cspotify.c test_cspotify.c capture.c test_main.c
$ ./test_cspotify
Allowed C Features
In this assignment, there are two restrictions on C Features:
You must follow the rules explained in the Style Guide.
You may not use the function fnmatch, or import fnmatch.h.
It is recommended to only use features that have been taught in DP1091. Course work in Week 8, 9 and some of Week 10 will have a
particular focus on assistance for this assignment and you will not need any of the subject material from Weeks 11 or 12.
If you choose to disregard this advice, you must still follow the Style Guide. You also may be unable to get help from course staff if you use
features not taught in DP1091.
Reference Implementation
If you have questions about what behaviour your program should exhibit, we have provided a sample solution for you to use.
$ 1091 cspotify
Download the starter code (cspotify.zip) here or copy it to your CSE account using the following command:
$ 1091 setup_cspotify
2021/3/30 DPST1091 21T1 - Assignment 2 - CSpotify
https://cgi.cse.unsw.edu.au/~dp1091/21T1/assignments/ass2/index.html 4/13
Stage One
When you execute your program, you can assume that the Library has already been created for you to perform the following operations.
Stage 1 involves managing the Playlists in your Library as well as printing out the state of the Library. You will need to implement or
modify the following functions:
create_library (This is already implemented for you, you may need to modify it)
add_playlist
print_library
rename_playlist
Add a playlist
In cspotify.c you have been given the function stub (a stub is an unimplemented function):
// Add a new Playlist to the Library.
int add_playlist(Library library, char playlistName[MAX_LEN]) {
return SUCCESS;
}
This function will be given a Library and a Playlist name. You will need to insert a new Playlist node at the end of the linked list of
Playlists in the Library. If the Library has no Playlists, your new Playlist will become the first Playlist in the Library. If this is the case,
you will need to make this Playlist “selected”.
You can assume you will never receive a Playlist name which already exists in the Library
You may receive invalid inputs so the function will return either:
ERROR_INVALID_INPUTS if the given Playlist name is invalid (i.e. not alphanumeric).
SUCCESS if a new Playlist is successfully added.
You will need to create a Playlist node (using malloc) before it is inserted into the Library.
Please note that until you implement the next function in this stage for printing out the Library, you will not be able to see whether your
Playlist has been added successfully into the Library.
Print Out the Library
In cspotify.c you have been given the function stub (a stub is an unimplemented function):
// Print out the Library.
void print_library(Library library) {
}
You will need to use the following helper functions already provided to you in the same file: print_playlist, print_selected_playlist and
print_track.
This function will be given a Library. The function should go through each Playlist in the Library and print out the information in the order
they are in inside the Library. You should use the above helper functions to print the Library out, instead of calling printf yourself. Note
that the word static on these functions will make that function only accessible in the current file. We often use static on helper functions
that are not part of the header file and aren't used by any other parts of the program. static will not significantly change how you will use or
define this function.
Command: A
Example: A RoadTrip
Description: Adds a new Playlist named "Roadtrip" at the end of the Library of Playlists.
The message which appears right after running any command simply acknowledges the function has been called and/or depends on
your return values. It does not necessarily indicate the success of your implementation of this function.
Command: P
Example: P
Description: Prints out the Library.
2021/3/30 DPST1091 21T1 - Assignment 2 - CSpotify
https://cgi.cse.unsw.edu.au/~dp1091/21T1/assignments/ass2/index.html 5/13
You may see that both print_playlist and print_selected_playlist above take in an int number, this is the position in which they are in in
the Library of Playlists assuming that the first Playlist is at position 0.
The function should not return anything.
At this stage, you will only need to use print_playlist and print_selected_playlist to help you print out information in the Library.
print_track is not needed until Stage 2 has been implemented. After implementing stage 2, you should come back and make sure that the
Tracks in each Playlist are also printed out.
Rename a Playlist
In cspotify.c you have been given the function stub (a stub is an unimplemented function):
// Rename the name of an existing Playlist.
int rename_playlist(Library library, char playlistName[MAX_LEN],
char newPlaylistName[MAX_LEN]) {
return SUCCESS;
}
This function will be given a Library, a Playlist name and a new Playlist name. Your task is to find the playlistName in the Library of
Playlists and change its name to the name given in newPlaylistName.
You may receive invalid inputs so the function will return either:
ERROR_NOT_FOUND if the given Playlist name is not found otherwise,
ERROR_INVALID_INPUTS if the new Playlist name is invalid (i.e. not alphanumeric).
SUCCESS if a new Playlist is successfully added.
Stage Two
Stage 2 involves navigating around a Library of Playlists and adding Tracks. You will need to implement the following functions:
select_next_playlist
select_previous_playlist
add_track
playlist_length
Select the Next Playlist
In cspotify.c you have been given the function stub (a stub is an unimplemented function):
// Selects the next Playlist in the Library.
void select_next_playlist(Library library) {

}
This function will be given a Library. In Stage 1, by default the first Playlist added into the Library was selected. For this function, you will
need to change the selected Playlist in the Library to the Playlist after the currently selected Playlist.
If the currently selected Playlist is the last Playlist in the Library, make the first Playlist in the Library become the new selected
Playlist.
The function should not return anything.
Select the Previous Playlist
Command: R
Example: R Roadtrip SleepMusic
Description: Renames the existing Playlist "Roadtrip" to "SleepMusic".
Command: S
Example: S
Description: Selects the next Playlist in the Library.
2021/3/30 DPST1091 21T1 - Assignment 2 - CSpotify
https://cgi.cse.unsw.edu.au/~dp1091/21T1/assignments/ass2/index.html 6/13
In cspotify.c you have been given the function stub (a stub is an unimplemented function):
// Selects the previous Playlist in the Library.
void select_previous_playlist(Library library) {

}
This function is very similar to selecting the next Playlist. Given a Library, you will need to change the Playlist that is selected to the
Playlist before the currently selected Playlist.
If the currently selected Playlist is the first Playlist in the Library, make the last Playlist in the Library become the new selected
Playlist.
The function should not return anything.
Add a Track
In cspotify.c you have been given the function stub (a stub is an unimplemented function):
// Add a new Track to the selected Playlist.
int add_track(Library library, char title[MAX_LEN], char artist[MAX_LEN],
int trackLengthInSec, int position) {
return SUCCESS;
}
This function will be given a Library, Track title, the artist of the Track, the Track length in seconds as well as a position number.
Your task is to go through the selected Playlist and add a new Track node at the position specified by position. If position is 0, the node
should be inserted at the front of the Playlist. If the position has a value equal to the number of Tracks in the Playlist, the node should
be inserted at the end of the Playlist.
It is possible that the same Track can be added to the same Playlist multiple times. You may receive invalid inputs so the function will
return one of the following:
ERROR_NOT_FOUND if there are no Playlists in the Library, otherwise,
ERROR_INVALID_INPUTS if the given title/artist/position/track length is invalid. (see cspotify.h for more details)
SUCCESS if a new Playlist is successfully added.
You will also need to make changes to your print_library function in Stage 1 so that it will now also print out the Tracks you add to a
Playlist.
Calculate the Length of the Playlist
In cspotify.c you have been given the function stub (a stub is an unimplemented function):
// Calculate the total length of the selected Playlist in minutes and seconds.
void playlist_length(Library library, int *playlistMinutes, int *playlistSeconds) {
}
For this function, you are given a Library and two uninitialised int variables passed into the function by reference (i.e. the two int pointers
you receive in this function are pointing to the memory location of two int variables).
Command: W
Example: W
Description: Selects the previous Playlist in the Library.
Command: a

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!