C++ Programming: Search A Linked List The Content of \"songlist.txt\": Problem 2
ID: 3779748 • Letter: C
Question
C++ Programming: Search A Linked List
The Content of "songlist.txt":
Problem 2: Write a C++ program that searches the playlist (the linked list) for a certain song. There are two functions to be implemented. searchSong ByTitl e and searchSongByArtist. searchSongBy Title will search by song title and print the songs that have the title searchSongBy Artist will search by song artist and print the songs that are sung by the artist. Both functions do not need to return the song pointer and they can have a void return type.Explanation / Answer
#include<iostream>
#include<fstream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
vector<string> slist;
string line1[30];
int choice;
string artist,title;
ifstream myfile("songlist.txt");
int a = 0;
if(!myfile)
{
cout<<"Error opening the output file"<<endl;
return -1;
}
while(!myfile.eof())
{
getline(myfile,line1[a],' ');
slist.push_back(line1[a]);
}
cout<<" Press 1.Find song by title 2.Find song by singer"<<endl;
cin>>choice;
if(choice==1){
cout<<" Please enter the title of the song:";
getline (std::cin,title);
for(int i=0;i<slist.size();i++){
if(title==slist[i])
{
cout<<" Song found....!!!";
cout<<" "<<slist[i];
}
}
}
else if(choice==0){
cout<<" Please enter the artist name for the song:";
getline(cin,artist);
if(artist==slist[i])
{
cout<<" Song found....!!!";
cout<<" "<<slist[i];
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.