answersLogoWhite

0


Best Answer

#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

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a program to demonstrate boolean operators in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to demonstrate renaming the file?

Sure, here's a simple Python program that renames a file: import os current_name = 'original.txt' new_name = 'renamed.txt' os.rename(current_name, new_name) print(f'{current_name} has been successfully renamed to {new_name}') Make sure to replace original.txt with the actual name of the file you want to rename and renamed.txt with the desired new name.


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?


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)


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 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; } }


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?


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+" "); } } }}


How to write program for secant method in mathematica?

How to write a program for secant method by mathematica


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

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