Sesta esercitazione

Esercizio 1 (svolto)
Esercizio 2
Esercizio 3 (svolto)
Esercizio 4
Esercizio 5

Esercizi su strutture e classi

Esercizio 1
Elenco del telefono
#include <iostream>
#include <string>

struct elenco{
  string nome;
  string cognome;
  int    numero;
};

void add(elenco *);
elenco *trova_nome(string , int, elenco *);


int main(){

  int n,i;
  string cognome;
  struct elenco *mio_elenco;
  struct elenco *utente;

  cout << INSERISCI IL NUMERO DI UTENTI:  << ENDL; CIN>> n;
  mio_elenco = new elenco[n];

  for (i=0;i<n;i++)
     add(&mio_elenco[i]);

  cout << ; INSERISCI UN COGNOME:  CIN>> cognome;

  utente = trova_nome(cognome,n,mio_elenco);
  if (utente!=NULL)
    cout <<"IL NUMERO CERCATO  << UTENTE-  E':>numero << } COUT *EL){ NOME:  &LISTA[I]; VOID (COGNOME="=" ADD(ELENCO DELETE[] *TROVA_NOME(STRING FOR N, *LISTA){ CIN I; INT LISTA[I].COGNOME) RETURN << ELENCO ENDL; INSERISCI UN NUOVO UTENTE  COGNOME, IF (I="0;i<n;i++){" NULL; ; { MIO_ELENCO;>> el->nome;
  cout << COGNOME:  CIN ;>> el->cognome;
  cout << NUMERO:  CIN ;>> el->numero;
}

Esercizio 2
Definire una struttura per la gestione di vettori nel piano e le funzioni che calcolino le seguenti quantità:
Esercizio 3
Classe per trattare i numeri complessi.
#include <iostream>
#include <cmath>

class complex{
public:
  complex();
  complex(double, double);
  double  Mod();
  double  Phase();
  double  Real();
  double  Img();
  complex operator+(const complex &);
  complex operator-(const complex &);
  complex operator-();
  bool    operator==(const complex &);
private:
  double img,rea;
};

complex::complex(){
  rea = 0.0; 
  img = 0.0;
}
complex::complex(double r, double i){
  rea = r;     
  img = i;
}
double complex::Real(){
  return rea;
}
double complex::Img(){
  return img;
}
complex complex::operator+(const complex &b){
  complex c(rea+b.rea,img+b.img);
  return c;
}
complex complex::operator-(const complex &b){
  complex c(rea-b.rea,img-b.img);
  return c;
}
complex complex::operator-(){
  complex c(-rea,-img);
  return c;
}
bool complex::operator==(const complex &b){
  bool test = false;
  if (rea==b.rea && img==b.img) test = true;
  return test;
}


int main(){
  complex a(0.0,1.0);
  complex b(2.0,3.0);
  complex c;

  c = a-b;
  cout << }   C.IMG() 

Esercizio 4
Costruire un classe per la gestione di vettori nel piano che e che contenga i seguenti metodi:
Esercizio 5
Leggere dal file vettori.dat alcuni vettori nel piano secondo il formato
N
x_1 y_1
x_2 y_2
..
x_N y_N
e, utlizzando, le librerie grafiche (utilizzate la classe appena definita).