Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
-1 votes
1 answer
90 views

Is there a way to simplify a fraction including decimals? [duplicate]

Whenever a user inputs a fraction, it might be contain decimals (long double). I have some code (C++) below to show how I implement this: class Fraction { public: long double numerator, ...
hello there's user avatar
0 votes
1 answer
82 views

Incorrect multiplication of long fractions in different C++ compilers

A program takes two long fractions, and performs addition, subtraction, multiplication and comparison operations on them. In the standard CLion compiler (MinGW) the code is executed correctly, but in ...
nklobas's user avatar
  • 13
2 votes
1 answer
181 views

Overloading operator whose parameter is not class or enum

I want to overload operator like this: fraction operator / (int a, int b) // error here { return fraction(a,b); } (Not inside fraction class). But the compiler says: [Error] 'fraction operator/(int, ...
KhiemGOM's user avatar
1 vote
1 answer
112 views

Construct (give its value) an object outside its initialize in c++ [duplicate]

I make a fraction class, but I want to assign its value to another fraction, usually, I have to do this: fraction a; a.setNumerator=(1); a.setDenominator(2); b=a; //b is already intialized above This ...
KhiemGOM's user avatar
-1 votes
1 answer
82 views

Why does my code have trouble with cout<<num0+num1?

The code have an issue in main. When I try cout<<num0-num1; alone or cout<<num0+num1; alone they work fine, but when I do them together, the code just stops print one of them and the rest ...
iAmTired's user avatar
-1 votes
1 answer
87 views

Find the number of steps transforming a/b into c/d so that 0<a<b<100000 and 0<c<d<100000, or none if there is no ways

Original problem. Given two valid fractions a/b and c/d. Each transformation is adding 1 to a and b, then optimizing a/b. Find the number of steps transforming a/b into c/d so that 0<a<b<...
user avatar
-1 votes
1 answer
164 views

writing c++ program "fraction of double" [closed]

I wanna write a c++ program that read a double value and after reading it print only the fraction of that number, for example if the input was 14.25 then the output must be 0.25 should include iomanip ...
Aizen Sama's user avatar
1 vote
2 answers
529 views

How to add a number to a fraction in c++?

I created a Fraction : class Fraction { private: int numarator_, denum_; public: constexpr Fraction(int numarator, int denum=1) noexcept : numarator_(numarator), denum_(denum) {} virtual ~...
GreenApple's user avatar
2 votes
2 answers
2k views

C++ multiply float by fraction

just started C++ from a MATLAB background and getting confused. float farenheit, celcius; cin >> farenheit; celcius = (farenheit - 32) * (5 / 9); cout << "Temperature (c): " <&...
Helpmeplzimnotfrombath's user avatar
1 vote
1 answer
110 views

Overloading composed operators (+=,-=,*= and /=). Doesn't calculate how it should

The code is a part of a more complex one, but i reduced to see the part where i have the problem. So after overloading the +=, -=,*= and /= operators,the results are all the same and i don't know what ...
vivi25-5's user avatar
0 votes
0 answers
31 views

is it possible to show a fractional number in the output of c++? [duplicate]

I want to calculate some formula and show the results in a fractional number, but as I know c++ converts them to floats. probably, is there any library or method to show them just fractional? for ...
Tara's user avatar
  • 1
-1 votes
3 answers
2k views

Finding irreducible fractions between two given fractions in ascending order of denominators and then numerators

Time limit per test: 2 seconds Memory limit per test: 512 megabytes You are given two fractions a/b < c/d and a positive number N. Consider all irreducible fractions e/f such that 0 < e,...
IlyaMuravjov's user avatar
  • 2,512
1 vote
1 answer
903 views

How to sort an array of rational numbers in C++?

I want to sort an array of rational numbers of type integers. I have used the Bubble Sort algorithm. I am dividing numerator with denominator and then comparing two rational numbers on the basis of ...
Junaid's user avatar
  • 1,020
0 votes
1 answer
126 views

How can I write a function to accept a Fraction object in SWIG?

I'm writing an interface between Python and a our C++ video-processing library using SWIG. In python, I use the Fraction class to represent frame rate (e.g. NTFS24 = 24000/1001 FPS). The functionality ...
BIOStheZerg's user avatar
7 votes
2 answers
1k views

How to avoid using temporary variable with std::modf?

I've recently run into an issue where I got a segfault in MSVC where I wouldn't in GCC. After hours I realized that apparently my version of MSVC does not support the following syntax: double value ...
Krupip's user avatar
  • 5,007

15 30 50 per page
1
2 3 4 5 6