My Assingment is to create this program: Create a class called Musicians to cont
ID: 3890100 • Letter: M
Question
My Assingment is to create this program:
Create a class called Musicians to contain three functions string ( ), wind ( ) and perc ( ).
Each of these functions should initialize a string array to contain the following instruments:
- veena, guitar, sitar, sarod and mandolin under string ( )
- flute, clarinet saxophone, nadhaswaram and piccolo under wind ( )
- tabla, mridangam, bangos, drums and tambour under perc ( )
It should also display the contents of the arrays that are initialized.
Create a derived class called TypeIns to contain a function called get ( ) and show ( ). The get ( ) function must display a means as follows:
Type of instruments to be displayed
a. String instruments
b. ind instruments
c. Percussion instruments
The show ( ) function should display the relevant detail according to our choice. The base class variables must be accessible only to its derived classes.
So Far I have gotten this far and have come up an incomplete program if I could get some help solving this problem that would be great:
#include<iostream>
#include<cstring>
using namespace std;
class Instrument
{
protected:
char info[15][15];
public:
void wind()
{
strcpy(info[0], "Flute");
strcpy(info[1], "Clarinet");
strcpy(info[2], "Sexophone");
strcpy(info[3], "Nadhaswaram");
strcpy(info[4], "Picoolo");
}
void string()
{
strcpy(info[0], "Veena");
strcpy(info[1], "Guitar");
strcpy(info[2], "Sitar");
strcpy(info[3], "Sarod");
strcpy(info[4], "Mandolin");
}
void perc(void)
{
strcpy(info[0], "Tabla");
strcpy(info[1], "Mridangam");
strcpy(info[2], "Bangos");
strcpy(info[3], "Drums");
strcpy(info[4], "Tambour");
}
void build()
{
for(int i=0; i<5; i++)
{
cout << info[i] ;
cout << " " << endl;
}
}
};
class typIns : public Instrument
{
public:
void get()
{
cout<<"A. String Instrument"<<endl;
cout<<"B. Ind Instrument"<<endl;
cout<<"C. Percussion Instrument"<<endl;
}
void build(char build)
{
if(build == 'A' || build == 'a'){
string();
Instrument::build();
}
else if( build == 'B' || build == 'b'){
wind();
Instrument::build();
}
else{
perc();
Instrument::build();
}
}
};
int main()
{
char again;
do {
int a;
typIns b;
b.get();
cout << " Enter the type of Instrument(1, 2, or 3): " << endl;
cin >> a;
b.build(a);
cout << " Would you like to look up other instruments(Y or N): ";
cin >> again;
}
while (again =='y' || again =='Y');
return 0;
}
Explanation / Answer
the code so modified
#include<iostream>
#include<cstring>
using namespace std;
class Instrument
{
protected:
char info[15][15];
public:
void wind()
{
strcpy(info[0], "Flute");
strcpy(info[1], "Clarinet");
strcpy(info[2], "Sexophone");
strcpy(info[3], "Nadhaswaram");
strcpy(info[4], "Picoolo");
}
void string()
{
strcpy(info[0], "Veena");
strcpy(info[1], "Guitar");
strcpy(info[2], "Sitar");
strcpy(info[3], "Sarod");
strcpy(info[4], "Mandolin");
}
void perc(void)
{
strcpy(info[0], "Tabla");
strcpy(info[1], "Mridangam");
strcpy(info[2], "Bangos");
strcpy(info[3], "Drums");
strcpy(info[4], "Tambour");
}
void build()
{
for(int i=0; i<5; i++)
{
cout << info[i] ;
cout << " " << endl;
}
}
};
class typIns : public Instrument
{
public:
void get()
{
cout<<"A. String Instrument"<<endl;
cout<<"B. Ind Instrument"<<endl;
cout<<"C. Percussion Instrument"<<endl;
}
void build(char build)
{
if(build == 'A' || build == 'a'){
string();
Instrument::build();
}
else if( build == 'B' || build == 'b'){
wind();
Instrument::build();
}
else{
perc();
Instrument::build();
}
}
};
int main()
{
char again;
do {
int a;
typIns b;
b.get();
cout << " Enter the type of Instrument(1, 2, or 3): " << endl;
cin >> a;
b.build(a);
cout << " Would you like to look up other instruments(Y or N): ";
cin >> again;
}
while (again =='y' || again =='Y');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.