Question

In: Computer Science

6. Assignment Instructions: Please respond with at least 100 words. Your initial post should address each...

6.

Assignment Instructions:

Please respond with at least 100 words. Your initial post should address each of the topic below thoughtfully.

Topic: Do you think there might be a way to directly access commonly used operators, such as the arithmetic operators or the stream operators, with enumeration types. For example, would overloading these operators be a good solution? Why or why not?

Solutions

Expert Solution

Step(1)

What is Operator overloding.........???

Operator overloading allows C/C++ operators to have user-defined meanings on user-defined types (classes). Overloaded operators are syntactic sugar for function calls.

Or we can also Say

In C++, we can make operators to work for user defined classes. This means C++ has the ability to provide the operators with a special meaning for a data type, this ability is known as operator overloading.
For example, we can overload an operator ‘+’ in a class like String so that we can concatenate two strings by just using +.
Other example classes where arithmetic operators may be overloaded are Complex Number, Fractional Number, Big Integer, etc.

Step(2)

Operator overloding of "+" oprator

#include <iostream>

using namespace std;

class A

{

  int x;

      public:

      A(){}

A(int i)

{

x=i;

}

    void operator+(A);

    void display();

};

void A :: operator+(A a)

{

    

    int m = x+a.x;

    cout<<"The result of the addition of two objects is : "<<m;

}

int main()

{

    A a1(5);

    A a2(4);

    a1+a2;

    return 0;

}

Output

The result of the addition of two objects is : 9 

Step(3)

let's Discuss your Question

Operator or fumction overloads have No effect on performance, whatsoever. Overload resolution is done at compile time. Overloading won't cause any drop in execution speeds. This person may have been confusing virtual functions, which are typically implemented with a pointer indirection.

And it also reduces documentation complexity. Programmer uses the memory in better way and it is easier for him to trace the function by its name. programmer got the advantage of defining the near similar functionality with the same name.

I tihink There is no real downside to it other than losing short-circuiting on logical operators, at least in C++.

As long as it follows the expected behavior of the operator, overloads don't cause any problems. Operator overloading is just syntatic sugar for a function call. There is nothing magical about it. It just makes some code more idiomatic.

IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK YOU!!!!!!!!----------


Related Solutions

Assignment Instructions: Please respond with at least 100 words. Your initial post should address each of...
Assignment Instructions: Please respond with at least 100 words. Your initial post should address each of the topic below thoughtfully. Topic: Many companies use internal programs that were implemented before object-oriented programming came into widespread use. What are the issues involved in moving their systems to an object-oriented approach?
8. Assignment Instructions: Please respond with at least 100 words. Your initial post should address each...
8. Assignment Instructions: Please respond with at least 100 words. Your initial post should address each of the topic below thoughtfully. Topic: What do you think some of the relevant issues to consider when determining whether to use protected or private members in a base class. Are there any risks involved with using the protected member access specifier instead of the private member access specifier?
4. Assignment Instructions: Please respond with at least 100 words. Your initial post should address each...
4. Assignment Instructions: Please respond with at least 100 words. Your initial post should address each of the topic below thoughtfully. Topic: What are some ways to prevent out of bounds errors when reading input into C-strings?
5. Assignment Instructions: Please respond with at least 100 words. Your initial post should address each...
5. Assignment Instructions: Please respond with at least 100 words. Your initial post should address each of the topic below thoughtfully. Topic: With the advent of object-oriented programming, is it ever necessary to use C-type structs rather than classes? If so, when? What are the advantages or disadvantages of each approach?
Please respond to the discussion post 1 and 2 in your own words: (Must respond to...
Please respond to the discussion post 1 and 2 in your own words: (Must respond to both) Discussion post 1 How do you think most people see the majority of human interactions, as opportunities to compete or to cooperate? I believe that the majority of human interactions are seen as opportunities to compete. The reason I say this is the competitive nature that we have in us as humans. This nature is exemplified daily in our school and our work....
Please respond to the discussion post 1 and 2 in your own words: (Must respond to...
Please respond to the discussion post 1 and 2 in your own words: (Must respond to both) Discussion post 1 Organize and review all your work-to-date. What stands out to you that is potentially of strategic relevance? Think in particular about how your organization is, or can be, or should be different!How will being (more) different in this way potentially create competitive advantages for the organization? Is this a matter of completely reinventing the organization or of enabling it to...
Address all of the following as your Main Post, using at least 250 words: What is...
Address all of the following as your Main Post, using at least 250 words: What is a job order cost system? Describe how you think a job order cost system might be used for professional service businesses. Describe factory overhead costs and give one example of an overhead cost. Lastly, write about one definition or additional concept related to job order costing
In 2-3 paragraphs, respond to the following. Your initial post should be substantive and be supported...
In 2-3 paragraphs, respond to the following. Your initial post should be substantive and be supported by course concepts. Your initial post is due by Wednesday to allow other students to respond. Should the United States government be required to have a balanced budget? What are the long-term implications of continued government indebtedness? cite references.
In 2-3 paragraphs, respond to the following. Your initial post should be substantive and be supported...
In 2-3 paragraphs, respond to the following. Your initial post should be substantive and be supported by course concepts. Your initial post is due by Wednesday to allow other students to respond. How will an understanding of macroeconomics affect your daily life?
In 2-3 paragraphs, respond to the following. Your initial post should be substantive and be supported...
In 2-3 paragraphs, respond to the following. Your initial post should be substantive and be supported by course concepts. Your initial post is due by Wednesday to allow other students to respond. Should we, as Americans, be concerned with the economies and standard of living of other countries? Explain your reasoning using course concepts.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT