vendredi 28 juillet 2017

How to Calculate MPG miles per gallon using Classes in C++

Hello I need help understanding C++ in dumb down term can any one help me understand how to calculate MPG using classes. this is what i have so far. I want really want to get better but every program been kicking my but in class.

#include <iostream>
using namespace std;

class cars{
    double miles;
    double gallons;
private:
    double miles[6] = {240.5, 300.0, 320.5, 280.7, 190.7, 265.3};
    double gallons[6] = {16.4, 15.6, 17.2, 15.4, 13.7, 16.9};

public:
    cars(double m, double g) : miles(m), gallons(g){}
    double mpg(void) {return miles / gallons;}
};


int main() {
    int i;
    cout << "Index\tMiles\tGallons\tMPG\n";
    for (i=0; i<6; i++) {
        cout << i << "\t" << miles[i] << "\t" << gallons[i] << endl;
    }
    char z; cin >> z;
}

Aucun commentaire:

Enregistrer un commentaire