In: Computer Science
Use C++ language Create a program which will ask the user to input three songs for a playlist (you may use TV shows or movies, if you prefer). Declare three strings to store each of the songs. Use getline to receive the input. Display output which lists each of the songs (or movies or tv shows), on separate lines, with a title on the first line: My Playlist. Insert three lines of comments at the beginning of the program for your name, today's date, and my playlist on the third line.
The program can be designed using the getline function.
The getline function is used for input of the strings until a new line is encountered. This helps in taking multiple words as input instead of just a single word.
Syntax:
getline(cin, variable_name)
The following steps are required for writing the program:
The C++ program is as follows:
#include <iostream>
#include <string>
using namespace std;
int main()
{
//variables for storing the name of the songs
string s1,s2,s3;
//input the first song
cout<<"Enter the first song name:\n";
getline(cin,s1);
//input the second song
cout<<"Enter the second song name:\n";
getline(cin,s2);
//input the third song
cout<<"Enter the third song name:\n";
getline(cin,s3);
//output all the songs
cout<<"\n MY PLAYLIST\n";
cout<<"1."<<s1<<endl;
cout<<"2."<<s2<<endl;
cout<<"3."<<s3;
}
Sample output: