Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Modify the program to find the satellite that is farthest from the receiver (rgh

ID: 3551272 • Letter: M

Question

Modify the program to find the satellite that is farthest from the receiver (rght now it finds the one that is closest)


ORIGINAL:

#include <iostream>

#include <cfloat>

using namespace std;

int main()

{

    const double C(299792458.0);

    const int NUMBER_OF_SATELLITES (5);

    int satID, minID;

    double tTime, pRange, minPRange (DBL_MAX);

    cout << "Enter id and transit time for "

    << NUMBER_OF_SATELLITES << " satellites: "

    << "Use whitespace to separate the values(ie: 25 0.00257) "

    << endl;

    for(int i=1; i<=NUMBER_OF_SATELLITES; ++i)

    {

        cin >> satID >> tTime;

        pRange = tTime*C;

        if(pRange < minPRange)

        {

            minPRange = pRange;

            minID = satID;

        }

    cout << "Satellite " << satID << " has a pseudorange of "

    << pRange << " m n" << endl;

    }

    cout << " Satellite " << minID

    << " is closest to GPS receiver." << endl;

    return 0;

}

?

Explanation / Answer

#include <iostream>

#include <cfloat>

using namespace std;

int main()

{

    const double C(299792458.0);

    const int NUMBER_OF_SATELLITES (5);

    int satID, minID;

    double tTime, pRange, minPRange (DBL_MAX);

    cout << "Enter id and transit time for "

    << NUMBER_OF_SATELLITES << " satellites: "

    << "Use whitespace to separate the values(ie: 25 0.00257) "

    << endl;

    for(int i=1; i<=NUMBER_OF_SATELLITES; ++i)

    {

        cin >> satID >> tTime;

        pRange = tTime*C;

        if(pRange > minPRange)

        {

            minPRange = pRange;

            minID = satID;

        }

    cout << "Satellite " << satID << " has a pseudorange of "

    << pRange << " m n" << endl;

    }

    cout << " Satellite " << minID

    << " is closest to GPS receiver." << endl;

    return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote