From 53043b9f428aa51feef279864d91ae7afca3b66e Mon Sep 17 00:00:00 2001 From: Alessandro Ferro <49845537+xfarrow@users.noreply.github.com> Date: Fri, 19 Mar 2021 11:30:28 +0100 Subject: [PATCH] lezione 3 --- teoria/enum_istream_ostream.cpp | 26 ++++++++++++++++++++++++++ teoria/enumeration.cpp | 27 +++++++++++++++++++++++++++ teoria/friendFunction.cpp | 19 +++++++++++++++++++ teoria/istream_ostream.cpp | 17 +++++++++++++++++ teoria/struct.cpp | 3 ++- 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 teoria/enum_istream_ostream.cpp create mode 100644 teoria/friendFunction.cpp create mode 100644 teoria/istream_ostream.cpp diff --git a/teoria/enum_istream_ostream.cpp b/teoria/enum_istream_ostream.cpp new file mode 100644 index 0000000..1cea588 --- /dev/null +++ b/teoria/enum_istream_ostream.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; + +enum class Color{red, white, green, black}; + +ostream& operator<<(ostream& outputStream, const Color& color){ //la keyword const non è obbligatoria, ma meglio metterla + switch(color){ + case Color::red: + outputStream<<"Rosso"; + break; + case Color::white: + outputStream<<"Bianco"; + break; + case Color::green: + outputStream<<"Verde"; + break; + case Color::black: + outputStream<<"Nero"; + } + return outputStream; +} +int main(){ + Color myColor = Color::red; + cout< +using namespace std; + +enum class Color1{green, white, red}; +enum class Color2{black, blue, brown, green, red}; + +enum Color3{rosso, arancione}; +//enum Color4{rosso, viola}; //errore, rosso già dichiarato + +int main(){ + + // Posso accedere ai valori di Color3 come fossero variabili globali + cout< +using namespace std; + +struct Studente{ + friend void printSecureNumber(Studente); // posso mettere questa linea ovunque all'interno della struct + + string nome; + string cognome; + private: + int secureNumber = 999; +}; +void printSecureNumber(Studente s){ + cout< +using namespace std; +struct Studente{ + string nome, cognome, matricola; + int annoCorso; +}; +ostream& operator<<(ostream& outputStream, const Studente& st){ //la keyword const non è obbligatoria, ma meglio metterla + return outputStream<>(istream& inputStream, Studente& st){ + return inputStream>>st.nome>>st.cognome>>st.matricola>>st.annoCorso; +} +int main(){ + Studente s; + cin>>s; + cout<