C++ :: Rational Number Class - Handling Numbers Of Different Denominators
Apr 6, 2014
My assignment is to handle rational numbers of different denominators...
Develop rational number class that can
•add
•subtract
•multiply
•divide
•reduce to simplest form
Your class must be able to handle rational numbers of different denominators
This is the errors I am getting
error C4716: 'Rational::addition' : must return a value
error C4716: 'Rational::multiplication' : must return a value
error C4716: 'Rational::division' : must return a value
error C4716: 'Rational::subtraction' : must return a value
View 1 Replies
ADVERTISEMENT
Nov 1, 2013
I complete this program, but the only thing is that it won't execute the program.the other problem is the program is not running as it is suppose to.
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <cctype>
using namespace std;
class Rational
[code]....
View 1 Replies
View Related
Mar 5, 2015
Assignment to make a rational numbers class as follows:
create a constructor that prevents a 0 denominator in a fraction, reduces or simplifies fractions that are not in reduced form, and avoids negative denominators.
Overload the addition, subtraction, multiplication and division operators for this class.
Overload the relational and equality operators for this class. My code so far is as follows:
header file:
#ifndef RATIONAL_H
#define RATIONAL_H
#include <iostream>
[Code].....
I'm getting an error:
Build started: Project: 11.10rationalnumberclass, Configuration: Debug Win32 ------
1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall Rational::setFraction(int,int)" (?setFraction@Rational@@QAEXHH@Z) referenced in function _main
1>C:UsersJacobDocumentsVisual Studio 2010ProjectsComplexnumbers11.8projectDebug11.10rationalnumberclass.exe : fatal error LNK1120: 1 unresolved externals
part of the problem might be that I cannibalized another program dealing with complex numbers to make this. While I don't need this class to be perfect, I'm not sure I entirely understand everything about classes and overloading yet.
View 2 Replies
View Related
Nov 4, 2013
how to use a Class structure to create a program that reads in two rational numbers and adds them, subtracts, multiplies, and divides them.
View 3 Replies
View Related
Sep 13, 2013
I'm implementing a rational number class:
#include <iostream>
#include <stdint.h>
using namespace std;
typedef int64_t RAT_INT;
struct RAT{
RAT_INT Num, Den;
RAT(RAT_INT num = 0, RAT_INT den = 1){
Num = num;
Den = den;
[Code].....
Two questions:
1) In the second line in main, how does C++ know to convert 2 to the appropriate RAT?
2) Is it possible to make the third line in main valid without adding global operators for all the member operators to support plain integers?
View 5 Replies
View Related
Feb 22, 2015
I'm having trouble finishing this program. What I'm trying to do is create a class for Rational numbers. Get input from user for denominator and numerator. Store the numbers without a sign, and for the sign store it separately in char. I'm not supposed to use accessor functions. The part that I can't seem to know how to do is use the info that was stored in the addUp function. This function need to add two rational numbers. i need to make this function general enough that it can handle two fractions, or a fraction and a whole number, or two whole numbers. What I already have here is readin function which reads in the numerator and denominator. setnumerator and setdenominator to assign positive values. setsign should get the sign of the fraction. Finally addUp should addUp which I explained before. I have some ideas about writing the tests, but can't seem to know how to implement it to the program. The main program is still empty but all I'm supposed to do there is call the class functions.
Code:
#include <iostream>
using namespace std;
class Rational {
private:
int numerator, denominator;
char sign;
[Code] .....
View 14 Replies
View Related
Apr 10, 2013
The program works, but the rational number doesn't print as reduced. I guess i have to call the reduction function, but i'm not sure where
the output that i get is:
2/6 + 7/8 = 58/48
58/48 = 1.20833
2/6 - 7/8 = -26/48
-26/48 = -0.541667
2/6 x 7/8 = 14/48
14/48 = 0.291667
2/6 / 7/8 = 16/42
16/42 = 0.380952
the output that i suppose to get is:
1/3 + 7/8 = 29/24
29/24 = 1.20833
1/3 - 7/8 = -13/24
-13/24 = -0.541667
1/3 x 7/8 = 7/24
7/24 = 0.291667
1/3 / 7/8 = 8/21
8/21 = 0.380952
here is my header file
//Prevent multiple inclusions of header
#ifndef RATIONAL_H
#define RATIONAL_H
//Rational class definition
class Rational {
[Code] .....
View 3 Replies
View Related
Aug 4, 2014
I tried to check the rational or irrational numbers after we take the square root. i dont get the formula. for eg. squareroot of 64 is 8 and it is rational. square root of 2 is irrational. how to check it in c++..
View 10 Replies
View Related
Feb 20, 2015
Write a program that prompts the user to enter a number larger than 2. The program should use the Number class to determine the prime numbers between 2 and the number entered, and display them in the console window.I've been stuck for a while now and just lost in implementing classes and contstructors.
#include <iostream>
using namespace std;
int main(int argc, char * argv[])
{
cout << "Enter a number larger than 2: " << endl;
int n;
cin >> n;
View 1 Replies
View Related
Sep 26, 2013
I'm trying to make an array that takes a group of numbers and finds the largest number into a template class.
template<class TYPE>
void Integers(TYPE data) {
int integers[] = {4, 25, 32, 85, 150, 12, 98, 200};
int i = 0;
int Max=integers[0];
for (i=1; i < 8; i++) {
[Code] ....
I'm sure I'm going about it all wrong, but I'm not sure as to get it so that it will accept the arrays input.
View 2 Replies
View Related
Feb 16, 2014
Suppose i have a very large number stored as a string, say
std::string str = "1000000000000000000000000000000000001";
And i use std::stringstream to convert it to int like this
std::stringstream ss(str);
uint64_t i;
ss >> i;
Then I would be maxed out right. so how would one practically handle things like comparison of two such numbers.
I could think of 2 approaches :
1) I can compare the numbers character by character.
2) I can put the results of ss >> i; into an array then compare each element of array
would there be any other methods??
View 4 Replies
View Related
Jan 24, 2014
I have to implemente the to_string method. Whats the fastest way? Stringstreams. But I have to use C++ without any headers, so I need to implement the stringstream class. How can an stringstream hold one float? An double? Hoq cqn I implement an strigstream myself?
View 8 Replies
View Related
Feb 4, 2015
I'm working on this program that I have to design a class Numbers that can be used to translate whole numbers to the English description of the number.
Now this is what I got so far:
#include <iostream>
#include <string>
using namespace std;
class Numbers {
private:
int number;
static string ones[];
static string tens[];
[Code] ....
The program seems to work. However its not giving me the right number description,
Example:
Please enter the amount you would like translated into words: 5
six dollars
please enter another number: 10
eleven dollars
please enter another number: 20
thirty dollars
please enter another number: 30
forty dollars
please enter another number: 100
two hundred dollars
please enter another number: 150
two hundred sixty dollars
please enter another number: 500
six hundred dollars
please enter another number: 1000
two thousand dollars
please enter another number:
View 4 Replies
View Related
Nov 13, 2014
I cannot get my function overloading the input operator for rational type objects to work.
lab9.cpp: In function ‘std::istream& operator>>(std::istream&, const rational&)’:
lab9.cpp:186:20: error: invalid initialization of reference of type ‘std::istream& {aka std::basic_istream<char>&}’ from expression of type ‘rational’
return (inputFrac);
lab9.h
#include <iostream>
using namespace std;
class rational {
public:
rational();
rational(int a, int b);
[Code] ......
View 4 Replies
View Related
Aug 14, 2013
Example: If i had the number 5 it needs to be represented/stored as two 4-bit binary numbers,
so 0000 0101, = 0 5.
Or 22 = 0010 0010 = 2 2.
The initial numbers/values are being read from a binary file in to an array....
View 7 Replies
View Related
Nov 28, 2013
How to find the smallest number amongst 4 numbers
View 10 Replies
View Related
Oct 23, 2014
I'm trying to find the second smallest number out of 4 numbers. I produced some code that does that but it doesn't work if i have duplicate numbers.
secondSmallest = a;
if(b > secondSmallest) {
secondSmallest = b;
}
if(c < secondSmallest) {
[Code] ....
View 1 Replies
View Related
Jul 30, 2014
Not a major issue since I got this to work but for some reason both my random numbers are the same and not sure why ...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class ComputerAssistedInstructions {
private static Random rand1 = new Random();
private static Random rand2 = new Random();
[Code] .....
View 2 Replies
View Related
May 10, 2014
I am a beginner at C++, the output is pretty self explanatory. I'm trying to make a number sorting program with other features, but the numbers are all wrong.
Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
[Code] .....
Input.DAT
Code:
376 389 450 735 600 576 612 700 450 628 778 389 667 500 475 550 687 791 829 344
549 476 400 587 535 657 789 583 340 764 422 826 566 436 565 834 533 423 837 701
847 521 746 356 582 465 493 593 425 421
I can't for the life of me figure out why the numbers are all messed up.
View 5 Replies
View Related
Feb 26, 2014
I calculate two numbers "R1",R2"
when i make
cout<<R1;
cout<<R2
i get
R1=51,9151
R2=51,915
when i make
Code: if (R1>R2) cout<<"i am here" he print the message
but they are equal. how i made limit the number of flottant to get equal numbers?
View 13 Replies
View Related
Jan 14, 2014
the text file looks like: one hello hi twenty-five billion fifty maths three thousand and two
output: count the number of text numbers: 4
View 1 Replies
View Related
Feb 19, 2013
I've written a program which takes a character string and then prints each character vertically so that for instance the string 123 can be written as
1
2
3
no what i need is for all the numbers from zero to the inputted number to print the numbers digits vertically but each number to be printed horizontally so that for instance an input of 11 prints
1 2 3 4 5 6 7 8 9 1 1
0 1
i've made it so that i can print all numbers up to the inputted number vertically; however, i am stuck with a method for making each number print horizontally as described above.
View 3 Replies
View Related
Mar 6, 2015
Coding for- To print all combinations of numbers that can compose a given number..
View 3 Replies
View Related
Oct 21, 2013
I have a error with one of my programs. I'm supposed to get rid of negative numbers when there are numbers that are randomly generated. Here is the middle part of the code.
{
int vectorLength = 10;
vector<int> bothSigns(vectorLength);
cout << " Input vector: ";
for (int i = 0; i < vectorLength; i = i + 1)
{ bothSigns[i] = rand()%201 - 100;
[code] .....
The part where i'm supposed to start is after the /////'s. However, whenever I input a number for the random numbers(not put in part of code), i keep getting a segmentation error.
View 3 Replies
View Related
Apr 24, 2013
I have to write a code in which the addition of prime number gives the number user input..
for example if user enters 10 then
7+3 = 10
2+3+5 = 10
View 2 Replies
View Related
Sep 15, 2013
I have a very large number in word ~6million digits long
I wish to make a program to check if it is prime.
View 5 Replies
View Related