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

Using the Star structure defined in file p1.cpp, write the function named magnit

ID: 3604972 • Letter: U

Question

Using the Star structure defined in file p1.cpp, write the function named magnitudeBetween(). The function takes three input parameters: a vector of Stars as well as a lower and upper bounds. The function returns a vector of size_t containing indexes of the stars whose magnitude falls between the two bounds (exclusive). Please explain your steps if possible . Thanks.

p1.cpp:

*/
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <cmath> // already included for you
using namespace std;

// The structure (don't change these)
struct Star {
double x, y;
double magnitude;
int draperNumber;
string names;
};

vector indexes; indexes magnitudeBetween (vStars, 1.5, 3.4);

Explanation / Answer

Please finf the function definition of magnitideBetween() below:

//Definition of function magnitugeBetween
vector<size_t> magnitudeBetween(vector<Star> vStars,double upper,double lower)
{
//Declare a vector indexes
vector<size_t> indexes;
//Loop through all the elements in the vStars vector
for (int i=0;i< vStars.size(); i++)
{
//Check if magnitude is between upper & lower bound, if true add the index of the star to the vector indexes
if (vStars[i].magnitude > lower && vStars[i].magnitude < upper )
indexes.push_back(i);
}
  
//Return the vector indexes
return indexes;
  
}

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