Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include <string>
- using namespace std;
- struct fraction
- {
- public:
- int a;
- int b;
- fraction(int _a, int _b)
- {
- a = _a;
- b = _b;
- }
- string to_string()
- {
- return "(" + std::to_string(a) + "/" + std::to_string(b) + ")";
- }
- //This function subtracts the input fraction from this fraction
- //Do not simplify the result in any way
- fraction subtract(fraction f)
- {
- // Your code starts here
- fraction subFrac;
- cout << "Enter your Numerator";
- cin >> subFrac.a;
- cout << "Enter your Denominator";
- cin >> subFrac.b;
- return = ((f.a * subFrac.b) - (f.b * subFrac.a)) / (f.b * subFrac.b);
- // Your code ends here
- }
- //This function divides this fraction by the input fraction
- //Do not simplify the result in any way
- fraction divide(fraction f)
- {
- // Your code starts here
- fraction divFrac;
- cout << "Enter your Numerator";
- cin >> divFrac.a;
- cout << "Enter your Denominator";
- cin >> divFrac.b;
- return = ((f.a * divFrac.b) - (f.b * divFrac.a)) / (f.b * divFrac.b);
- // Your code ends here
- }
- //This function simplifies the fraction
- //Definition of simplification: https://www.mathsisfun.com/simplifying-fractions.html
- fraction simplify()
- {
- // Your code ends here
- }
- };
- //After
- fraction main() {
- fraction f1;
- cout << "Enter your Numerator";
- cin >> f1.a;
- cout << "Enter your Denominator";
- cin >> f1.b;
- cout << subtract(f1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement