Objective: Implement the storage portion of the tsuPod (pronounced \"su Pod\" -
ID: 3675763 • Letter: O
Question
Objective:
Implement the storage portion of the tsuPod (pronounced "su Pod" - the much smaller version of the iPod). Learn how to use structures.
Specifications:
General design:
The code must be designed to allow the storage of the following data:
up to 8 songs not to exceed 25MB
for each song we will store the title (string), artist (string), and size (int) in MB
the title and artist cannot be blank
the size of each song must be greater than zero
Code design:
you are provided with the tsuPod.h file with prototypes of the functions that you need to define. (Note: some of the prototypes have to be modified for the test code to work correctly)
you have to create file tsuPod.cpp where you define functions specified in tsuPod.h file
you have to edit file test_tsuPod.cpp that tests the functionality of tsuPod
· following variables and structures must be declared in your tsuPod.h or tsuPod.cpp code (Note: in your code 8 songs should be presented by an array of structure variables)
const int NUM_SONGS = 8; /*we will have the maximum 8 slots with some slots being empty /
const int MEMORY_SIZE = 25; /*total memory size of tsuPod in MB*/
struct TsuPod
{
string title;
string artist;
int size;
};
tsuPod.h should be included in both tsuPod.cpp and test_tsuPod.cpp
You must use linux for this project. you need to type “g++ tsuPod.cpp test_tsuPod.cpp” to compile and get the executable file. Note: all code will compiled by the grader under linux on eros.cs.txstate.edu.
Testing:
Edit file test_tsuPod.cpp where you are going to test required functionality of the tsuPod program.
Following storage functionalities have to be tested to receive full grade:
Initialization
Successful song addition
Unsuccessful song addition – failure due to the lack of memory
Unsuccessful song addition – failure due to other reason (ex: no empty slots)
Successful song removal
Unsuccessful song removal – failure because a song with such name was not found
Clearing of the song list
Shuffle functionality – implementation and testing of this function will result in an extra grade.
In your test_tsuPod.cpp explain you what exactly you are testing with each block of code. Examples: test addition of a song to a play list, test shuffling capabilities, etc.
tsuPod.h file and the example of the test_tsuPod.cpp are located in the archive
Explanation / Answer
#include "tsuPod.h"
#include <iostream>
using namespace std;
void initTsuPod (TsuPod songMaker[],int NUM_SONGS, int songCount)
{
for(int j =0; j < NUM_SONGS; j++)
{
songMaker[j].title = "";
songMaker[j].artist ="";
songMaker[j].size =0;
}
songCount = 0;
}
int addSong (float &memory,TsuPod songMaker[], string newTitle, string newArtist, int size, int MEMORY_SIZE,int songCount)
{
if (memory + size <= MEMORY_SIZE && newTitle != "" && newArtist != "")
{
songMaker[songCount].title = newTitle;
cout << songMaker[songCount].title << endl;
songMaker[songCount].artist = newArtist;
cout << songMaker[songCount].artist << endl;
songMaker[songCount].size = size;
cout << songMaker[songCount].size << endl;
memory -= size;
cout << memory << endl;
songCount++;
cout << songCount << endl;
return 0;
}
else if (memory + size > MEMORY_SIZE)
{
return -1;
}
else
{
return -2;
}
}
int removeSong(float &memory,TsuPod songMaker[], string newTitle, int songCount)
{
int count =0;
while(newTitle != songMaker[count].title)
{
if(count == songCount)
return -1;
else
count ++;
}
for (;count<songCount; count++)
{
songMaker[count] = songMaker[count+1];
}
songCount--;
}
void clearMemory(float &memory,TsuPod songMaker, int songCount )
{
songCount =0;
}
void showSongList (TsuPod songMaker[], int songCount)
{
for(int i =0; i<songCount; i++)
{
cout << songMaker[i].title << endl;
cout << songMaker[i].artist << endl;
cout << songMaker[i].size << endl;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.