{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# strucquiz answer - CS 31 Quiz 14 John A Rohr Gasoline...

This preview shows pages 1–3. Sign up to view the full content.

Sheet1 Page 1 // CS 31 Quiz 14 // February 28, 2007 // John A. Rohr // // Gasoline Mileage Calculator // Array of Structs // This program calculates gasoline mileage // using an array of structs of type double data // Inputs: Odometer readings and gallons of gas. // Output: Miles per gallon. #include <iostream> using namespace std int main() { const int INITIAL_TANKS = 5 // Initial number of purchases struct GasData// Gasoline data struct { double miles // Odometer reading double gallons // Amount of gasoline purchased double mpg // Mileage for purchase } double initialMiles // Initial mileage reading double totalGallons // Total gallons purchased double milesPerGallon // Overall mileage int tank // Tank number int capacity // Maximum number of purchases int index // Accumulate loop index bool done // Done indicator GasData*gas // Gasoline data pointer // Display a program title cout << "GASOLINE MILEAGE CALCULATOR" << endl // Display a blank line cout << endl // Allocate the initial gas data array gas = new GasData[INITIAL_TANKS] // If the gas data array could not be allocated

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Sheet1 Page 2 if (!gas) {
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern