Answer to Question #225533 in C++ for Dhruvi

Question #225533
Write a C++ program to create a class Distance which has parameters as miles. In main function take an int as kilometre. Write code to convert miles into kilometre. 1 KM = 0.621 miles)
1
Expert's answer
2021-08-12T16:24:29-0400
#include <iostream>
#include <string>






using namespace std;


class Distance{
private:
	int kilometres;
public:
	//Distance which has parameters as kilometres
	Distance(int kilometres){
		this->kilometres=kilometres;
	}
	double convertKilometresToMiles(){
		return this->kilometres* 0.621;
	}
};


int main()
{
	int kilometres;
	cout<<"Enter kilometres: ";
	cin>>kilometres;
	Distance distance(kilometres);
	cout<<"Miles: "<<distance.convertKilometresToMiles()<<"\n";


	cin>>kilometres;
	return 0;
}






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS