Create a Road class(C++, include a .h file, cpp file, driver file). The class sh
ID: 3664029 • Letter: C
Question
Create a Road class(C++, include a .h file, cpp file, driver file). The class should have functions for setting the width of the road in feet and the length of the road in miles. It should also have functions for getting the width of the road and the length of the road (2 separate functions). Those 2 functions should not have code for a prompt for the user or for input. The user interaction should be in the driver file. Create a function called asphalt that will accept a road thickness as an input parameter, then, on the basis of the thickness, it will compute and return the number of cubic feet of asphalt needed to pave the road (1 mile = 5280 feet). Test each function of the class thoroughly with a driver file.
Explanation / Answer
ROAD.CPP file having road as class
#include<iostream>
using namespace std;
class road
{
private:
int length;
int width;
public:
//setter methods
void set_length(int l);
void set_width(int w);
//getter methods
int get_length();
int get_width();
int asphalt(int thick);
};
//Setters
void road::set_length(int l)
{
length = l;
}
void road::set_width(int w)
{
width = w;
}
//Getters
int road::get_length()
{
return length;
}
int road::get_width()
{
return width;
}
//asphalt method
int road::asphalt(int thick)
{
int noofCubeFeet = thick * get_length()*5280*get_width();
return noofCubeFeet;
}
DRIVER.CPP file
#include<iostream>
#include"ROAD.CPP"
using namespace std;
int main()
{
int widht, length, thickness;
cout<<"enter the widht of road "<<endl;
cin<<width;
cout<<"enter the length of road "<<endl;
cin<<length;
cout<<"enter the thickness of road "<<endl;
cin<<thickness;
road r1;
r1.set_width(widht);
r1.set_length(length);
int requiredcubeFeets = r1.asphalt(thickness);
cout<<"the required cubefeets are"<<requiredcubeFeets<<endl;
}