Originariamente inviata da
oregon
A me non dà nessun problema ... se pubblichi, una volta per tutte, *tutto* il codice (compreso il main) che utilizzi, forse il problema è da qualche altra parte ... (suppongo proprio nel main).
Perdonami per la non completezza delle informazioni. Ho applicato delle modifiche alle funzioni ( verificando preventivamente il funzionamento in un codice a parte). Il problema persiste comunque.
Docente.h
codice:
#ifndef DOCENTE_H
#define DOCENTE_H
#include<string>
using std:: string;
#include <iostream>
using std :: istream;
using std :: ostream;
class Docente{
friend ostream& operator<<(ostream&, const Docente*);
friend istream& operator>>(istream&, Docente* &);
public:
Docente();
Docente(string, string);
void stampa();
string getNome();
string getCognome();
private:
string nome,cognome;
};
#endif
Docente.cpp
codice:
#include "Docente.h"
#include <iostream>
using std :: cout;
using std :: endl;
using std ::istream;
using std :: ostream;
#include <string>
using std :: string;
Docente :: Docente(){};
Docente :: Docente(string n, string c){
nome = n;
cognome = c;
}
void Docente :: stampa(){
cout << "Docente : " << nome << cognome;
}
string Docente :: getNome(){
return nome;
}
string Docente :: getCognome(){
return cognome;
}
ostream& operator<<(ostream& out,const Docente* d){
out << d->nome << " "<< d->cognome;
return out;
}
istream& operator>>(istream& in, Docente* &d){
in >> d->nome >> d->cognome;
return in;
}
Segreteria.h
codice:
#ifndef SEGRETERIA_H
#define SEGRETERIA_H
#include"Docente.h"
#include"Studente.h"
#include"Materia.h"
#include"Verbale.h"
class Segreteria{
public:
Segreteria();
~Segreteria();
void addDocente();
void addStudente();
void addMateria();
void loadVerbale();
private:
Docente* doc[30];
Studente* stu[300];
Materia* mat[30];
Verbale* ver[50];
};
#endif
Segreteria.cpp
codice:
#include "Segreteria.h"
#include "Docente.h"
#include "Materia.h"
#include "Verbale.h"
#include <iostream>
using std :: cin;
using std :: cout;
using std :: endl;
using std :: istream;
using std :: ostream;
#include <string>
using std :: string;
Segreteria :: Segreteria(){
for(int i = 0; i < 30;i++)
doc[i] = 0;
for(int i = 0; i < 300;i++)
stu[i] = 0;
for(int i = 0; i < 30;i++)
mat[i] = 0;
for(int i = 0; i < 50;i++)
ver[i] = 0;
}
Segreteria::~Segreteria(){
for(int i = 0; i < 30;i++)
if(doc[i])
delete doc[i];
for(int i = 0; i < 300;i++)
if(stu[i])
delete stu[i];
for(int i = 0; i < 30;i++)
if(mat[i])
delete mat[i];
for(int i = 0; i < 50;i++)
if(ver[i])
delete ver[i];
}
void Segreteria :: addDocente(){
cout << "Inserisci nome e cognome docente: ";
for(int i = 0; i < 30; i++)
if(doc[i]==0){
doc[i] = new Docente;
cin >> doc[i];
//doc[i]->stampa();
cout << doc[i];
break;
}
}
void Segreteria :: addStudente(){//Studente: matricola, nome, cognome,cdl
long m;
string n, c, cdl;
cout << "Inserisci matricola, nome, cognome, cdl dello studente: ";
cin >> m >> n >> c >> cdl;
for (int i = 0; i < 300; i++)
if(stu[i] == 0){
stu[i] = new Studente(n, c,cdl,m);
return;
}
}
void Segreteria :: addMateria(){ //string nome,int codice,cfu
string n;
int c, cf;
cout << "Inserisci nome, codice e cfu materia : ";
cin >> n >> c >> cf;
for(int i = 0; i < 30; i++)
if(mat[i] ==0){
mat[i] = new Materia(n,c,cf);
return;
}
}
void Segreteria :: loadVerbale(){
}
main.cpp
codice:
#include "Segreteria.h"
#include<iostream>
using std :: cout;
using std :: cin;
using std :: endl;
#include<string>
using std :: string;
int main(){
Segreteria seg;
while(true)
{
char c;
cout<<endl;
cout << "1)Aggiungi docente" <<endl;
cout << "2)Aggiungi studente" <<endl;
cout << "3)Aggiungi materia" <<endl;
cout << "4)Caricamento nuovo verbale" <<endl;
cout << "0) Esci"<<endl;
cin >> c;
switch(c){
case('1'): seg.addDocente();
break;
case('2'): seg.addStudente();
break;
case('3'): seg.addMateria();
break;
case('4'): seg.loadVerbale();
break;
case('0'): return 0;
}
}
return 0;
}