answersLogoWhite

0


Best Answer

#include<iostream.h>

#include<conio.h>

class num

{

private:

int a,b,c,d;

publ;ic:

num(int j,int k,int m,int l)

{

a=j;

b=k;

c=m;

d=l;

}

void show(void);

void operator++();

};

void num::show()

{

cout<<...................................................................

}

void num::operator++()

{++a;++b;++c;++d;

}

main()

{

clrscr();

num X(3,2,5,7);

cout<<"b4 inc of x";

X.show();

++X;

cout<<"after inc of x";

X.show();

return 0;

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

class myclass {

public:

myclass& operator++(); // preincrement

myclass& operator++(int); postincrement

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to overload preincrement and postincrement operator?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why is it necessary to overload an operator?

The assignment is done explicit without internal operation. Subject to the programming language, explicit assignment operators are needed wherever implicit ones are insufficient. Implicit assignment is typically implemented as a flat copy, while explicit overloading of the assignment operator allows for any other suitable behavior. Consider this example in pseudocode similar to C++: class Demo { int* valuepointer; ... }; Demo a, b; ... b = a; Assigning a to b using implicit assignment means that a.valuepointer and b.valuepointer share the same value. Both a and b can change the pointed-to value, and the either will "see" the change. This is the required behavior in some cases, but often, you'd want to explicitly assign a to b such that each has its own pointer, accessing different copies of the value. This behavior would require an explicit assignment operator (or copy constructor).


C plus plus program for overloading operator?

#include&lt;iostream&gt; #include&lt;string&gt; // a simple class class my_class { private: std::string m_caption; public: // default constructor my_class (std::string caption): m_caption (caption) {} // read-only accessor const std::string&amp; get_caption() const { return m_caption; } }; // output stream insertion operator overload std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const my_class&amp; obj) { os &lt;&lt; obj.get_caption(); return os; } int main() { // call default constructor my_class object1 ("This is the caption for object1"); // exercise output stream insertion operator overload std::cout &lt;&lt; object1 &lt;&lt; std::endl; }


C program to implement arithmetic assignment operator?

y=2x2+3x+1


How can user defined operator overloading harm the readability of the program?

Because the built in operator has the precision and compiler knows all the precision between the operators, and it works on that precision. User can also create its own operator but the compiler does not come to know thow to make precision of this operator. Therefore we dont use user defined operator


When the Java Virtual Machine sees the new operator in a program it instantiates an object for a specified class.?

Yes.

Related questions

Is buffer overload a computer virus?

No, a buffer overload is not a computer virus. A buffer overload is an error that occurs when a program on your computer is writing data to a buffer and exceeds the buffer's capacity. This can cause problems and will usually cause the program which caused the buffer overload to crash.


What is the first step one should take when determining the amount of overload to include in an exercise program?

There are a few ways to determine what is overload on an exercise program. When a person starts to feel very sick they should cease the program.


Why is it necessary to overload an operator?

The assignment is done explicit without internal operation. Subject to the programming language, explicit assignment operators are needed wherever implicit ones are insufficient. Implicit assignment is typically implemented as a flat copy, while explicit overloading of the assignment operator allows for any other suitable behavior. Consider this example in pseudocode similar to C++: class Demo { int* valuepointer; ... }; Demo a, b; ... b = a; Assigning a to b using implicit assignment means that a.valuepointer and b.valuepointer share the same value. Both a and b can change the pointed-to value, and the either will "see" the change. This is the required behavior in some cases, but often, you'd want to explicitly assign a to b such that each has its own pointer, accessing different copies of the value. This behavior would require an explicit assignment operator (or copy constructor).


C plus plus program for overloading operator?

#include&lt;iostream&gt; #include&lt;string&gt; // a simple class class my_class { private: std::string m_caption; public: // default constructor my_class (std::string caption): m_caption (caption) {} // read-only accessor const std::string&amp; get_caption() const { return m_caption; } }; // output stream insertion operator overload std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const my_class&amp; obj) { os &lt;&lt; obj.get_caption(); return os; } int main() { // call default constructor my_class object1 ("This is the caption for object1"); // exercise output stream insertion operator overload std::cout &lt;&lt; object1 &lt;&lt; std::endl; }


How can you download c compiler?

write a c program to fine largest/smallest of 3no (using ?:ternary operator/conditional operator)


Which term is defined as part of a resistance training program that gradually increases the stress placed on t?

Variation (Based on Educere Schooling Website)


What is the order of precedence with regard to the operator used in embedded C program?

Operator precedence in embedded C is exactly the same as in standard C.


Part of a resistance training program that gradually increases the stress placed on the body during training?

progressive overload


How do you solve central difference in Matlab?

Possibly the Program Stepping Operator by Matlab.


What are the three components of the FITT acronym associated with overload and progression?

The three components of F.I.T.T. acronym associated with overload and progression are "Frequency, Intensity, and Time." These elements can make or break the success of an individuals fitness program.


What fitness program is a good example of regularity without overload?

There are quite a few fitness programs that are great examples for regularity without overload. One is jogging a few miles once every couple of days.


How can you create a file called history by using a redirection operator?

somecommand > historywhere somecommand is the program that normally prints to stdout. The redirection operator is the > symbol.