A
arnuld
this is the most unclear and messy exercise i have ever seen. i am not
able to to write up even single line of solution. her eis what i have
tried:
/* C++ Primer - 4/e
*
* Chapter 7, exercise 7.31
* STATEMENT
* Sales_item class is given. add 2 new public members add to read and
write Sales_item objects. these public members should do the
transactions like the input and output operators of standard library.
*
* SOLUTION IDEA
* author wants us to overload the default input and output operators
*
*/
#include <iostream>
#include <string>
/* Default Sales_item class.
the purpose of Sales_item is to store an ISBN and keep track of the number
of copies sold, revenue and average sales price for that book. class
Sales_item {
public:
// operations on Sales_item objects
double avg_price() const;
bool same_isbn( const Sales_item& rsi ) const {
return isbn == rsi.isbn;
}
private:
std::string isbn;
unsigned units_sold;
double revenue;
};
// member funtion defined outside of class
double Sales_item::avg_price() const
{
if( units_sold )
{
return revenue/units_sold;
}
else
{
return 0;
}
}
*/
/* my own Slaes_item Class */
class Sales_item {
public:
/* operations on Sales_item objects */
double avg_price() const;
bool same_isbn( const Sales_item& rsio ) const {
return isbn == rsio.isbn;
}
/* new output operator */
void <<( const Sales_item& rsio ) const;
/* new input operator */
void >>( const Sales_item& rsio ) const;
private:
std::string isbn;
unsigned units_sold;
double revenue;
};
inline double Sales_item::avg_price() const
{
if( units_sold )
{
return revenue/units_sold;
}
else
{
return 0;
}
}
inline void Sales_item::<<( const Sales_item& rsio )
{
/* i cannot think of anything */
}
int main()
{
Sales_item sales_obj;
return 0;
}
able to to write up even single line of solution. her eis what i have
tried:
/* C++ Primer - 4/e
*
* Chapter 7, exercise 7.31
* STATEMENT
* Sales_item class is given. add 2 new public members add to read and
write Sales_item objects. these public members should do the
transactions like the input and output operators of standard library.
*
* SOLUTION IDEA
* author wants us to overload the default input and output operators
*
*/
#include <iostream>
#include <string>
/* Default Sales_item class.
the purpose of Sales_item is to store an ISBN and keep track of the number
of copies sold, revenue and average sales price for that book. class
Sales_item {
public:
// operations on Sales_item objects
double avg_price() const;
bool same_isbn( const Sales_item& rsi ) const {
return isbn == rsi.isbn;
}
private:
std::string isbn;
unsigned units_sold;
double revenue;
};
// member funtion defined outside of class
double Sales_item::avg_price() const
{
if( units_sold )
{
return revenue/units_sold;
}
else
{
return 0;
}
}
*/
/* my own Slaes_item Class */
class Sales_item {
public:
/* operations on Sales_item objects */
double avg_price() const;
bool same_isbn( const Sales_item& rsio ) const {
return isbn == rsio.isbn;
}
/* new output operator */
void <<( const Sales_item& rsio ) const;
/* new input operator */
void >>( const Sales_item& rsio ) const;
private:
std::string isbn;
unsigned units_sold;
double revenue;
};
inline double Sales_item::avg_price() const
{
if( units_sold )
{
return revenue/units_sold;
}
else
{
return 0;
}
}
inline void Sales_item::<<( const Sales_item& rsio )
{
/* i cannot think of anything */
}
int main()
{
Sales_item sales_obj;
return 0;
}