4. On what line number(s) are arrays declared? 7. For every function you identif
ID: 3919370 • Letter: 4
Question
4. On what line number(s) are arrays declared?
7. For every function you identified in #4 above:
a. Is the function ever called?
b. What are the function’s arguments?
c. What value, if any, does the function return?
// Ex4_01.cpp
2) // Calculating gas mileage
3) #include
4) #include
5)
6) using std::cin;
7) using std::cout;
8) using std::endl;
9) using std::setw;
10)
11) int main()
12) {
13) const int MAX {20}; // Maximum number of values
14) double gas[ MAX ]; // Gas quantity in gallons
15) long miles[ MAX ]; // Odometer readings
16) int count {}; // Loop counter
17) char indicator {'y'}; // Input indicator
18)
19) while( ('y' == indicator || 'Y' == indicator) && count < MAX )
20) {
21) cout << endl << "Enter gas quantity: ";
22) cin >> gas[count]; // Read gas quantity
23) cout << "Enter odometer reading: ";
24) cin >> miles[count]; // Read odometer value
25)
26) ++count;
27) cout << "Do you want to enter another(y or n)? ";
28) cin >> indicator;
29) }
30)
31) if(count <= 1) // count = 1 after 1 entry completed
32) { // ... we need at least 2 cout << endl << "Sorry - at least two readings are necessary.";
33) return 0;
34) }
35)
36) // Output results from 2nd entry to last entry
37) for(int i {1}; i < count; i++)
38) {
39) cout << endl
40) << setw(2) << i << "." // Output sequence number
41) << "Gas purchased = " << gas[i] << " gallons" // Output gas
42) << " resulted in " // Output miles per gallon
43) << (miles[i] - miles[i - 1])/gas[i] << " miles per gallon.";
44) }
45) cout << endl;
46) cout <<
47) return 0;
48)
}
Explanation / Answer
4. On what line number(s) are arrays declared? Answer: 14, 15 7. For every function you identified in #4 above: function name: setw a. Is the function ever called? Answer: yes b. What are the function’s arguments? Answer: 2 c. What value, if any, does the function return? Answer: ostream object
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.