Question

In: Computer Science

Use C++ language Create a program which will ask the user to input three songs for...

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.

Solutions

Expert Solution

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:

  • Header files iostream and string have to be included.
  • In the main function create three string variables.
  • Prompt the user to enter the names of songs.
  • Input the name of the songs using the getline function.
  • Using the cout statement, display the names of the songs in the playlist.

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:


Related Solutions

using C language Create a bitwise calculator that ask user for input two input, first int,...
using C language Create a bitwise calculator that ask user for input two input, first int, bitwise operation, second int (i.e 5 & 9) only those bitwise operation are allowed: & ~ ^ | << >>. If user uses wrong operators stop program and ask again. Convert the first int and second int into 8 BITS binary (00000000) and use bitwise operator given by user to either AND, OR, XOR, etc (ie 1001 & 1111)
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
Q1 Create a program that asks the user to input their budget. Then, it will ask...
Q1 Create a program that asks the user to input their budget. Then, it will ask the user to input each of their purchase until their entire budget is used up. What kind of loop do you think is the most appropriate? You don't have to create the entire program. Part of it has already been created for you (see code below). Note: Assume that the user always uses up their budget to the last cent and they don't over...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
(Use C++ language) CREATE A PROGRAM CALLED and or not.cpp THAT: ASKS USER FOR AGE Note:...
(Use C++ language) CREATE A PROGRAM CALLED and or not.cpp THAT: ASKS USER FOR AGE Note: you must be 18 or older to vote && is the symbol for And | | is the symbol for Or ! is the symbol for Not USE AND, OR, OR NOT TO SEE IF THEY'RE OLD ENOUGH TO VOTE and display appropriate message USE AND, OR, OR NOT TO SEE IF THEY ENTERED A NUMBER LESS THAN 0 and display appropriate message USE...
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT