Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:13:15+00:00 2026-06-13T04:13:15+00:00

I’m working on a fraction assignment where I prompt the user for two fractions,

  • 0

I’m working on a fraction assignment where I prompt the user for two fractions, then I add, subtract, multiply and divide the two fractions. I know I still need to reduce fractions, however I can’t figure out why the denominators are being multiplied by 10. If I input 1 1/2 for frac1, and 2 2/5 for frac2, the denominator is 100 instead of 10. So weird..any guidance is appreciated! 🙂

// fraction9.cpp : main project file.
#include "stdafx.h"
#include<conio.h>
#include<iostream>
 #include<string>
using namespace std;


class Fraction
{
private:
   int whole;
   int numerator;       // may be any integer
   int denominator;     // should always be positive
public:
 Fraction();    // Set numerator = 0, denominator = 1.
 Fraction(int w, int n, int d=1);   // constructor with parameters
            //  acts as conversion constructor

 // operator overload as member
 Fraction operator+ (const Fraction& f) const; 
 Fraction operator- (const Fraction& f) const;
 Fraction operator* (const Fraction& f) const;
 Fraction operator/ (const Fraction& f) const;     

 // standard input/output routines
 void Input();      // input a fraction from keyboard.
 void Show() const;     // Display a fraction on screen

 // accessors
 int GetWhole() const;
 int GetNumerator() const;
 int GetDenominator() const;

 // mutator
   bool SetValue(int w, int n, int d=1); // set the fraction's value through parameters
   //double Evaluate() const;   // Return the decimal value of a fraction


};

Fraction Fraction::operator+(const Fraction& f) const
// operator overload for + written as member function
{
   Fraction r;      // result
   r.numerator = (denominator * whole + numerator) * f.denominator + (f.denominator *     f.whole + f.numerator) * denominator;
   r.denominator = (denominator * f.denominator);
   return r;
}

Fraction Fraction::operator-(const Fraction& f) const
// operator overload for - written as member function
{
   Fraction r;      // result
   r.numerator = (denominator * whole + numerator) * f.denominator - (f.denominator *     f.whole + f.numerator) * denominator;
   r.denominator = (denominator * f.denominator);
   return r;
}

// operator overload for * written as member function
Fraction Fraction::operator*(const Fraction& f) const
{
   Fraction r;      // result
   r.numerator = ((denominator * whole + numerator) * (f.denominator * f.whole +     f.numerator));
   r.denominator = (denominator * f.denominator);
   return r;
}

// operator overload for / written as member function
Fraction Fraction::operator/(const Fraction& f) const
{
   Fraction r;      // result
   r.numerator = ((denominator * whole + numerator) * f.denominator);
   r.denominator = (denominator * (f.denominator * f.whole + f.numerator));
   return r;
}

Fraction::Fraction()
// Default constructor.  Initializes fraction to 0/1
{
   whole = 0;
   numerator = 0; 
   denominator = 1;
}

Fraction::Fraction(int w, int n, int d)
// initializes fraction to n/d (defaults to 0/1 if invalid data)
{
   if (SetValue(w, n, d) == false)
  SetValue(0, 0, 1);
}

void Fraction::Input()
{
    cout << "Enter whole number ";
  cin >> whole;
  cout << "Enter numerator " ;  
  cin >> numerator; 
  cout << "Enter denominator ";
  cin >> denominator;
      if (denominator <= 0)
  cout << "*** Denominator must be positive.  Try again: ";
  while (denominator <= 0)
    {
        cout << "Please re-enter the denominator of the fraction, it cannot be 0" <<     endl;
        cin >> denominator;
    };
}

void Fraction::Show() const
// Display a fraction
{
   cout << whole << " " << numerator << '/' << denominator;
}

int Fraction::GetWhole() const
{
    return whole;
}

int Fraction::GetNumerator() const
{
   return numerator;
}

int Fraction::GetDenominator() const
{
   return denominator;
}

bool Fraction::SetValue(int w, int n, int d)
// sets fraction to n/d and returns true for success (good data)
// returns false and leaves fraction alone if bad data
{
   if (d <= 0)
    return false;

   numerator = n;
   denominator = d;
   return true;
}

// Driver routine to test the Fraction class 

int main()
{

Fraction f1, f2;
cout << "Enter first fraction: ";
f1.Input();
cout << "\n You entered ";
f1.Show();
cout << "\n Enter second fraction: ";
f2.Input();
cout << "You entered ";
f2.Show();
cout << "\n The sum of the first and second fraction is ";
Fraction Aresult;
Aresult = f1 + f2;
Fraction Sresult;
Sresult = f1 - f2;
Fraction Mresult;
Mresult = f1 * f2;
Fraction Dresult;
Dresult = f1 / f2;
Aresult.Show();
Sresult.Show();
Mresult.Show();
Dresult.Show();
cout << '\n';
_getch();
return 0;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:13:17+00:00Added an answer on June 13, 2026 at 4:13 am

    Those extra zeros aren’t being appended to the denominators. They’re the whole parts of mixed fractions you’re stringing together.

    The results are actually

    0 39/10
    0 -9/10
    0 36/10
    0 15/24
    

    but you’re printing them on one line:

    0 39/100 -9/100 36/100 15/24
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I need to clean up various Word 'smart' characters in user input, including but
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.