Answer to Question #204226 in C++ for Shafeeq Ahmed

Question #204226

Write a C++ program which perform the following:

1. Create a class

2. Create two objects and assign the values

3. Now compare the object values by using the Operator

Overloading on the following operator: a. Operator Overloading (>)

4. And print if the value of which object is greater.


1
Expert's answer
2021-06-08T02:12:50-0400
#include<iostream>
using namespace std;
class Coder{
	private:
		int first;
	
	public:
		Coder(): first(0)  {} // Constructor initializing first and second to 0
		Coder(int s){
			first = s;
			
		}
		//Overload > operator


	Coder operator >(const Coder& b){
		 
		Coder code;
		code.first = first;
		if(b.first > first){
			code.first = b.first;
		}
	
		
		
		return code;
	}
	void display(){
		cout<<"Output larger number is\t "<<first;
	}
		
};
int main(){
	Coder c1(10), c2(89);
	Coder c3 = c1>c2;
	c3.display();
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog