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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started