Question

DQuestion 12 2 pts Consider the following declaration: template cclass type> class strange private type a; type b; 冫; . Write

  1. Write a statement that declares sObj to be an object of type strange such that the private member variables a and b are of type int.
  2. Write statement that shows the the declaration in the class strange to overload the operator == as a member function.
  3. Assume that two objects of type strange are equal if their corresponding member variables are equal. Write the definition of the function operator== for the class strange, which is overloaded as a member function.

In c++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ques 1.

// create object of class strange with int as data type

strange<int> ob;

Ques 2.

// overload the == operator

bool operator==(strange<type>& ob);

Ques 3.

bool strange::operator(strange<type>& ob)

{

    // if the class variables are same

    if( ob.a == this->a && ob.b == this->b )

        return true;

    // if the class variables are not same

    else

        return false;

}

Add a comment
Know the answer?
Add Answer to:
Write a statement that declares sObj to be an object of type strange such that the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In c++ Consider the following declaration: class strange { . . . }; Write a statement...

    In c++ Consider the following declaration: class strange { . . . }; Write a statement that shows the declaration in the class strange to overload the operator >>. Write a statement that shows the declaration in the class strange to overload the operator =. Write a statement that shows the declaration in the class strange to overload the binary operator + as a member function. Write a statement that shows the declaration in the class strange to overload the...

  • Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...

    Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a class Employee (with member variables: char * name, int id, and double age). 2. Create a constructor that should be able to take arguments and initialize the member variables. 3. Create a copy constructor for employee class to ensure deep copy. 4. Create a destructor and de allocate the dynamic memory. 5. Overload the assignment operator to prevent shallow copy and ensure deep copy....

  • For the following code, which statement is not true? Class Point {     private:         double...

    For the following code, which statement is not true? Class Point {     private:         double y;         double z;     public:         double x; }; a.z is available to objects of type Point declared outside the class. b.x is available to objects of type Point declared outside the class. c.x, y, and z are called members variables of the class. d.The name of the class is Point. Given the code below, What is the most accurate description of AwesomeClass(AwesomeClass...

  • Multiple Choice Multiple Choice Section 2.1 - 2.2 Introduction to Classes Here is the start of...

    Multiple Choice Multiple Choice Section 2.1 - 2.2 Introduction to Classes Here is the start of a class declaration: class foo { public: void x(foo f); void y(const foo f); void z(foo f) const; ... Which of the three member functions can alter the PRIVATE member variables of the foo object that activates the function? A. Only x can alter the private member variables of the object that activates the function. B. Only y can alter the private member variables...

  • Write a C++ class named CashRegister. The class should have private data members named Hundreds, Tens,...

    Write a C++ class named CashRegister. The class should have private data members named Hundreds, Tens, Fives, and Singles all of type integer. The class should have the following: 1. A member function named GetTotalCash to retrieve the total cash inside the cash register. 2. Overload the + operator to allow adding two objects of type CashRegister (note, add the hundreds to the hundreds, tens to tens and so on). 3. Overload the > operator to compare between two CashRegisters...

  • 1. Write TWO different but equivalent statements to do the same thing: use a for statement...

    1. Write TWO different but equivalent statements to do the same thing: use a for statement to print the elements of array numbers by using pointer ptr. 2. Write an expression that uses ptr to copy element 1 (zero-based) of the array to element 3. Do not use numbers in the array in Here is the start of a class declaration: class foo { public: void x(foo f); void y(const foo f); void z(foo f) const; ... 3. Which of...

  • Design a class named NumDays, to store a value that represents a number of hours and...

    Design a class named NumDays, to store a value that represents a number of hours and convert it to a number of days. For example, 24 hours would be converted to 1 day, 36 hours would be converted to 1.5 days, and 54 hours would be converted to 2.25 days. This class has two private member variables with data type double: one is named as hours; another is named as days. This class has a constructor that accepts a value...

  • C++ myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream» 5 using namespace std; 6 const int SIZE-5; //Stack size 7 //...

    C++ myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream» 5 using namespace std; 6 const int SIZE-5; //Stack size 7 //class declaration 8 class stack Instructions Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same Overload the relational operatorfor the class stackType that returns true if two stacks of the same type are the same; it returns false...

  • Write three object-oriented classes to simulate your own kind of team in which a senior member...

    Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....

  • Java please answer A to I please dont type the answer on paper please use the...

    Java please answer A to I please dont type the answer on paper please use the computer A.   Explain why alpha cannot be accessed by other members of its class. B.   In the program, how can you determine the type of access modifier? C.   Describe the differences and similarities of beta and gamma in program, within the context of access specifiers and class member accessibility. D.   Explain how objects, a and b, are passed to the method. E.    Why...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT