Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*avendo 3 vettori di 10 posizioni
- registrare nome cognome e voto
- stampare il nome e cognome col voto più alto
- stampare il nome più corto
- usare le funzioni per scrivere il codice
- stampare il cognome più lungo*/
- #include <iostream>
- #include <string>
- using namespace std;
- void caricaStringhe(string v[],int dim);
- void caricaVoto(int v[],int dim);
- void votoAlto (string v1[], string v2[],int v3[],int dim);
- void stampa (string v1[],string v2[],int dim);
- int main(){
- int dim=3 ;
- string v1[dim],v2 [dim];
- int v3[dim];
- cout << "inserimento dei nomi" << endl;
- caricaStringhe(v1, dim);
- cout << "inserimento dei cognomi " << endl;
- caricaStringhe(v2, dim);
- cout << "inserimento dei voti" << endl;
- caricaVoto(v3,dim);
- votoAlto(v1,v2,v3,dim);
- stampa(v1,v2,dim);
- return 0;
- }
- void caricaStringhe(string v[],int dim){
- for(int i =0;i<dim;i++){
- cout<<"inserisci la stringa "<<i+1<<" nel vettore ";
- cin>>v[i];
- }
- }
- void caricaVoto(int v[],int dim){
- for(int i =0;i<dim;i++){
- cout<<"inserisci il voto "<<i+1<<" nel vettore ";
- cin>>v[i];
- }
- }
- void votoAlto(string v1[],string v2[],int v3[],int dim){
- int max = v3[0];
- string str1 , str2;
- for(int i=0;i<dim;i++){
- if (max < v3[i]){
- max=v3[i];
- str1=v1[i];
- str2=v2[i];
- }
- }
- cout<<str1<<" "<<str2<<" ha preso il voto più alto :"<<max <<endl;
- }
- void stampa(string v1[],string v2[],int dim){
- int min=0;
- int max=0;
- string str1 ,str2;
- for(int i=0; i<dim; i++){
- if(min > v1[i].length()){
- min=v1[i].length();
- str1= v1[i];
- }
- if(max < v2[i].length()){
- max=v2[i].length();
- str2= v2[i];
- }
- }
- cout<<"il nome più corto è"<<str1<<endl;
- cout<<"il nome più lungo è"<<str2<<endl;
- }
- /*non capisco perhce non mi da il nome più corto..*/
Add Comment
Please, Sign In to add comment