question archive a class Music, which contains Three data members i

a class Music, which contains Three data members i

Subject:Computer SciencePrice:8.89 Bought3

a class Music, which contains

  • Three data members i.e. songTitle (of string type), singerName (of string type), and singingYear (of integer type)
  • no-argument constructor to initialize all data members with default values i.e. "---""---", and 0, respectively
  • parameterized constructor to initialize all data members with user-defined values
  • Three setter functions to set values for all data members individually

Derive a class named FolkMusic that contains

  • A data field provinceName to hold the name of the province (of string type)
  • no-argument constructor to assign default value as "---" to provinceName
  • four argument constructor to assign user-defined values to songTitlesingerNamesingingYear, and provinceName
  • setter function to set the name of the province
  • A function named show() that displays all data member values of invoking object

a main() function that instantiates objects of FolkMusic class and test the functionality of all its member functions.

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

#include <iostream>
using namespace std;


class Music
{
	public:
		string songTitle;
		string singerName;
		int singingYear;
		
		Music()
		{
			songTitle = "---";
			singerName = "---";
			singingYear =0;
		}
		
		Music(string title, string name, int year)
		{
			songTitle = title;
			singerName = name;
			singingYear = year;
		}
		
		void setSongTitle(string title)
		{
			songTitle  = title;
		}
		
		void setSingerName(string name)
		{
			singerName = name;
		}
		
		void setSingingYear(int year)
		{
			singingYear = year;
		}
};


class FolkMusic: public Music
{
	public:
		string provinceName;
		
		FolkMusic()
		{
			provinceName = "---";
		}
		
		FolkMusic(string title, string name, int year, string province): Music(title, name, year)
		{
			provinceName = province;
		}
		
		void setProvinceName(string province)
		{
			provinceName = province;
		}
		
		void show()
		{
			cout << "Song Title   : "<<songTitle<<endl;
			cout << "Singer Name  : "<<singerName<<endl;
			cout << "Singing Year : "<<singingYear<<endl;
			cout << "Province Name: "<<provinceName;
		}
};


int main()
{
	FolkMusic fMusic("Ours","Taylor Swift",2010,"Alask");
	fMusic.show();
	return 0;
}

 

Please find the above C++ program. It has the Music class and FolkMusic class and main method to test these class.