0
l need an example of struct,please please give a hand
(l did my code,but dont know how to cobtinue) input n and N students' information, including name, his number and 5 class grades, order the input information from large to small and print .
4 Respostas
+ 1
You should really compile your code from time to time, there are quite a few mistakes already...
Fix those and we can look into what's next.
+ 1
there are quite a few typos and errors. what about commenting out code until you get down to something that compiles and works as expected, then add new code progressively? so that when you get stuck there is less code to look at.... you may even find answers by yourself! :-) .
0
and how to cintinue?☞#include <iostream>
using namespace std;
void fun(struct student stu[],int i)
{
for(int k=1;k<=i;k++)
{
450 pos=k-1;
for(int j=k;j<=i-1;j++)
{
if(stru[pos].sum<stu[j].sum)
pos=j;
}
int t=stu[pos];
stu[pos]=stu[k-1];
stu[k-1]=t;
}
}
struct student{
int num;
string name[10];
int grade1;
int grade2;
int grade3;
int grade4;
int grade5;
}stu[10]
int main() {
cout<<"please import students's grades(five subject)"
???????
return 0;
}
0
what about this?where is my mistake?? :
#include <iostream>
using namespace std;
template<class T>
void myswap (T&x,T&y) { //change x to y,change y to x
T temp=x;
x=y;
y=temp;}
template<class T>
void bubbleSort (T a[ ],int n) {
int i=n-1;
while(i>0) {
int lastexchangeindex=0;
for(int j=0; j<i; j++)
{
if (a[ j+1]>a[ j])
{myswap(a[ j],a[ j+1]);
lastexchangeindex=j;}
}
i=lastexchangeindex;
}
}
struct student{
int num;
string name;
int grade1;
int grade2;
int grade3;
int grade4;
int grade5;
};
int main() {
int n;
cin>>n;
student object[n];
for(int x=0;x<n;x++) //imput
cin>>object[n]>>endl;
int score[n];
for(int x=0;x<n;x++) //get the totall score of 5 grades and order the student from large to small
{ score[n]=object[n].grade1+object[n].grade2+object[n].grade3+object[n].grade4+object[n].grade5;
if(score[n]<score[n+1])
bubbleSort(object[n],object[n+1]) }
for(int x=0;x<n;x++) //output
cout<<object[n]<<endl;
return 0;
}