Question: (C++) Here is the programming problem: Define a class called Fraction that has 2 private members that represent the numerator and denominator respectively. They will

(C++)

Here is the programming problem: Define a class called Fraction that has 2 private members that represent the numerator and denominator respectively. They will be represented as integers. Include a constructor and a public void function called print that prints out the fraction. (For example, if the numerator is 3 and the denominator is 5, print provides as output 3/5.) Include the class in a program that prints out the fraction 3/5. My code so far is listed below, but I am not able to start the program. I believe the problem resides with the output I am trying to do with "print". Not sure what should be there instead.

#include using namespace std;

class Fraction { public: void print(); private: int num; int dem; };

void Fraction::print() { cout << num << "/" << dem << endl; }

int main() { int num = 0; int dem = 1; void print();

cout << "Enter numerator: "; cin >> num; cout << "Enter demoninator: "; cin >> dem;

cout << "Fraction is: " << print << endl;

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!