online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
// Programa que demuestra ordenamiento de estructuras // Utilizando reglas multiples en C++ #include <algorithm> #include <string> #include <iostream> using namespace std; struct Student { string name; // Dado int math; // Notas de Matemática (Dado) int phy; // Notas de Fisica (Dado) int che; // Notas de Quiica (Dado) int total; // Suma Total de notas (debe calcularse) int rank; // Rank of student (debe calcularse) }; // Funcion para comparar a dos estudiantes // de acuerdo con las reglas establecidas bool compareTwoStudents(Student a, Student b) { // Si la suma total de notas no son iguales // retorna verdadero para el total mayor if (a.total != b.total) return a.total > b.total; // Si las notas de matematica no son las mismas, entonces // retorna verdadero para las mas altas if (a.math != b.math) return a.math > b.math; // lo mismo para las notas de fisica if (a.phy != b.phy) return a.phy > b.phy; // por ultimo retorna verdadero para las notas // mas altas de quimica return (a.che > b.che); } // Calcula los totales de las notas y el ranking de todos los estudiantes void computeRanks(Student a[], int n) { // Calcula el total para todos los estudiantes for(int i=0; i<n; i++) a[i].total = a[i].math + a[i].phy + a[i].che; // Ordena el arreglo de estructuras usando // la funcion especial compareTwoStudents() sort(a, a+5, compareTwoStudents); // Asigna el ranking despues de ordenar for(int i=0; i<n; i++) a[i].rank = i + 1; } int main() { int n = 5; // Arreglo de objetos tipo estructura Student a[n]; // Detalle del estudiante 1 a[0].name = "Bryan"; a[0].math = 80; a[0].phy = 95; a[0].che = 85; // Detalle del estudiante 2 a[1].name = "Lorenzo"; a[1].math = 95; a[1].phy = 85; a[1].che = 99; // Detalle del estudiante 3 a[2].name = "Nicolas"; a[2].math = 95; a[2].phy = 85; a[2].che = 80; // Detalle del estudiante 4 a[3].name = "Frank"; a[3].math = 80; a[3].phy = 70; a[3].che = 90; // Detalle del estudiante 5 a[4].name = "Raul"; a[4].math = 80; a[4].phy = 80; a[4].che = 80; computeRanks(a, n); // Nombre de Columnas para mostrar la informacion cout<<"Ranking"<<" "<<"Nombre"<<" "; cout<<"Matematica"<<" "<<"Fisica"<<" "<<"Quimica"; cout<<" "<<" Total\n"; // Mostrar los detalles de los estudiantes for(int i=0; i<n; i++){ cout<<a[i].rank<<"\t"; cout<<a[i].name<<"\t\t"; cout<<a[i].math<<"\t" <<a[i].phy<<" " <<a[i].che<<"\t"; cout<<a[i].total<<" "; cout<<"\n"; } return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue