Question

[COSC29-SLO2+SLO7+SLO8] Write an operator overloading function for the Character class that overloads the !=operator. class
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the solution if you have any doubts then you can write in the comment section.

Please give feedback.

Solution:

Operator overloading for a class means use that operator for class objects.

Here != operator will results in true if both objects have different values of variable v, otherwise, it returns false.

//class Character
class Character
{
    //variable
    char v=0;
    public:
    //constructor
    Character(char v)
    {
        this->v=v;
    }
    //operator overloading of operator !=
    bool operator !=(Character ch)
    {
        /*if both object's variable v are different then return true other wise 
        return false; ch.v because ch is an object.  this->v because this is 
        pointer */
        if(ch.v!=this->v)
        return true;
        else
        return false;
    }
};

Thank You!

Add a comment
Know the answer?
Add Answer to:
[COSC29-SLO2+SLO7+SLO8] Write an operator overloading function for the Character class that overloads the '!='operator. class Character...
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
  • Programming Question 4: Operator Overloading [20 marks] The class SpecialArray represents an arra...

    C++ please Programming Question 4: Operator Overloading [20 marks] The class SpecialArray represents an array of integers. The class contains two data members: array (of type int"), which represents the array of integers, and size (of type int) that represents the size of the array. The class SpecialArray also overloads the following operators: operator: Compares two arrays. An array "A" is smallerhan an array "B" if the size of array "A" is smaller than the size of "B", or if...

  • This problem is considered from C++, I need to know the steps using the step-by-step function...

    This problem is considered from C++, I need to know the steps using the step-by-step function for me to fully understand on how to solve this tough problem. Question 30 10 pts (SHORT ANSWER) Write three separate if blocks to check the following THREE conditions (number your answers): 1. If the number variable testScore is outside the range of O through 100 (excluding both those scores), print the message: "INVALID: OUTSIDE RANGE 0-100" 2. If the number variable bonusPoints is...

  • this for my class SQL language Question 3 10 pts What errors are in the following...

    this for my class SQL language Question 3 10 pts What errors are in the following create statement? CREATE AUTHORS (AUTHOR NUM CHAR(10) PRIMARY KEY, 1ST NAME CHAR(20), LAST NAME CHAR(20), ADDRESS CHAR(100) NOT EMPTY.CITY CHAR(20), STATE CHAR(10), ZIP CHAR(6) HTML Editora B I VA -A I ET 1 1 1 XX, SE - E o N V PRVO T 12pt Question 4 10 pts Write the SQL to add the following customer to the Colonial Adventure Tours The customer...

  • Given two complex numbers, find the sum of the complex numbers using operator overloading. Write an...

    Given two complex numbers, find the sum of the complex numbers using operator overloading. Write an operator overloading function     ProblemSolution operator + (ProblemSolution const &P) which adds two ProblemSolution objects and returns a new ProblemSolution object. Input     12 -10      -34 38     where, Each row is a complex number. First element is real part and the second element is imaginary part of a complex number. Output     -22 28 Two complex numbers are 12-10i and -34+38i. Sum of complex numbers are =...

  • (COSC28-SLO2+SLO8] Given the portion of the class definition below, add a member function called print that...

    (COSC28-SLO2+SLO8] Given the portion of the class definition below, add a member function called print that prints the member variable report and flog. class Log { string report = ""; string flag = ""; public: // constructor Log(string flag) { this->flag = flag; this->report = "Report logged for " + flag; 3 // The print function to be added here 3 I A - IX E 3 7 1 x X, DE - V GT 12pt Paragraph v

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • Given [H30") = 4.65x107M, find the pH. HTML Editor BIVA - A - I E331 XX,...

    Given [H30") = 4.65x107M, find the pH. HTML Editor BIVA - A - I E331 XX, EE Ve v TTK 12pt Р Paragraph O words

  • C++ What would be the proper function prototype of overloading the + operator of a Cat...

    C++ What would be the proper function prototype of overloading the + operator of a Cat class? O const Cat operator+ (Cat right) O const Cat operator+ (const Cat &right) O const Cat ++(const Cat right) O const Cat +-(const Cat &right)

  • In c++ What does operator overloading allow us to do ? Why must the << and...

    In c++ What does operator overloading allow us to do ? Why must the << and the >> operators be overloaded as friend functions instead of member functions, for a user defined class ? What is the difference between an instance member variable and a static member variable ? How are call to static member functions made ? Describe the difference between reading a file using the >> operator and with the getline function What is inheritance What is a...

  • OV Question 8 For the following acid, • write the ionization reaction with water • write...

    OV Question 8 For the following acid, • write the ionization reaction with water • write the Ka expression, include the value of the Ka • Determine the pH of a solution at equilibrium that starts with a concentration of 1.55M of the acid. • Show as much work as you can. You are welcome to upload your written work to the Optional Work Upload quiz posted after this quiz Be sure it is neat and your ID is in...

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