Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I see that some of the code was not copied correctly into my original post. Here

ID: 3634260 • Letter: I

Question

I see that some of the code was not copied correctly into my original post. Here is the correct/complete code.

**********************************************************************************************************
*****Main.cpp******
/******************************************
#include<iostream>
#include<fstream>
#include<string>
#include"LinkedList.h"
#include"Song.h"
using namespace std;

char DisplayMenu();
void LoadSongFile();
void AddNewSong();
void DeleteSong();
void PlaySongs();
void PrintAllSongs();
LinkedList list;

int main()
{
bool terminate = false;
char selection;

while (!terminate)
{
selection = DisplayMenu();

switch(selection)
{
case 'a':
LoadSongFile();
break;
case 'b':
AddNewSong();
break;
case 'c':
DeleteSong();
break;
case 'd':
PlaySongs();
break;
case 'e':
PrintAllSongs();
break;
case 'f':
terminate = true;
break;
default:
cout << "That is not a valid choice! ";
}

}
system("pause");
return 0;
char ch;
do
{
cout << "Please make a selection: ";
cout << "a) Open a song file";
cout << "b) Add a song" << endl;
cout << "c) Delete a song" << endl;
cout << "d) Play a song" << endl;
cout << "e) Print all songs" << endl;
cout << "f) Quit" << endl;
cout << "Enter your option: " << endl;
cin >> ch;

}while(true);
}

void AddNewSong()
{
string fullname;
string path;
string name;
cout<<endl<<"Enter the full song path and name: ";
cin.ignore();
getline(cin, fullname);
int index=fullname.find_last_of('\');
path=fullname.substr(0,index);
name=fullname.substr(index+1);
Song s((char*)name.c_str());
s.SetSongPath((char*)path.c_str());
list.AddLinkToBack(&s);
s.AppendToListFile();
}
void DeleteSong()
{
string nameToDelete;
cout<<endl<<"Enter the song name with extension: ";
cin.ignore();
getline(cin,nameToDelete);
Song s[20];
int len=list.GetListLength();
ifstream fin;
fin.open(Song::songListFile_);
string name;

int count=0;
char t;
cout<<endl;
while(getline(fin,name))
{
int position=name.find_last_of("\");
string path, filename;
path=name.substr(0,position);
filename=name.substr(position+1);
Song temp((char*)filename.c_str());
temp.SetSongPath((char*)path.c_str());
if(nameToDelete!=filename)
s[count++]=temp;
}
list.RemoveLinkFromFront();
fin.close();
ofstream fout;
fout.open(Song::songListFile_);
for(int i=0;i<count;i++)
{
fout<<s[i].GetSongPath()<<"\"<<s[i].GetSongName()<<endl;
}
fout.close();
}
void PlaySongs()
{
string nameToPlay;
cin.ignore();
cout << endl << "Enter the song name with extension: ";
getline(cin, nameToPlay);
Song *s = (Song*)list.GetFirstNode();
ifstream fin;
fin.open(Song::songListFile_);
string name;

int count=0;
char t;
cout<<endl;
while(getline(fin,name))
{
int position=name.find_last_of("\");
string path, filename;
path=name.substr(0,position);
filename=name.substr(position+1);
Song temp((char*)filename.c_str());
temp.SetSongPath((char*)path.c_str());
if(nameToPlay==filename)
{
s->PlaySong();
cout << "Song is playing. " << endl;
return;
}
}
cout<<endl<<"Could not find that song in list!"<<endl;
list.RemoveLinkFromFront();
fin.close();

}
void PrintAllSongs()
{
Song s;
int len=list.GetListLength();
ifstream fin;
fin.open(Song::songListFile_);
string name;

int count=0;
char t;
cout<<endl;
while(getline(fin,name))
{
int position=name.find_last_of("\");
string path, filename;
path=name.substr(0,position);
filename=name.substr(position+1);
Song temp((char*)filename.c_str());
temp.SetSongPath((char*)path.c_str());
list.AddLinkToBack(&temp);
count++;
cout<<filename<<endl;
}
}
void LoadSongFile()
{
Song song;
char file[ENTRY_SZ];
cout<<"Enter the full file path: ";
cin>>file;
//strcpy(file,"songList.txt");
song.SetSongPath(file);
strcpy(Song::songListFile_,file);
ifstream fin;
fin.open(file);
//char name[ENTRY_SZ];
string name;

int count=0;
char t;
while(getline(fin,name))
{
int index=name.find_last_of('\');
string path, filename;
path=name.substr(0,index);
filename=name.substr(index+1);
Song temp((char*)filename.c_str());
temp.SetSongPath((char*)path.c_str());
list.AddLinkToBack(&temp);
count++;
}
cout<<endl<<"Loaded file and read "<<count<<" Song objects."<<endl<<endl;
}
char DisplayMenu()
{
char ch;
do
{
cout << "Welcome to James, Matt, and Arianes MP3 Player" << endl;
cout << "Please make a selection: " << endl;
cout << "a) Open a song file" << endl;
cout << "b) Add a song" << endl;
cout << "c) Delete a song" << endl;
cout << "d) Play a song" << endl;
cout << "e) Print all songs" << endl;
cout << "f) Quit" << endl;
cout << "Enter your option: " << endl;
cin >> ch;
ch=tolower(ch);
if(ch =='a' || ch =='b' || ch =='c' || ch =='d' || ch =='e' || ch =='f')
return ch;
else
cout<<"Invalid choice"<<endl;
}while(true);
}

*****Song.cpp******
#include "Song.h"
#include<Windows.h>
#include<iostream>
#include<fstream>
using namespace std;

char Song::songListFile_[ENTRY_SZ]="";
char Song::currentMP3_[ENTRY_SZ]="";
Song::Song(void)
{
}
Song::Song(char* name)
{
strcpy_s(songName_,name);
}
void Song::SetSongPath(char* path)
{
strcpy_s(songPath_,path);
}
Song::~Song(void)
{
}
const char* Song::GetSongName()
{
return songName_;
}
const char* Song::GetSongPath()
{
return songPath_;
}
void Song::PlaySong()
{
const int BUFF_SZ = 512;
char fullStr[BUFF_SZ];
MCIERROR err;

StopSong();

// Set global variable so we know this file is playing.
// Sandwich the file path in escaped double quotes so
// spaces can be included and don't need to double up
// on the backslashes.
sprintf_s(currentMP3_, ENTRY_SZ, ""%s"", songPath_);
sprintf_s(fullStr, BUFF_SZ,
"open %s type mpegvideo alias myFile", currentMP3_);
err = mciSendString(fullStr, NULL, 0, 0);
err = mciSendString("play myFile", NULL, 0, 0);
}

void Song::StopSong()
{
MCIERROR err;

// Stop any currently playing file
if (currentMP3_[0] != 0)
{
err = mciSendString("stop myFile", NULL, 0, 0);
err = mciSendString("close myFile", NULL, 0, 0);
}
}
void Song::AppendToListFile()
{
ofstream fout;
fout.open(Song::songListFile_,ios::app);
fout<<songPath_<<"\"<<songName_<<endl;
fout.close();
}

*****Song.h*****
#ifndef SONG_H
#define SONG_H

const int ENTRY_SZ = 512;

class Song
{
private:
char songPath_[ENTRY_SZ]; // Contains the full path name
char songName_[ENTRY_SZ]; // Song name extracted from the path

public:

// Store the path name of the song list file
static char songListFile_[ENTRY_SZ];
static char currentMP3_[ENTRY_SZ];

// Static method to empty the song list file
static void ClearListFile();

Song();
Song(char* name);
~Song();
void SetSongPath(char* path);
const char* GetSongPath();
const char* GetSongName();
void AppendToListFile();
void PlaySong();
void StopSong();
};
#endif

****LinkedList.cpp****

// This file contains the linked implementation of class
// LinkedList .cpp

#include "LinkedList.h"
#include <iostream>

LinkedList ::LinkedList () // Class constructor
{
listLen_ = 0;
first_ = NULL;
last_=NULL;
}


long LinkedList ::GetListLength()
// Post: Number of items in the list is returned.
{
return listLen_;
}

void LinkedList ::AddLinkToBack(void* ptr)
// item is in the list; listLen_ has been incremented.
{
Node *temp;
temp=new Node;
temp->data_=ptr;
temp->next_=NULL;
if(first_==NULL)
{
first_=new Node;
last_=new Node;
first_=temp;
last_=temp;
}
else
{
last_->next_ = temp; // Store address of new node into external pointer
last_=last_->next_;
}
listLen_++; // Increment listLen_ of the list
}


void LinkedList ::RemoveLinkFromFront()
{
Node* location = first_;
Node* tempLocation;

// Locate node to be deleted.
tempLocation = location;
first_ = first_->next_; // Delete first node.
delete tempLocation;
listLen_--;
}


Node* LinkedList::GetFirstNode()
{
return first_;
}
LinkedList ::~LinkedList ()
// Post: List is empty; all items have been deallocated.
{
Node* tempPtr;
while (first_ != NULL)
{
tempPtr = first_;
first_ = first_->next_;
delete tempPtr;
}
}

****LinkedList.h*****
// LinkedList .h
#ifndef LINKEDLIST_H
#define LINKEDLIST_H

struct Node
{
void* data_;
Node* next_;
Node* prev_;

Node()
{
data_ = 0;
next_ = 0;
prev_ = 0;
}
};
class LinkedList
{
public:
LinkedList (); // Constructor
~LinkedList (); // Destructor
void AddLinkToBack(void* ptr); // Function: Adds item to list.
void* RemoveThisLink(Node* node);
void RemoveLinkFromFront();
Node* GetFirstNode();
long GetListLength();

private:
Node* first_;
Node* last_;
long listLen_;
};
#endif

Explanation / Answer

Whats your question ?????????????