Treceți la conținutul principal

fractie cpp

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
#define maxint 0x7FFFFFFF
int cmmdc(int a,int b)
{
 if (a<b) cmmdc(b,a);
 if(a%b) cmmdc(b,a%b);else return b;
}


int cmmmc(int a,int b)
{ return a*b / cmmdc (a,b);}

class fractie
{
private:
 int num,int nr;
public:
explicit fractie(int n=0,int m=1)
{
 if(m<0) m=-m,n=-n;nr = m?n:maxint ; num=(m?m:1);

}

friend ostream &operator<<( ostream & ies,fractie &f)
{
 ies<<""<<f.nr<<"/ "<<f.num;return ies;
}

void simplif( )
{
 int factor=cmmdc(abs(nr),abs(num));
     nr/=factor,num/=factor;
}


void amplif(int factor)
{
 nr*=factor;
 num*=factor;
}
//adunarea a doua fractii

fractie operator+( fractie f2)
{
 fractie f1 =*this,rez;f1.simplif();f2.simplif();
 int mc=cmmmc(f1.nr,f2.num);
 f1.amplif(mc/f1.num);
 f2.amplif(mc/f2.num);
 rez.nr=f1.nr+f2.nr;
 rez.num=mc;
 rez.simplif();
 return(rez);
}

//schimbare de semn
fractie operator -()
{
 return fractie(-nr,num);
}

//scaderea ca adunare cu -f2
fractie operator -(fractie f2) {return(fractie(*this+f2));}
//inmultirea a doua fractii

fractie operator * (fractie f2)
{
 fractie temp;
 temp.nr=nr* f2.nr;
 temp.simplif();
 return temp;
}

//impartire prin inmultire cu inversa

fractie operator / (fractie f2)
{return *this*fractie(f2.num,f2.nr);}
 bool operator <= (fractie f2)
 {
 return((double)nr/num)<=((double)f2.nr/f2.num) ?1:0;}
 operator double(){return(double)nr/num;}
};

void main(int argc,char *argv[])

{
fractie f1(7,4),f2(5,8);
cout<<endl<<f1<<" + " <<f2<<"="<<f1+f2<<endl;
cout<<endl<<f1<<" - " <<f2<<"="<<f1-f2<<endl;
cout<<endl<<f1<<" * " <<f2<<"="<<f1*f2<<endl;
f1.simplif();f2.simplif();
}











Comentarii

Postări populare de pe acest blog

program principal cpp

#include "clasa.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define DELAY 9000000 void delay() { for(long i=0;i<DELAY;i++); } //constructor cu initializare de la tastatura BigInt::BigInt() {char x; signed char t[400]; int i; printf("\nNumarul cu semn "); do s=getche(); while((s!='+')&&(s!='-')); n=0; do {x=getche(); t[n]=x-'0'; n++; } while((x>='0')&&(x<='9')); n--; for(i=0;i<n;i++) nr[i]=t[n-i-1]; } //constructor cu initializare prin parametri BigInt::BigInt(char semn,signed char numar[],int dim) {int i; s=semn; n=dim; for(i=0;i<n;i++) nr[i]=numar[n-i-1]; } //transform un int negativ in pozitiv int BigInt::Pozitiv(int x) {int a,vb; a=0; vb=0; while(vb==0) if((x+a)==0) vb=1; else a=a+1; x=a; return x; } //constructor dintr-un nr int obisnuit BigInt::BigInt(int x) {int i; if(x>=0) s='+'…

NUMERE PRIME ALGORITM C++

// NUMERE PRIME ALGORITM C++//  reediting from scratch //on this page is just the study for a next algoritm for generating the parime nr series like Fibonnaci or ....if possibile

74111121313417374414124343447 if u know the red part you can generate the orange part
1 0 1 111112222 1 1 23

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…