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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.