1
#include <iostream>
#include <stdio.h>
#include <string>
void print(float arr[], string nome[], int x){
for (int i=0; i < x; i++){
printf("O aluno %s obteve media de %2.2f\n", nome[i],arr[i]);
}
}
void ordem(float arr[], string nome[], int x){
float aux;
string caux;
for (int i=0; i < x; i++){
for (int j=i+1; j < x; j++){
if (arr[j] > arr[i]){
aux = arr[i];
arr[i] = arr[j];
arr[j] = aux;
caux = nome[i];
nome[i] = nome[j];
nome[j] = caux;
}
}
}
print(arr, nome, x);
}
int main(){
float A1[19], A2[19];
float media[19];
int i=0;
const int x=5;
string nome[x];
while (i < x){
printf("\nDigite o nome do Aluno: ");
scanf("%s", &nome[i]);
printf("\nDigite a nota A1 do %d aluno: ", i+1);
scanf("%f", &A1[i]);
printf("\nDigite a nota A2 do %d aluno: ", i+1);
scanf("%f", &A2[i]);
media[i] = (A1[i] + A2[i])/2;
i++;
}
ordem(media, nome, x);
return 0;
}
Avoid mixing C and C++. Specify Std:: before string.
– anonimo
Since you are using C++, use Std::vector instead of C arrays. Remember to use Std::, which is the namespace where the standard functions are. If you don’t want to, declare: using namespace Std;. But I recommend reading this at SO https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice
– Kevin Kouketsu