Question
Study the C++ code that appears on the next page and answer the following questions. 1. On what line number(s) are if statements located? 2.
Study the C++ code that appears on the next page and answer the following questions.
1. On what line number(s) are if statements located?
2. On what line number(s) are case statements located?
3. On what line number(s) are loops located?
4. On what line number(s) are arrays declared?
5. On what line number(s) are arrays accessed?
6. On what line number(s) are function(s) declared?
7. For every function you identified in #4 above:
a. Is the function ever called?
b. What are the functions arguments?
c. What value, if any, does the function return?
1) // 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) }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started