test ed studio LAB2
This commit is contained in:
parent
0b992089f3
commit
9b0c46bccc
12 changed files with 323 additions and 0 deletions
53
LAB2/Lezione2/complesso.cc
Normal file
53
LAB2/Lezione2/complesso.cc
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#include "complesso.h"
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
complesso::complesso(double r, double i) : m_real(r),
|
||||
m_imag(i) {}
|
||||
|
||||
complesso::complesso(const complesso &orig) : m_real(orig.m_real),
|
||||
m_imag(orig.m_imag) {}
|
||||
|
||||
complesso::~complesso() {}
|
||||
|
||||
double
|
||||
complesso::modulo() {
|
||||
return sqrt(m_real * m_real + m_imag * m_imag);
|
||||
}
|
||||
|
||||
double
|
||||
complesso::parte_reale() const {
|
||||
return m_real;
|
||||
}
|
||||
|
||||
double
|
||||
complesso::parte_immaginaria() const {
|
||||
return m_imag;
|
||||
}
|
||||
|
||||
void complesso::stampami() {
|
||||
std::cout << this->m_real << " + " << this->m_imag << "i" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
complesso complesso::operator+(const complesso &addendo) {
|
||||
complesso somma(m_real, m_imag);
|
||||
somma.m_real = somma.m_real + addendo.m_real;
|
||||
somma.m_imag = somma.m_imag + addendo.m_imag;
|
||||
return somma;
|
||||
}
|
||||
|
||||
complesso &
|
||||
complesso::operator=(const complesso &orig) {
|
||||
m_real = orig.m_real;
|
||||
m_imag = orig.m_imag;
|
||||
return *this;
|
||||
}
|
||||
|
||||
complesso operator+(const complesso &uno, const double &due) {
|
||||
double real = uno.parte_reale() + due;
|
||||
double imag = uno.parte_immaginaria();
|
||||
complesso somma(real, imag);
|
||||
|
||||
return somma;
|
||||
}
|
||||
20
LAB2/Lezione2/complesso.h
Normal file
20
LAB2/Lezione2/complesso.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef complesso_h
|
||||
#define complesso_h
|
||||
|
||||
class Complesso {
|
||||
public:
|
||||
Complesso(const Complesso &orig);
|
||||
|
||||
void stampami();
|
||||
|
||||
Complesso operator+(const Complesso &addendo);
|
||||
Complesso &operator=(const Complesso &orig);
|
||||
|
||||
private:
|
||||
double m_real;
|
||||
double m_imag;
|
||||
};
|
||||
|
||||
Complesso operator+(const Complesso &uno, const double &due);
|
||||
|
||||
#endif
|
||||
BIN
LAB2/Lezione2/main_00
Executable file
BIN
LAB2/Lezione2/main_00
Executable file
Binary file not shown.
34
LAB2/Lezione2/main_00.cpp
Normal file
34
LAB2/Lezione2/main_00.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
c++ -o main_00 complesso.cc main_00.cpp
|
||||
*/
|
||||
|
||||
#include "complesso.h"
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// test del constructor
|
||||
complesso numero_complesso_1(0., 0.);
|
||||
complesso numero_complesso_2(3., 4.);
|
||||
|
||||
std::cout << numero_complesso_1.modulo() << std::endl;
|
||||
std::cout << numero_complesso_2.modulo() << std::endl;
|
||||
|
||||
// test del copy constructor
|
||||
complesso numero_complesso_3(numero_complesso_2);
|
||||
|
||||
// test dell'operator+
|
||||
complesso numero_complesso_4 = numero_complesso_3 + numero_complesso_2;
|
||||
// complesso numero_complesso_4 = numero_complesso_3.operator+ (numero_complesso_2) ;
|
||||
numero_complesso_4.stampami();
|
||||
|
||||
// test dell'operator=
|
||||
complesso numero_complesso_5 = numero_complesso_4 + 5.;
|
||||
numero_complesso_5.stampami();
|
||||
|
||||
complesso numero_complesso_6 = numero_complesso_5 = numero_complesso_2;
|
||||
numero_complesso_5.stampami();
|
||||
numero_complesso_6.stampami();
|
||||
|
||||
return 0;
|
||||
}
|
||||
BIN
LAB2/Lezione2/ref
Executable file
BIN
LAB2/Lezione2/ref
Executable file
Binary file not shown.
61
LAB2/Lezione2/ref.cpp
Normal file
61
LAB2/Lezione2/ref.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
// classe test
|
||||
class Meow {
|
||||
private:
|
||||
std::string m_NomeGatto;
|
||||
int m_Ripetizione;
|
||||
|
||||
public:
|
||||
Meow(const std::string &NomeGatto,const int &Ripetizioni)
|
||||
: m_NomeGatto(NomeGatto),
|
||||
m_Ripetizione(Ripetizioni) { // Scope Costructor
|
||||
puts("\nClasse inizializzata.");
|
||||
|
||||
puts("##########Costruttore###########");
|
||||
printf("Valore:\t\tm_NomeGatto: %s\n", m_NomeGatto.c_str());
|
||||
printf("Indirizzo:\tm_NomeGatto: %p\n", &m_NomeGatto);
|
||||
printf("Valore:\t\tm_Ripetizioni: %d\n", m_Ripetizione);
|
||||
printf("Indirizzo:\tm_Ripetizioni: %p\n", &m_Ripetizione);
|
||||
|
||||
// riferimento
|
||||
puts("##########Riferimento###########");
|
||||
printf("Valore:\t\tNomeGatto: %s\n", NomeGatto.c_str());
|
||||
printf("Indirizzo:\tNomeGatto: %p\n", &NomeGatto);
|
||||
printf("Valore:\t\tRipetizioni: %d\n", Ripetizioni);
|
||||
printf("Indirizzo:\tRipetizioni: %p\n", &Ripetizioni);
|
||||
}
|
||||
// END costructor
|
||||
|
||||
void stampami() {
|
||||
puts(".STAMPAMI() dentro classe");
|
||||
printf("n_NomeGatto: %s\n", m_NomeGatto.c_str());
|
||||
printf("m_Ripetizione: %d\n", m_Ripetizione);
|
||||
};
|
||||
|
||||
void CAMBIO() {
|
||||
m_NomeGatto = "GATTOMODIFICATO";
|
||||
m_Ripetizione = 21;
|
||||
puts("\nCAMBIO");
|
||||
printf("gatto_Valore: \t%s\n", m_NomeGatto.c_str());
|
||||
printf("gatto_Indiri: \t%p\n", &m_NomeGatto);
|
||||
printf("n_Valore: \t%d\n", m_Ripetizione);
|
||||
printf("n_Indirizzo: \t%p\n", &m_Ripetizione);
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
std::string gatto = "meow";
|
||||
int n = 3;
|
||||
|
||||
printf("1 Gatto: %s\n", gatto.c_str());
|
||||
printf("Indirizzo gatto: %p\n", &gatto);
|
||||
printf("1 N: %d\n", n);
|
||||
printf("Indirizzo N: %p\n", &n);
|
||||
|
||||
Meow gatto1(gatto, n);
|
||||
|
||||
gatto1.stampami();
|
||||
gatto1.CAMBIO();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue