namespace CPPBook { Fraction::Fraction(int n, int d) : numer(n), denom(d) { if (d == 0) { cerr << "błąd: mianownik równy zero" <

NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


#include "h1.h"

#include <cstdlib>
namespace CPPBook {

Fraction::Fraction(int n, int d)
: numer(n), denom(d)
{
if (d == 0) {
cerr << "błąd: mianownik równy zero" <<endl;
exit(EXIT_FAILURE);
}
if (d < 0) {
numer = -n;
denom = -d;
}
else
{
numer = n;
denom = d;
}
}

const Fraction& Fraction::operator *= (const Fraction& f)
{
*this = *this * f;
return *this;
}

bool Fraction::operator < (CPPBook::Fraction& f) const
//(const Fraction& f) const
{
return numer * f.denom < f.numer* denom;
}

} // koniec przestrzeni nazw





#include "h1.h"
int main()
{
using namespace CPPBook;
const Fraction w(7, 3);
w.print();
Fraction x = w * w;
while (x < Fraction(1000))
{
x *= w;
x.print();
}

char ch;
std::cin >> ch;
}



// 
Procedury2.cpp
//
#include <algorithm>
#include <cstdlib>
#include "h2.h"
namespace CPPBook
{
unsigned RFraction::gcd() const
}
if (numer 0)
{
}
return denom;
unsigned divisor = std::min(std::abs(numer), denom); while (numer& divisor = 0 || denom & divisor != 0)
--divisor;
return divisor;
}
}
void RFraction::reduce()
{
if (reducible)
{
int divisor = gcd();
numer /= divisor;
denom / -divisor;
reducible = false;
-0
}
const RFraction& RFraction::operator= (const RFraction & f)
{
numer
denom
f.numer; f.denom;
}
if (!reducible)
{
}
reducible(gcd() > 1);
return *this;
void RFraction::scanFrom(std::istream & strm)
{
Fraction::scanFrom(strm);
reducible = (gcd()
> 1);
}

//
main.cpp
//
#include <iostream>
#include <cstdlib>
#include "h2.h"
int main()
{
CPPBook: : RFraction x(91, 39);
std::cout << x;
std::cout << (x.isReducible() ? "(do skrocenia) " : " (skrocony)") << std::endl; x.reduce();
std::cout << x;
std::cout << (x.is Reducible() ? "(do skrocenia) " : " (skrocony)") << < std::endl; x *= 3;
std::cout << < x;
std::cout << (x.is Reducible() ? "(do skrocenia)" : " (skrocony) ") << std::endl;
char ch;
std::cin >> ch;
}

//
procedury.cpp
//

#include "h1.h"
#include <cstdlib>
namespace CPPBook
{
Fraction::Fraction(int n, int d)
{
: numer(n), denom(d)
if (d == 0)
}
std::cerr << "blad: mianownik rowny zero" << std::endl; std::exit(EXIT_FAILURE);
if (d < 0)
- 0 -
numer - n;
denom - d;
}
else
numer n; denom = d;
const Fraction& Fraction::operator= (const Fraction & f)
* this* this* f;
return *this;
bool operator < (const Fraction & a, const Fraction & b)
{
return a.numerb.denom < b.numera.denom;
void Fraction::printon(std::ostream & strm) const
{
strm << numer << "/" << denom;

void Fraction::scan From(std::istream & strm)
{
int n, d;
strm >> n;
if (strm.peek()== '/')
{
strm.get();
strm >> d;
}
else
{
d = 1;
}
if (!strm)
return;
}
if (d == 0)
{
strm.clear(strm.rdstate() I std::ios::failbit);
return;
}
if (d < 0)
{
numer - n;
denom - d;
}
else
{
numer = n;
denom d;
}

//
h2
//


#ifndef RFRACTION_HPP
#define RFRACTION HPP
#include "h1.h"
namespace CPPBook
{
class RFraction : public Fraction
{
protected:
bool reducible;
unsigned gcd() const;
public:
RFraction(int n = 0, int d - 1) : Fraction(n, d)
{
}
reducible = (gcd() > 1);
const RFraction& operator= (const RFraction&); void scanFrom(std::istream&);
void reduce();
bool isReducible() const
return reducible;
-D
}
}
};
#endif
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.