Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write the function starsBetween() I added the p1.cpp file contents below the question. We are just starting structures, streams and vectors. I appreciate the help

write the function starsBetween()

image text in transcribed

I added the p1.cpp file contents below the question. We are just starting structures, streams and vectors. I appreciate the help

/**

CS 150 Vectors and Structures

Below you'll find a definition for a Star structure

similar to the one we used in class, but a little simpler.

Write the function called starsInSector(), following the

instructions in your handout.

*/

#include

#include

#include

#include

#include // already included for you

using namespace std;

// The structure (don't change these)

struct Star {

double x, y;

double magnitude;

int draperNumber;

string names;

};

///////////////// WRITE YOUR FUNCTION BELOW THIS LINE ///////////////////////

function here

///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE ///////////////////////

ostream& operator&);

void studentTests()

{

cout

cout

const vector vStars = {

{-0.516566, -0.340233, 4.53, 124675, "BOO KAPPA"},

{-0.391537, 0.791148, 1.16, 62509, "POLLUX; GEM BETA"},

{-0.798418, 0.601749, 4.54, 82446, "HYA TAU"},

{0.544153, 0.174444, 4.34, 6961, "CAS THETA"},

{-0.843478, 0.099816, 3.54, 100407, "HYA XI"},

{-0.455459, -0.603227, 4.98, 138629, "BOO NU"},

{-0.298198, 0.387683, 3.35, 71369, "MUSCIDA; UMA OMICRON"},

{-0.696134, 0.155399, 3, 96833, "UMA PSI"},

{-0.916842, 0.246614, 4.08, 95272, "ALKES"},

{0.11301, 0.945279, 2.58, 36673, "ARNEB"},

{0.214075, -0.813927, 3.25, 176437, "SULAFAT; LYR GAMMA"},

{0.305802, 0.232677, 4.46, 15089, "CAS IOTA"},

{0.658924, -0.733896, 3.78, 198001, "ALBALI"},

{0.820248, 0.448325, 2.64, 11636, "SHERATAN"},

{-0.263867, 0.822592, 4.41, 54719, "GEM TAU"},

{0.148253, -0.755971, 5.37, 173608, "LYR EPSILON"},

{-0.741021, -0.628146, 3.78, 129246, "BOO ZETA"},

{-0.188502, -0.981846, 5.89, 156247, "U OPH"},

{0.147985, -0.755362, 6.02, 173583, "LYR EPSILON"},

{-0.317623, 0.871206, 3.5, 56986, "WASAT; GEM DELTA"},

};

vector names;

starsInSector(vStars, names, -1, -1);

cout

cout [BOO KAPPA, BOO NU, BOO ZETA, U OPH]"

cout "

cout

cout

}

ostream& operator& v)

{

out

int len = v.size();

if (len > 0)

{

out

for (int i = 1; i

out

}

out

return out;

}

3 THE starsBetween PROBLEM Using the Star structure defined in file p1.cpp, write the function named starsBetween() The function takes three input parameters: a vector of Stars as well as a lower and upper bounds. The function returns a double representing the average magnitude of the stars falling between the two bounds (exclusive). If no stars are in the range, then return -1. In addition, the function has an output parameter that returns the names of the stars that are included. vector names; double avg starsBetween (vStars, names, 2.3, 2.4); Input parameter Output parameter

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

threat analysis and exploitation Law enforcement sector on SAR

Answered: 1 week ago