Write a class for Miles.h and Miles.cpp for the UML Mileage
private: miles : double
public: Mileage(m : double):
getMiles():double
getKilometers():double
setMiles(m : double): void
setKilometers(k : double): void
The setKilometers function takes a distance in kilometers and converts to miles for storage.
#ifndef MILES_H #define MILES_H class Miles { private: double miles; public: double getMiles(); double getKilometers(); void setMiles(double m); void setKilometers(double k); }; #endif
#include "Miles.h" double Miles::getMiles() { return miles; } void Miles::setMiles(double m) { Miles::miles = m; } double Miles::getKilometers() { return 1.60934 * miles; } void Miles::setKilometers(double k) { miles = k / 1.60934; }
#include <iostream> #include "Miles.h" using namespace std; int main() { Miles miles; double k; cout << "Enter number of kilometers: "; cin >> k; miles.setKilometers(k); cout << "It's " << miles.getMiles() << " miles" << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.