/******************************************************************/ /* Program
ID: 3805265 • Letter: #
Question
/******************************************************************/
/* Program chapter4_5 */
/* */
/* This program computes and prints the pseudorange for */
/* 4 satellites. It also prints the number of the satellite */
/* that is closest to the receiver. */
#include<iostream> //Required for cout
#include<cfloat> //required for DBL_MAX
using namespace std;
int main()
{
//Declare and initialize objects
const double C(299792458.0); //meters per second
const int NUMBER_OF_SATELLITES(5);
int satID, minID,maxID;
double tTime, pRange, minPRange(DBL_MAX), maxPRange(0);
//Prompt user for input
cout << "Enter id and transit time for "
<< NUMBER_OF_SATELLITES << " satellites: "
<< "Use whitespace to separate the values(ie: 25 0.00567) "
<< endl;
for (int i = 1; i <= NUMBER_OF_SATELLITES; ++i)
{
cin >> satID >> tTime;
pRange = tTime*C;
//Check for closest satellite
if (pRange < minPRange)
{
minPRange = pRange;
minID = satID;
}
if (pRange > maxPRange)
{
maxPRange = pRange;
maxID = satID;
}
cout << "Satellite " << satID << " has a pseudorange of "
<< pRange << " m " << endl;
}
//Output ID of closest satellite
cout << " Satellite " << minID
<< " is closest to GPS receiver with range =" <<minPRange<< endl;
//Output ID of farthest satellite
cout << " Satellite " << maxID
<< " is farthest from GPS receiver with range =" <<maxPRange<< endl;
system("pause");
return 0;
}
Explanation / Answer
/******************************************************************/
/* Program chapter4_5 */
/* */
/* This program computes and prints the pseudorange for */
/* 4 satellites. It also prints the number of the satellite */
/* that is closest to the receiver. */
#include<iostream> //Required for cout
#include<cfloat> //required for DBL_MAX
using namespace std;
//Main function definition
int main()
{
//Declare and initialize objects
const double C(299792458.0); //meters per second
const int NUMBER_OF_SATELLITES(6);
int satID, minID,maxID;
double tTime, pRange, minPRange(DBL_MAX), maxPRange(0);
//Prompt user for input
cout << "Enter id and transit time for "<< NUMBER_OF_SATELLITES << " satellites: "
<< "Use whitespace to separate the values(i.e.,: 25 0.00567) "
<< endl;
for (int i = 1; i <= NUMBER_OF_SATELLITES; ++i)
{
cin >> satID >> tTime;
pRange = tTime*C;
//Check for closest satellite
if (pRange < minPRange)
{
//Updates the minimum P Range to current pRange
minPRange = pRange;
//Updates minimum Id to current satellite id
minID = satID;
}//End of if condition
//Checks for the farthest satellite
if (pRange > maxPRange)
{
//Updates the maximum P Range to current pRange
maxPRange = pRange;
//Updates maximum Id to current satellite id
maxID = satID;
}//End of if condition
cout << "Satellite " << satID << " has a pseudorange of "
<< pRange << " m " << endl;
}
//Output ID of closest satellite
cout << " Satellite " << minID
<< " is closest to GPS receiver with range =" <<minPRange<< endl;
//Output ID of farthest satellite
cout << " Satellite " << maxID
<< " is farthest from GPS receiver with range =" <<maxPRange<< endl;
return 0;
}//End of main
Output:
Enter id and transit time for 6 satellites:
Use whitespace to separate the values(i.e.,: 25 0.00567)
3098 .00234 1243 .00101 1111 .00099 9876 .00567 2018 .00901 7777 .00777
Satellite Number3098 Measured Transit times701514 m
Satellite Number1243 Measured Transit times302790 m
Satellite Number1111 Measured Transit times296795 m
Satellite Number9876 Measured Transit times1.69982e+006 m
Satellite Number2018 Measured Transit times2.70113e+006 m
Satellite Number7777 Measured Transit times2.32939e+006 m
Satellite 1111 is closest to GPS receiver with range =296795
Satellite 2018 is farthest from GPS receiver with range =2.70113e+006
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.