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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
5. 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.
Expert Solution
The following is how the students' test score and test grade are determined:

// 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

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Matrix multiplication
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education