Complexos
Publicado por jorgyano bruno 04/09/2007
[ Hits: 5.247 ]
Classe que realiza operações como adição, subtração, multiplicação, divisão, multiplicação por um escalar e divisão por escalar com números complexos.
/*
Jorgyano Bruno de Oiveira Vieira
*/
#include <iostream>
#include<math.h>
using namespace std;
class Complexo{
private:
float real;
float img;
public:
Complexo();
Complexo(float _real, float _img);
void print();
void set(float,float);
void conjugado();
Complexo operator+(Complexo);
Complexo operator-(Complexo);
Complexo operator*(Complexo);
Complexo operator*(int);
Complexo operator/(Complexo);
Complexo operator/(int);
};
Complexo::Complexo() {
real=0;
img=0;
}
Complexo::Complexo(float _real, float _img){
real = _real;
img = _img;
}
void Complexo::print() {
cout << real << " + " << img << "i" << endl;
}
void Complexo::set(float rl, float im) {
real = rl;
img = im;
}
void Complexo::conjugado(){
img = (-1)*img;
}
Complexo Complexo::operator+(Complexo b) {
Complexo c;
c.real = real + b.real;
c.img = img + b.img;
return c;
}
Complexo Complexo::operator-(Complexo b) {
Complexo c;
c.real = real - b.real;
c.img = img - b.img;
return c;
}
Complexo Complexo::operator*(Complexo b){
Complexo c;
c.real = (real*b.real) - (img*b.img);
c.img = (real*b.img) + (img*b.real);
return c;
}
Complexo Complexo::operator*(int b){
Complexo c;
c.real = b*real;
c.img = b*img;
return c;
}
Complexo Complexo::operator/(Complexo b){
Complexo c;
c.real = (real*b.real) + (img*b.img)/(pow(b.img,b.img) + pow(b.real,b.real));
c.img = (b.real*img) - (real*b.img)/(pow(b.img,b.img) + pow(b.real,b.real));
}
Complexo Complexo::operator/(int b){
Complexo c;
c.real = b/real;
c.img = b/img;
return c;
}
int main(){
Complexo a(4,-5), b, c;
a.conjugado();
b = a;
c=a+b;
cout<< "a+b = ";c.print();
c=a/b;
cout << "a/b = ";c.print();
c=a*b;
cout<<"a*b = ";c.print();
c = a*3+b/2;
cout <<"a*3+b/2 = ";c.print();
system("pause");
}
C --> Calculadora de equações de 2º grau explicada.
Nenhum comentário foi encontrado.
Gentoo binário em 2026: UEFI, LUKS, Btrfs e Systemd
Trabalhando Nativamente com Logs no Linux
Jogando Daikatana (Steam) com Patch 1.3 via Luxtorpeda no Linux
LazyDocker – Interface de Usuário em Tempo Real para o Docker
Por que sua empresa precisa de uma PKI (e como automatizar EMISSÕES de certificados via Web API)
Instalando NoMachine no Gentoo com Systemd (acesso Remoto em LAN)
Gentoo: Trocando wpa_supplicant pelo iwd no NetworkManager (Systemd)
OCS Inventory NG: Instalação de Agentes Linux e Windows + Autenticação HTTP
Removere linux-image-6... [RESOLVIDO] (2)
Quando vocês pararam de testar distros? (19)
O que houve com slackware ??? (6)









