First time working with classes

hey, please help! So the program is suppose to calculates the amount of asphalt needed to pave a road.
The calculation must be in cubic yards. Prompt the user for the length of the road in miles, the width in feet and depth in inches. Convert all to yards and then calculate and display the cubic yards needed.
The parameters for length, width and depth are private variables along with the calculated cubic yards.This program must provide a loop so that you can enter
several different calculations. Start with 10 miles, 300 feet wide and 36 inches
deep then produce several more calculations and desk check your numbers to
ensure your calculations are correct. Do at least 2 more calculations aside from
the original and round all answers to 1 decimal place.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  #include <iostream>

using namespace std;
class Road {
  private:
      double length=0;
      double width=0;
      double depth=0;

  public:
    void setlength (double);
    void setwidth (double);
    void setdepth(double);
    double getlenght()const;
    double getwidth()const;
    double getdepth()const;
    double getvolume()const;
};
//========== Set Functiion ========================
void Road::setlength(double length_road){
length =length_road;
}
void Road::setwidth(double width_road){
width =width_road;
}
void Road::setdepth(double depth_road){
depth =depth_road;
}
//==============Get functions=======================
double Road::getlenght()const{
 return length;
}
double Road::getwidth()const{
 return width;
}

double Road::getdepth()const{
 return depth;
}

double Road::getvolume()const{
 return length *  width * depth;
}


int main()
{
    Road route_1;
    double road_length, road_width, road_depth;


    cout<<"How many volume do you want to calculate?"<<endl;
    int response;
    cin>>response;
     for (int x=0; x<response; x++){
            cout<< "Please enter desired length in miles"<<endl;
    cin>> road_length;

    cout<< "Please enter desired width in feet"<<endl;
    cin>> road_width;

    cout<< "Please enter desired depth in inches "<<endl;
    cin>> road_depth;


     }
 route_1.setlength(road_length *1760);

    route_1.setwidth(road_width *5280);

    route_1.setdepth(road_depth * 2.14);

    cout<<"The lenght is:"<<route_1.getlenght()<<endl;

    cout<<"The width is:"<<route_1.getwidth()<<endl;

    cout<<"The depth is:"<<route_1.getdepth()<<endl;
   cout<<"The Result of the Calculation is:"<<endl;
    cout<<"========================================:"<<endl;
    cout<<"The volume is:"<<route_1.getvolume()<<endl;
 return 0;
}
So what have you got now?
What is your question?
we're suppose to convert the length from miles to cubic yards, width from feet to cubic yards and depth from inches to cubic yards.
i converted them to feet instead and the volume V(cu yrds) = L*W*D/27. but i can't find the conversion of the rest.
What is 1 cubic yard to 1 cm?
SO i finally have the right calculations but it's not giving the result for the second time, the questions are repeated but it's not calculating. I'm really bad with loops, someone please helppppp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <iomanip>

using namespace std;
class Road {
  private:
      double length=0;
      double width=0;
      double depth=0;

  public:
    void setlength (double);
    void setwidth (double);
    void setdepth(double);
    double getlenght()const;
    double getwidth()const;
    double getdepth()const;
    double getvolume()const;
};
//========== Set Functiion ========================
void Road::setlength(double length_road){
length =length_road;
}
void Road::setwidth(double width_road){
width =width_road;
}
void Road::setdepth(double depth_road){
depth =depth_road;
}
//==============Get functions=======================
double Road::getlenght()const{
 return length;
}
double Road::getwidth()const{
 return width;
}

double Road::getdepth()const{
 return depth;
}

double Road::getvolume()const{
 return (length *  width * depth); // V = L*W*D
}


int main()
{
    Road route_1;
     double road_length, road_width, road_depth;
    char response = 'Y';

    cout<< "Please enter desired length in miles"<<endl;
    cin>> road_length;

    cout<< "Please enter desired width in feet"<<endl;
    cin>> road_width;

    cout<< "Please enter desired depth in inches "<<endl;
    cin>> road_depth;


    route_1.setlength((road_length *5280)/3);

    route_1.setwidth((road_width* 1)/3);

    route_1.setdepth((road_depth/12 )/3);



    cout<<"The length of your desired road in cu yd:"<<route_1.getlenght()<<endl;
    cout<< setprecision(2)<<fixed<<road_length<<endl;

    cout<<"The width of your desired road in cu yd:"<<route_1.getwidth()<<endl;
    cout<< setprecision(2)<<fixed<<road_width<<endl;

    cout<<"The depth of your desired road in cu yd:"<<route_1.getdepth()<<endl;
    cout<< setprecision(2)<<fixed<<road_depth<<endl;

    cout<<"The Result of the Calculation is:"<<endl;
    cout<<"========================================:"<<endl;
    cout<<"The volume of your desired road in cu yds is:"<<route_1.getvolume()<<endl;

/* ******* */

    cout<<"Do you need more road calculations?"<<endl;
    cin >> response;
    if (response == 'Y')
    {
    cout<< "Please enter desired length in miles"<<endl;
    cin>> road_length;

    cout<< "Please enter desired width in feet"<<endl;
    cin>> road_width;

    cout<< "Please enter desired depth in inches "<<endl;
    cin>> road_depth;

    cout<<"Do you need more road calculations?";
    cin >> response;
    }
    else if (response == 'N')
    {
        cout<<"Have a good day!"<<endl;
    }




}


 
route_1.setdepth( road_depth * 2.14 );
There are 36 inches in a yard, so your calculation is incorrect.

1
2
3
    route_1.setlength( road_length *1760 );
    route_1.setwidth( road_width * 5280 );
    route_1.setdepth( road_depth * 2.14 );

This will only calculate the values the user entered at the end of the for loop. The previously entered values are discarded.

double Road::getlenght()const{
Spelling error.

round all answers to 1 decimal place.

Have a look at the sample code.
http://www.cplusplus.com/reference/ios/fixed/

1
2
3
4
5
    route_1.setlength((road_length *5280)/3);

    route_1.setwidth((road_width* 1)/3);

    route_1.setdepth((road_depth/12 )/3);

Maybe do this, to make it more readable?
1
2
3
4
5
6

    route_1.setlength(road_length * 1760);

    route_1.setwidth(road_width / 3);

    route_1.setdepth(road_depth / 36);


tweaktwe wrote:

SO i finally have the right calculations but it's not giving the result for the second time, the questions are repeated but it's not calculating. I'm really bad with loops, someone please helppppp
1
2
3
do {

} while( response == 'Y' || response == 'y' );
Last edited on
Thank you, Thats also correct .but i guess i took the long way. i converted; Length in miles to feet then cubic yards which is ( Length*5280)/3, width is already in feet so width/3 and depth in inches, converted to feet then cubic yards (Depth/12)/3. Since they're all converted Volume V= L*W*D. I used a volume calculator to counter check.

i'm just having problems with the loop
Last edited on
NVM ignore that last comment, your way totally shows clarification!
Topic archived. No new replies allowed.