Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- class Studente{
- public:
- Studente();
- ~Studente();
- int getMatricola();
- void getVoti();
- int getMedia();
- void setVoti();
- char* getNome();
- private:
- int* voti;
- char nome[20];
- int matricola;
- };
- Studente::Studente(){
- int m;
- cout << "Inserisci la tua matricola: ";
- cin >> m;
- matricola = m;
- voti = new int[10];
- for(int i = 0; i < 10; i++){
- voti[i] = rand()%13+18;
- }
- cout << "Inserisci il tuo nome: ";
- cin >> nome;
- }
- int Studente::getMatricola(){
- return matricola;
- }
- void Studente::getVoti(){
- cout << "Voti dell'alunno " << getNome() << ": ";
- for(int i = 0; i < 10; i++)
- cout << voti[i] << " ";
- }
- char* Studente::getNome(){
- return nome;
- }
- void Studente::setVoti(){
- for(int i = 0; i < 10; i++){
- cout << "Imposta voto " << i+1 << ": ";
- cin >> voti[i];
- }
- }
- Studente::~Studente(){
- delete [] voti;
- voti = NULL;
- }
- void truccaVoti(Studente*);
- int main(){
- srand(time(NULL));
- Studente s;
- Studente* ptr = &s;
- ptr->getVoti();
- cout << "\nNome dell'alunno: " << ptr->getNome() << endl;
- cout << "Numero di matricola: " << ptr->getMatricola() << endl;
- truccaVoti(ptr);
- ptr->getVoti();
- return 0;
- }
- void truccaVoti(Studente* stPtr){
- stPtr->setVoti();
- }
Add Comment
Please, Sign In to add comment