answersLogoWhite

0

#include

#include

class A

{

public:

A(std::string desc,double price):m_desc(desc),m_price(price){}

A(const A& rhs):m_desc(rhs.m_desc),m_price(rhs.m_price){}

A& operator= (const A& rhs){ m_desc=rhs.m_desc; m_price=rhs.m_price; }

const bool operator== (const A& rhs) const { return(m_desc==rhs.m_desc && m_price==rhs.m_price);}

const bool operator!= (const A& rhs) const { return(m_desc!=rhs.m_desc && m_price!=rhs.m_price);}

static void compare(const A& a, const A& b);

friend std::ostream& operator<< (std::ostream& os, const A& rhs);

private:

double m_price;

std::string m_desc;

};

std::ostream& operator<< (std::ostream& os, const A& rhs)

{

os<

return(os);

}

void A::compare(const A& a, const A& b)

{

if ( a==b )

std::cout<

// else if ( a!=b )

std::cout<

}

int main()

{

A a("Knife", 1.89);

A b("Fork", 1.99);

A c("Fork", 2.99);

A d(a);

std::cout<<"Objects:\n"<

std::cout<

std::cout<

std::cout<

std::cout<

std::cout<<"\nBoolean operator results:\n"<

A::compare(a,b);

A::compare(a,c);

A::compare(a,d);

A::compare(b,c);

A::compare(b,d);

A::compare(c,d);

}

Output

Objects:

Knife ($1.89)

Fork ($1.99)

Fork ($2.99)

Knife ($1.89)

Boolean operator results:

Knife ($1.89) is not the same as Fork ($1.99)

Knife ($1.89) is not the same as Fork ($2.99)

Knife ($1.89) is the same as Knife ($1.89)

Knife ($1.89) is not the same as Knife ($1.89)

Fork ($1.99) is not the same as Fork ($2.99)

Fork ($1.99) is not the same as Knife ($1.89)

Fork ($2.99) is not the same as Knife ($1.89)

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

Write a narrow Boolean search for pages about pet boxers?

Write a narrow boolean search for pages about pet boxers.


How can I write a program to display prime numbers from 1 to 100?

Write a function that implements an algorithm that checks to see if a particular integer is prime (returning a boolean). Write a program that uses that function on each number from 1 to 100, and if true, displays that number.


Write a C program called MonthDays to find the number of days in a given month Test your code with different input values to demonstrate that your function is robust?

Write a C program called MonthDays to find the number of days in a given month Test your code with different input values to demonstrate that your function is robust?


Do you have to write a thesis for a bachelor's degree?

Yes, typically a bachelor's degree program requires students to write a thesis as a culminating project to demonstrate their research and analytical skills in their field of study.


Write a program that allows the user to input a word or phrase and then determine if its a palindrome. I need to use a Boolean equals valued Function procedure names IsPalindrome. How?

forward(word) backward(word)


Write a c plus plus program to find the largest among three numbers using ternary operators?

R = (A &gt; B &amp;&amp; A &gt; C) ? A : (B &gt; C) ? B : C; // parentheses not necessary - for clarity only


Write an if statement that sets the variable fees to 50 if the boolean variable max is true?

class d { private int fees=0; static void main(boolean max) { if(max) fees=50; } }


What is the C plus plus code using Boolean value as output?

The question is not clear. If you mean can you write a C++ program such that the main function returns a boolean, the answer is no, you cannot. The main function must return an int to the operating system. However, the return value can be treated as boolean such that non-zero indicates true (an error has occurred) and zero indicates false (no error). Unlike C, C++ does include a primitive bool data type which can only be true or false. All the comparision operators such as ==, !=, &lt;, &lt;=, &gt; and &gt;= return bool and all the integral data types (int, char, wchar_t) can be implicitly converted to and from bool. Converting a bool to an int returns the value -1, since false is typically imlemented with all bits set while true is implemmented with all bits unset.


Write a programme to perform binary operations on integer argument The arguments and operators should be accepted using command line parameters?

There are many different operators, which are you referring to?


How to write program for secant method in mathematica?

How to write a program for secant method by mathematica


Write a program in java to print prime factors of a number?

import java.io.*; class PrimeFactors { private boolean prime(int a) { boolean b=true; for(int i=2;i&lt;=(a/2);i++) { if(a%i==0) b=false; } return b; } protected static void main()throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter the Number: "); int a=Integer.parseInt(in.readLine()); PrimeFactors o=new PrimeFactors(); System.out.println("Prime Factors of "+a+" are::"); for(int i=1;i&lt;=(a/2);i++) { if(a%i==0) { boolean b=o.prime(i); if(b==true) System.out.print(i+" "); } } }}


Write duality of following boolean function A plus b equals ac?

if f :- a+b = ac then fd:- a.b = a+c