I have instantiated an object with arguments( string, float, float)
The two floating numbers are initialized using the constructor but when I display my object using my print function instead of getting the two floating numbers I entered, I get 0.00 for each.
#ifndef Publication_H
#define Publication_H
#include <string>
using std::string;
class Publication
{
public:
Publication( const string &, float = 0.00 );
void setBookTitle( const string & ); //function to set book's title
string getBookTitle() const; // function to retrieve book's title
void setBookPrice( const float ); // function to set book's price
float getBookPrice() const; // function to retrieve book's price
void print() const;
private:
string bookTitle;
float bookPrice;
};
#endif
#include <iostream>
using std::cout;
using std::endl;
#include "Publication.h"
Publication::Publication( const string &title, float price)
: bookTitle( title )
{
setBookPrice( price );
}
void Publication::setBookTitle(const string &title )
{
bookTitle = title;
}
string Publication::getBookTitle() const
{
return bookTitle;
}
void Publication::setBookPrice( const float price )
{
bookPrice = ( price > 0.00 ) ? 0.00 : price;
}
float Publication::getBookPrice() const
{
return bookPrice;
}
void Publication::print() const
{
cout << "Wayman Publishing\n Books in Circulation:"
<< "\nTitle: " << getBookTitle() << "\nPrice: "<< "$" << getBookPrice() << endl;
}
Notice here I instantiate Tape audio( "Lord of the Rings", 19.95, 246.50 ); but the 19.95 and 246.50 display 0.00
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
#include <iomanip>
using std::setprecision;
#include "book.h"
#include "tape.h"
int main()
{
Tape audio( "Lord of the Rings", 19.95, 246.50 );
Book book1( "Terrorism in the Air", 64.99, 343);
cout << fixed << setprecision( 2 );
audio.setBookPrice( 19.95 );
audio.setPlayingTime( 261.15 );
audio.print();
book1.print();
}