Consider the program shown in Figure 3. Overload the prefix operator for Fraction class using a friend function to produce the following output (in bold): x/y: 4/8

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question
#include <iostream>
using namespace std;
(а)
class Fraction{
int x, y;
public:
Fraction (int a, int b) {x=a; y=b;};
int getx(){return x;}
int gety() {return y;}
} ;
int main()
Fraction n(3, 7);
++n;
cout << "x/y: " <« n.getx()<< "/" « n.gety()<<endl;
return 0;
Figure 3: Program for Question 8(a)
Consider the program shown in Figure 3. Overload the prefix operator for Fraction class
using a friend function to produce the following output (in bold):
Х/у: 4/8
You do not need to write the full program. Only write the overloaded function.
Transcribed Image Text:#include <iostream> using namespace std; (а) class Fraction{ int x, y; public: Fraction (int a, int b) {x=a; y=b;}; int getx(){return x;} int gety() {return y;} } ; int main() Fraction n(3, 7); ++n; cout << "x/y: " <« n.getx()<< "/" « n.gety()<<endl; return 0; Figure 3: Program for Question 8(a) Consider the program shown in Figure 3. Overload the prefix operator for Fraction class using a friend function to produce the following output (in bold): Х/у: 4/8 You do not need to write the full program. Only write the overloaded function.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr