Ciao! Ho risolto per quella parte, ma ho un altro problema:
codice:
#include <iostream>
using namespace std;
struct studente
{
char nome[20];
char cognome[20];
int votoesameelementi;
};
void stampa_studente(studente a[], int indice)
{
cout << " Il nome dello studente è : " << a[indice].nome << endl;
cout << " Il cognome dello studente è : " << a[indice].cognome << endl;
cout << " Il voto dello studente è : " << a[indice].votoesameelementi << endl;
}
void costruisci_vettore(studente a[], studente b[], int voto_dato, int indice)
{
for(int i=0; i<indice; i++)
{
if(a[i].votoesameelementi > voto_dato)
{
b[i].votoesameelementi = a[i].votoesameelementi;
for(int c=0; a[i].nome[c] =! '0'; c++)
{
b[i].nome[c] = a[i].nome[c];
}
for(int d=0; a[i].cognome[d] =! '0'; d++)
{
b[i].cognome[d]=a[i].cognome[d];
}
}
}
}
void stampa_voto_dato(studente a[], int voto_dato, int indice)
{
if (a[indice].votoesameelementi > voto_dato)
{
cout << " Uno studente con il voto maggiore rispetto al voto dato è lo studente di cognome : " << a[indice].cognome << endl;
}
}
void ricerca_studente(studente a[], int dim)
{
char surname[20];
cout<< " Inserisci cognome da ricercare : ";
cin>>surname;
for(int indice=0; indice<dim; indice++)
{
if(a[indice].cognome==surname)
{
cout << " I dati dello studente cercato sono : " << endl << a[indice].nome << endl << a[indice].cognome << endl << a[indice].votoesameelementi << endl;
}
}
}
int main()
{
int n=0;
cout << " Quanti sono gli studenti ? ";
cin >> n;
studente a[n];
// Inserisci informazioni
for(int i = 0; i < n; i++)
{
cout << " Per lo studente numero " << i+1 << endl;
cout << " Inserisci nome : ";
cin >> a[i].nome;
cout << " Inserisci cognome : ";
cin >> a[i].cognome;
cout << " Inserisci voto : ";
cin >> a[i].votoesameelementi;
cout << endl;
}
//Stampa informazioni dei primi due studenti inseriti
for (int i=0; i<=1; i++)
{
cout << " Dati dello studente " << i+1 << " : " << endl;
stampa_studente(a, i);
cout << endl;
}
//Stampa studenti con voto maggiore di un dato voto
int voto_minimo;
cout << " Inserisci voto minimo : ";
cin >> voto_minimo;
for (int i=0; i<n; i++)
{
stampa_voto_dato(a, voto_minimo, i);
}
//Ricerca di uno studente
ricerca_studente(a, n);
return 0;
}
Non riesco ad utilizzare la funzione ricerca e non capisco come la funzione che costruisce il vettore di studenti con voto maggiore di un voto dato debba essere inserita nel main.