In: Computer Science
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Song{
public:
Song(); //default constructor
Song(string t, string a, double d); //parametrized constructor
string getTitle()const; // return title
string getAuthor()const; // return author
double getDurationMin() const; // return duration in minutes
double getDurationSec() const; // return song's duration in seconds
void setTitle(string t); //set title to t
void setAuthor(string a); //set author to a
void setDurationMin(double d); //set durationMin to d
private:
string title; //title of the song
string author; //author of the song
double durationMin; //duration in minutes
};
Song::Song(){
title ="";
author = "";
durationMin = 0;
}
Song::Song(string t, string a, double d){
//complete your code here for Task2
//the parameter t is for title, a is for author and d is for durationMin
}
string Song::getTitle()const{
//complete your code here for Task3
}
string Song::getAuthor()const{
return author;
}
double Song::getDurationMin()const{
return durationMin;
}
double Song::getDurationSec()const{
//complete your code here for Task4
//return the duration of the song in seconds
}
//complete the code for three member functions for Task5
// void setTitle(string t); //set title to t
// void setAuthor(string a); //set author to a
// void setDurationMin(double d); //set durationMin to d
C++ PROGRAM
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Song{
public:Song(); //default constructor
Song(string t, string a, double d); //parametrized
constructor
string getTitle()const; // return title
string getAuthor()const; // return author
double getDurationMin() const; // return duration in minutes
double getDurationSec() const; // return song's duration in
seconds
void setTitle(string t); //set title to t
void setAuthor(string a); //set author to a
void setDurationMin(double d); //set durationMin to d
private:string title; //title of the song
string author; //author of the song
double durationMin; //duration in minutes
};
Song::Song(){ //default constructor
title ="";
author = "";
durationMin = 0;
}
Song::Song(string t, string a, double d){ //parametrized
constructor
setTitle(t);
setAuthor(a);
setDurationMin(d);
}
string Song::getTitle()const{ //get title
return title;
}
string Song::getAuthor()const{ //get author
return author;
}
double Song::getDurationMin()const{ //get durationMin
return durationMin;
}
double Song::getDurationSec()const{ //get durationSin
return durationMin * 60;
}
void Song::setTitle(string t){ //set title to t
title=t;
}
void Song::setAuthor(string a){ //set author to a
author=a;
}
void Song::setDurationMin(double d){ //set durationMin to d
durationMin=d;
}
int main(){ //main
Song s1("ABC","XYZ",10); //object s1
cout<<"\nTitle: "<<s1.getTitle(); //call function
getTitle()
cout<<"\nAuthor: "<<s1.getAuthor();//call function
getAuthor()
cout<<"\nDuration(min): "<<s1.getDurationMin();//call
function getDurationMin()
cout<<"\nDuration(sec): "<<s1.getDurationSec();//call
function getDurationSec()
}
OUTPUT