Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include using namespace std; //class inteface for template, Holder template class Holder { T data; public: void dataInput(); void dataOutput(); }; //Class implementation for
#include
#include
using namespace std;
//class inteface for template, Holder
template
class Holder
{
T data;
public:
void dataInput();
void dataOutput();
};
//Class implementation for class template, Holder
template
void Holder ::dataInput()
{
cout
cin>>data;
}
template
void Holder::dataOutput()
{
cout
cout
}
//Class Interfaces for Item and Food
class Item
{
private:
int num;
double price;
public:
friend ostream& operator
friend istream& operator>>(istream&, Item&);
};
class Food
{
private:
int fatGrams;
int calories;
public:
friend ostream& operator
friend istream& operator>>(istream&, Food&);
};
int main()
{
Holder num;
Holder- anItem;
Holder goody;
cout
num.dataInput();
cout
anItem.dataInput();
cout
goody.dataInput();
cout
num.dataOutput();
cout
anItem.dataOutput();
goody.dataOutput();
return 0;
}
//Class Implementation for Item and Food
ostream& operator
{
out
return out;
}
istream& operator>>(istream& in, Item& a)
{
cout
in >> a.num;
cout
in >> a.price;
return in;
}
ostream& operator
{
out
return out;
}
istream& operator>>(istream& in, Food& a)
{
cout
in >> a.fatGrams;
cout
in >> a.calories;
return in;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started