Stay out of the swamp land. Assume that you want to cross a swamp by hitting the fewest number of mud pits. The mud pits are indicated by a ‘X’ on a m by n matrix. You must start in the first column and end in the last column. Each move can be to the right, to the right and up, or to the right and down. Construct an algorithm to determine the minimal number of mud pits that must be traversed to get across the swamp. State the time efficiency of your approach.
// loop for calculating test_score
for(int i=0;i<5;i++){
double score=0;
for(int j=0;j<20;j++){
if(stud[i].answers[j]=='_'){
continue;
}
else if(stud[i].answers[j]==result[j]){
score+=4;
}else{
score-=1;
}
}
stud[i].test_score=(score/40)*100;
}
// loop for calculating test_grade
for(int i=0;i<5;i++){
if(stud[i].test_score>90){
stud[i].test_grade='A';
}else if(stud[i].test_score>80){
stud[i].test_grade='B';
}else if(stud[i].test_score>70){
stud[i].test_grade='C';
}else if(stud[i].test_score>60){
stud[i].test_grade='D';
}else if(stud[i].test_score>50){
stud[i].test_grade='E';
}else{
stud[i].test_grade='F';
}
}
This is how student structure is sorted and then displayed and then minimum, maximum, and average of scores is calculated:
// loop for sorting array of structures on the basis
// of student_id
for(int i=0;i<4;i++){
for(int j=i+1;j<5;j++){
if(stud[i].student_id.compare(stud[j].student_id)>0){
struct student st;
st=stud[i];
stud[i]=stud[j];
stud[j]=st;
}
}
}
// outputResults function definition
void outputResults(student s[], int size){
cout<<"StudentID\tAnswers\t\t\t"<<"%"<<"Score\tGrade"<<endl;
for(int i=0;i<5;i++){
cout<<s[i].student_id<<"\t"<<s[i].answers<<"\t\t\t"<<s[i].test_score<<"\t"<<s[i].test_grade<<endl;
}
return;
}
double max=stud[0].test_score;
int idmax=0;
int idmin=0;
double min=stud[0].test_score;
double sum=stud[0].test_score;
// loop for finding maximum and minimum score
for(int i=1;i<5;i++){
if(max<stud[i].test_score){
max=stud[i].test_score;
idmax=i;
}
if(min>stud[i].test_score){
min=stud[i].test_score;
idmin=i;
}
sum+=stud[i].test_score;
}
cout<<"Min score is "<<min<<"%"<<" for Student ID "<<stud[idmin].student_id<<endl;
cout<<"Max score is "<<max<<"%"<<" for Student ID "<<stud[idmax].student_id<<endl;
cout<<"Average is "<<(sum/5)<<"5";
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images