how to overload << and >> operator in c++
Answers were Sorted based on User's Feedback
Answer / manav sharma
class chocoBox {
private:
int pieCount;
float boxPrice;
public:
// By giving default arguments, const acts like
// 0, 1 and 2 argument contructor
myClass(int pCount = 10, float bPrice = 20.0)
: pieCount(pCount), boxPrice(bPrice)
{ }
int getPieCount() { return pieCount; }
float getBoxPrice() { return boxPrice; }
void setPieCount(int pc) { pieCount = pc; }
void setBoxPrice(float bp) {boxPrice = bp; }
};
/* Lets overload the operator << of ostream class. We will
return a reference of ostream class for cascading calls
e.g. cout<<obj1<<obj2
*/
ostream& operator<< (ostream &stream, const myClass &obj)
{
stream<<obj.GetPieCount<<" "<<obj.GetBoxPrice<<endl;
return (stream);
}
| Is This Answer Correct ? | 5 Yes | 0 No |
Answer / abed
in c++ << and >> overloaded as the insertion and out put
symbole
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / ramya
"<<" this inserssion perrator is used for output the
messages&values
">>"this exsersition operator is used for input the values
sentax:
return_type operator op(arguments_list)
{
----
----
}
| Is This Answer Correct ? | 1 Yes | 0 No |
tell about sorted linked list
if x<>=z then statement end what is the cyclomatic complexity
what is a template?
2 Answers Amazon, BITS, IBS, Wipro,
write a program to convert a decimal number in to its equivalent binary number?
#define CUBE(x) (x*x*x) main() { int a,b=3; a=cube(b++); printf("%d %d",a,b); } What should be the value of a and b? My calc a=4 but syst a=6 how pls tell me if you know it?
What is the stl, standard template library?
write a program to demonstrate,how constructor and deconstructor work under multilevel inheritance
sir please send me bpcl previous question papers
0 Answers BPCL Bharat Petroleum,
what is an algorithm in terms of STL?
what is compiler?
What two types of containers does the stl provide?
How can you create a bulleted list, numbered list and an outline by using bullets and numbering command. Explain with the help of example.