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

Assume that PrecinctReport is a structured type with these fields, address (a st

ID: 3795195 • Letter: A

Question

Assume that PrecinctReport is a structured type with these fields, address (a string ), and three int fields which are counts of crimes in the given precinct: felonies, murders, and robberies. Assume that NPRECINCTS is a pre-declared int constant and that an array named allPrecincts with NPRECINCTS elements , each of type PrecinctReport has been declared and initialized Assume that an int variable murderCount has been declared . Write the necessary code that traverses the allPrecincts array and adds up all the murder counts storing the resulting total in murderCount.

Explanation / Answer

struct PrecinctReport{
   string address;
   int felonies;
   int murders;
   int robberies;
};

PrecinctReport allPrecincts[NPRECINCTS];

int murderCount = 0;

// code to get the sum of all murders
for(int i=0; i<NPRECINCTS; i++)
   murderCount = murderCount + allPrecincts[i].murders;

Please let me know in case of any issue

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