The TuneShare type maintains al the information. It isessentially an array of pointers to User types. Each User has aname, an online status and an array of pointers to Songs that thisuser currently has on his/her computer. The Song type simplymaintains a

匿名用户 最后更新于 2021-11-29 17:10 计算机类Computing

The TuneShare type maintains al the information. It isessentially an array of pointers to User types. Each User has aname, an online status and an array of pointers to Songs that thisuser currently has on his/her computer. The Song type simplymaintains a title, artist and duration (in seconds). Download thetuneShare.c program. It contains the struct definitions, somelimits (i.e., maximum number of users, maximum number of songs thata user can have and the maximum number of separate song artists)and some testing code. You MUST write the following functions andprocedures (you can add additional functions and procedures if youwant):

tuneShare.c

#include
#include
#include


#define MAX_SONGS_PER_USER 10
#define MAX_USERS 5
#define MAX_ARTISTS 100


#define NUM_TEST_USERS 7


// This struct represents a song in the system
typedef struct {
char *title;
char *artist;
short int duration;
} Song;

// This struct represents a user in the system
typedef struct {
char *name;
char online; // 1 = YES, 0 = NO
Song *songs[MAX_SONGS_PER_USER]; // songs this userhas
short int numSongs; // numberof songs this user has
} User;

// This structure represents the Tune Share system
typedef struct {
User *users[MAX_USERS]; // An array of all registered users
short int numUsers;
} TuneShare;

/* ADD ALL YOUR FUNCTIONS HERE */


// DO NOT MODIFY THE MAIN FUNCTION
int main() {
// This is test data
static char *TITLES[] = {"Back 2 Life", "LonelinessFor Love", "Desire 126", "Perfect", "In My Head",
"Old Skool Love", "Let's Go", "No Place", "WeGotta Go", "How You Get the Girl",
"Catch", "Here Tonight", "Details", "Dangerous","Brighter Than the Sun",
"Photograph", "Thinking Out Loud", "If HeavenWere to Fall", "I Just Wanna Be With You",
"Song Sung Blue", "Outta Style", "Why", };

static char *ARTISTS[] = {"E-Type", "Lovely the Band","Hollerado", "Ed Sheeran", "Ryland James",
"Divine Brown", "Group 1 Crew", "BackstreetBoys", "E-Type", "Taylor Swift",
"Brett Young", "Brett Young", "BillyCurrington", "Kardinal Offichall",
"Colbie Caillat", "Ed Sheeran", "Ed Sheeran","E-Type", "E-Type", "Neil Diamond",
"Aaron Watson", "Frankie Avalon", };

static int DURATIONS[] = {217, 237, 187, 263, 205,204, 256, 179, 213, 247, 196,
216, 201, 251, 231, 202, 281,223, 230, 185, 222, 161};


static char *TEST_USER_NAMES[NUM_TEST_USERS] = {"DiscoStew", "Peter Punk", "Country Candy", "Ronnie Rocker",
"Sleeping Sam", "Disco Stew", "MellowMarvin"};

static int LIST_SIZES[NUM_TEST_USERS] = {7, 9, 9,5, 1, 0, 0};
static intSONGNUMS[NUM_TEST_USERS][MAX_SONGS_PER_USER] = {
{1, 2, 4, 5, 12, 15, 21}, {0,1, 3, 8, 9, 13, 14, 17, 20},
{6, 7, 8, 10, 11, 12, 13, 20,21}, {0, 8, 16, 17, 18}, {19}, {}, {}};


// Create the TuneShare Center
TuneShare tuneShareCenter;
tuneShareCenter.numUsers = 0;

// Attempt to register all test users
for (int i=0; i if(!registerUser(&tuneShareCenter, TEST_USER_NAMES[i]))
printf("Erroradding User: \"%s\"\n", TEST_USER_NAMES[i]);
else
printf("User:\"%s\" has been registered\n", TEST_USER_NAMES[i]);
}

// Display some stats
displayStats(&tuneShareCenter);

// Log on a user
printf("\nLogging on a user...\n");
logon(&tuneShareCenter, "Disco Stew");

// Display some stats
displayStats(&tuneShareCenter);

// Now add all the test songs for these testusers
for (int i=0; i for (int j=0; j addSong(tuneShareCenter.users[i], TITLES[SONGNUMS[i][j]],ARTISTS[SONGNUMS[i][j]], DURATIONS[SONGNUMS[i][j]]);
}

// Display some stats
displayStats(&tuneShareCenter);

// Display all songs by E-Type
printf("Available Songs By E-Type: \n");
displayAvailableSongsByArtist(&tuneShareCenter,"E-Type");


shutDown(&tuneShareCenter);
}

. A userWithName(TuneShare *t, char *name) function that finds and returns a pointer to the User with the given name in the given TuneShare. It should return NULL if the name does not match a registered user. A logon(Tune Share *t, char *name) function, that puts the User with the given name online. You MUST make use of the userWithName() function above. A logoff(TuneShare *t, char *name) function that puts the User with the given name offline. You MUST make use of the userWithName() function above. A display Available SongsBy Artist(TuneShare *t, char *artist) procedure that displays a list of all songs that are currently available (i.e., downloadable) by the given artist. If there are no songs available by that artist, then NONE should be displayed. A getSong(TuneShare *t, char *title, char *ownerName) function that returns a Song pointer pointing to the Song with the given title from the User with the given ownerName. It MUST make use of the userWithName() function. If the user is not valid or not online, NULL should be returned. A download Song(TuneShare *t, char *download ToName, char *title, char *download FromName) procedure that causes the song with the given title to be downloaded from the user with the given downloadFromName to the user with the given downloadToName. It MUST make use of the user WithName() and getSong() functions. If either user is offline or non-existent ... or if the song does not exist, then the procedure does nothing. Otherwise, a copy of the song should be added to the user with the downloadToName. A display Royalties(TuneShare *t) procedure that displays the royalties for all artists who have had at least one of their songs downloaded. It should display the royalty amount as well as the artist name as follows: $ $ $ 0.50 Neil Diamond 0.25 Ryland James 0.75 E-Type The royalties are calculated as $0.25 per downloaded song. You can assume that there are at most MAX_ARTISTS artists at any time in the collection of songs. You will need to find a way to keep track of the download information so that you can compute the royalties. You may “add to” the data types or define your own, but you MAY NOT “alter” the existing attributes of the data types that were given to you. A shutdown(TuneShare *t) procedure that logs all online users off and does any necessary cleanup (It is your decision as to what code to write for this, if any) before shutting down the TuneShare center.

已邀请: