In: Computer Science
I'm not sure i understand sending parameters and reference and i think im doing it wrong. In this code i'm trying to enter notas (grades) by user input into the exArrays, getting the promedio (average) and printing it on screen.
I've searched a lot of videos but they don't help. The lenguage is C++
void entrarNotas(int ex1Array[], int ex2Array[], int ex3Array[],
int sizeSalon, char notaPara, float promedioPara)
{
cout << "Entrar cuantos estudiantes hay en el
salon" << " :";
cin >> sizeSalon;
for (int k = 0; k < sizeSalon; k++)
{
cout << "Entre las notas del
estudiante " << ": " << k + 1;
cin >> ex1Array[k] >> ex2Array[k] >> ex3Array[k] ;
}
for (int i = 0; i < sizeSalon; i++)
{
promedioPara = ex1Array[i] +
ex2Array[i] + ex3Array[i];
promedioPara = promedioPara /
3.0;
}
for (int i = 0; i < sizeSalon; i++)
{
if (promedioPara >= 90)
notaPara =
'A';
else if (promedioPara >=
80)
notaPara =
'B';
else if (promedioPara >=
70)
notaPara =
'C';
else if (promedioPara >=
60)
notaPara =
'D';
else
notaPara =
'F';
}
}
void imprimir(int ex1Array[], int ex2Array[], int ex3Array[],
int sizeSalon, char notaPara, float promedioPara)
{
for (int k = 0; k < sizeSalon; k++)
{
cout << "Notas del
estudiante" << ": " << k + 1 << ex1Array[k]
<< ", " << ex2Array[k] << ", " <<
ex3Array[k] <<", " << promedioPara <<", "
<< notaPara;
}
}
int main()
{
int ex1[40], ex2[40], ex3[40], nota;
float promedio;
entrarNotas(ex1, ex2, ex3, nota, promedio);
imprimir(ex1, ex2, ex3);
return 0;
}
/* * C++ program */ #include <iostream> using namespace std; #define MAX 3 void entrarNotas(int ex1Array[], int ex2Array[], int ex3Array[], int sizeSalon, char notaPara[], float promedioPara[]) { float tempPromedio; for (int i = 0; i < sizeSalon; i++) { cout << "Entre las notas del estudiante " << i + 1 << ": "; cin >> ex1Array[i] >> ex2Array[i] >> ex3Array[i] ; } for (int i = 0; i < sizeSalon; i++) { tempPromedio = ex1Array[i] + ex2Array[i] + ex3Array[i]; promedioPara[i] = tempPromedio / 3.0; } for (int i = 0; i < sizeSalon; i++) { if (promedioPara[i] >= 90) notaPara[i] = 'A'; else if (promedioPara[i] >= 80) notaPara[i] = 'B'; else if (promedioPara[i] >= 70) notaPara[i] = 'C'; else if (promedioPara[i] >= 60) notaPara[i] = 'D'; else notaPara[i] = 'F'; } } void imprimir(int ex1Array[], int ex2Array[], int ex3Array[], int sizeSalon, char notaPara[], float promedioPara[]) { for (int k = 0; k < sizeSalon; k++) { cout << "Notas del estudiante" << ": " << k + 1 << ex1Array[k] << ", " << ex2Array[k] << ", " << ex3Array[k] <<", " << promedioPara[k] <<", " << notaPara[k] << endl; } } int main() { int ex1[MAX], ex2[MAX], ex3[MAX]; int size; char nota[MAX]; float promedio[MAX]; cout << "Entrar cuantos estudiantes hay en el salon" << ": "; cin >> size; entrarNotas(ex1, ex2, ex3, size, nota, promedio); cout << endl; imprimir(ex1, ex2, ex3, size, nota, promedio); return 0; }
Note: Drop comments, for queries.