Reference no: EM13167785
Write the function in C ++ to reduce the numerator and denominator in the Rat class to lowest terms.
// class for rational numbers
#include <iostream>
using namespace std;
class Rat{
private:
int n;
int d;
public:
// constructors
// default constructor
Rat(){
n=0;
d=1;
}
// 2 parameter constructor
Rat(int i, int j){
n=i;
d=j;
}
// conversion constructor
Rat(int i){
n=i;
d=1;
}
//accessor functions (usually called get() and set(...) )
int getN(){ return n;}
int getD(){ return d;}
void setN(int i){ n=i;}
void setD(int i){ d=i;}
//arithmetic operators
Rat operator+(Rat r){
Rat t;
t.n=n*r.d+d*r.n;
t.d=d*r.d;
return t;
}
2
// 2 overloaded i/o operators
friend ostream& operator<<(ostream& os, Rat r);
friend istream& operator>>(istream& is, Rat& r);
}; //end Rat
// operator<<() is NOT a member function but since it was declared a friend of Rat
// it has access to its private parts.
ostream& operator<<(ostream& os, Rat r){
os<<r.n<<" / "<<r.d<<endl;
return os;}
// operator>>() is NOT a member function but since it was declared a friend of Rat
// it has access to its provate parts.
istream& operator>>(istream& is, Rat& r){
is>>r.n>>r.d;
return is;
}
int main(){
Rat x(1,2), y(2,3), z;
z=x+y;
cout<<z;
x.setN(3);
y.setD(2);
z=x+y;
cout<<z;
cin>>x;
cout<<x;
z= x+5;
cout<<z;
system("pause");
return 0;
}
Generates numbers in the fibonacci sequence
: Write a class called fibs that generates numbers in the Fibonacci sequence (each number is the sum of the previous two). The sequence starts 1, 1, 2, 3, 5, ...
|
Write a program in which the program print out the input
: use (switch statement) to write a program in which the program print out the input (single character) if the character is not '2','t', or 'w'. Use 'default' and 'break' wisely.
|
State the candy inside a bomb calorimeter
: A researcher studying the nutritional value of a new candy places a 5.9 gram sample of the candy inside a bomb calorimeter and combusts it in excess oxygen.
|
Temperature conversions
: Temperature Conversions. The following problems generate temperature- conversion tables. Use following equations that give relationships between temperatures in degrees Fahrenheit(Tf), degree Celsius(Tc), degrees Kelvin(Tk), and degrees Rankin(Tr);
|
Reduce the numerator and denominator
: Write the function in C ++ to reduce the numerator and denominator in the Rat class to lowest terms.
|
Unit conversions
: Unit Conversions. The following problem generate tables of unit conversions. Include a table heading and column headings for the tables. Choose the number of decimal place based on the values to be printed.
|
What is the median of the reported blood pressure values
: What is the median of the reported blod pressure values?
|
Saddle point is an element
: For a square nXn a array, a saddle point is an element that is the maximum in its row and the minimum in its column.
|
What is the magnitude of the accumulated difference
: The difference is accumulated every 1/10th of a second for one day. What is the magnitude of the accumulated difference
|