In: Computer Science
Write a C++ program that design a class
definition to be put in
a header file called fizzjazz.h A store sells online FizzJazz
which are sound tones made by famous bands. For each
FizzJazz,
the store wants to keep track of the following attributes:
* title - the name of the sound tone
* band - Famous band name that created the tone
* duration - this is in seconds and may be fractional:
examples: 20.0, 34.5
Each attribute will have a corresponding getter(accessor)
function or setter(mutator) function. PLEASE PUT ONLY
FUNCTION PROTOTYPES IN YOUR CLASS; DO NOT ADD ANY FUNCTION
IMPLEMENTATION CODE. These would normally be put into
a.cpp
file which you do not need to provide.
Also remember to add a default constructor as well as a
constructor
that takes the attributes.
Thanks for the question.
Here is the completed code for this problem. Comments are included,
go through it, learn how things work and let me know if you have
any doubts or if you need anything to change. If you are satisfied
with the solution, please rate the answer. Thanks!
===========================================================================
#ifndef FIZZJAZZ_H
#define FIZZJAZZ_H
#include<string>
using std::string;
class FizzJazz
{
public:
//default constructor
FizzJazz();
// parameterized constructor
FizzJazz(string title, string band,
double duration);
// Each attribute will have a
corresponding getter(accessor)
string getTitle() const;
string getBand() const;
double getDuration() const;
// function or setter(mutator)
function
void setTitle(string val);
void setBand(string val);
void setDuration(double val);
private:
string title;
string band;
double duration;
};
#endif
===================================================================
#include "FizzJazz.h"
#include<string>
using std::string;
//default constructor
FizzJazz::FizzJazz(): title(""), band(""), duration(0.0) {
}
// parameterized constructor
FizzJazz::FizzJazz(string title, string band, double
duration)
: title(title), band(band), duration(duration) {
}
// Each attribute will have a corresponding
getter(accessor)
string FizzJazz::getTitle() const {return title;}
string FizzJazz::getBand() const{return band;}
double FizzJazz::getDuration() const{return duration;}
// function or setter(mutator) function
void FizzJazz::setTitle(string val){title = val;}
void FizzJazz::setBand(string val){band = val;}
void FizzJazz::setDuration(double val){duration =
val;}
===================================================================
#include <iostream>
#include "FizzJazz.h"
#include<string>
using namespace std;
int main() {
FizzJazz fizz("Coca Cola","Pepsi",5.67);
cout<<fizz.getTitle()<<endl;
cout<<fizz.getBand()<<endl;
cout<<fizz.getDuration()<<endl;
return 0;
}
===================================================================