Completely Screwed

Hey guys, I'm definitely screwed here and was wondering if anyone would lend a hand. I have 3 programs to write and not a lot of time to do it in. I've been having some trouble at home, so I haven't had time to write the programs, nor take the time to study C++ thoroughly to complete these projects. If anyone could help me, it would be loads of appreciation and praise. These programs would take someone who's good at C++ twenty minutes to write I know, but for someone who has little knowledge of C++ and little time due to helping my mom out with financial stuff, it's a little tough to get done. If anyone is interested, I will put all the project information down below.
---------------------------------------------------------------------------------

Diameter of a Tanker Truck

Assume the tanker is a cylinder of length 43 feet and volume 9500 gallons. What is the diameter of the tanker in feet? Your program must interactively input the capacity of the tanker in gallons and its length in feet. The program should then calculate and display the resulting diameter in feet.

------------------------------------------------------------------------------

Volume of a tanker truck, Using a struct

Define a struct called TankerTruck. This struct should have three fields: the diameter, the length and the volume of the tanker truck.

-----------------------------------------------------------------------------

Honestly I don't know how to compute the diameter... so that's for you to fill out (it doesn't have to do as much with programming as it does with math).

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
#include <iostream>

unsigned int compute_diameter(unsigned int length, unsigned int volume)
{
    unsigned int diameter;

    // uhh... compute diameter here... I forgot the formula
    return diameter;
}

int main()
{
    struct TankerTruck
    {
        unsigned int length;
        unsigned int volume;
        unsigned int diameter;
    };

    TankerTruck tt;

    std::cout << "Tanker capacity? Input: ";
    std::cin >> tt.volume;
    std::cout << "Tanker length? Input: ";
    std::cin >> tt.length;
    tt.diameter = compute_diameter(tt.length, tt.volume);
    std::cout << "Tanker diameter is: " << tt.diameter << ".\n";
}
Thanks Catfish. The hard part for me is the code. I haven't fully learned the syntax of it all. I have until 1PM this afternoon to get these projects done. If it wasn't for life getting in the way, I would have all this down pat, but like I said, I've been helping my mom out financially, so working 70 hours a week and trying to go to college at the same time is rough. Any help is definitely appreciated. Even if it's just to get my brain kick started.

I can do the math, just not the code for these problems and the code is the most important part. I had to take today off just to be able to get all of this done.
radius of tanker = incorrect formula
Last edited on
For planning inside my head of how the code will appear in the first program. The one that doesn't require a struct, will it be possible to do something like this? I want to start getting my head around using functions in every program that I write for now on. This is the code that I've got so far planned out. Thank you again Catfish for sharing that with me. That's going to help me on the next project.

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
#include <iostream>
#include <cmath>
using namespace std;

void tankerTruck();
void tankerRadius();
void tankerDiameter();


int main()
{
    
    tankerTruck();
    
    cout << "The answer: " << tankerRadius(radius);
    
    system("pause");
    return 0;
}
void tankerTruck()
{
     int length;
     int gallons;
     
     cout << "Please enter the length in feet of the truck: ";
     cin >> length;
     cout << "Please enter the amount of gallons: ";
     cin >> gallons;
}
void tankerRadius(float length, float gallons)
{
    float radius = sqrt((77 * gallons) / (576 * M_PI))* length;
    
    system("pause");
}
void tankerDiameter()
{

}
Minor suggestion: consider leaving an empty line between function definitions. As in:
1
2
3
4
5
6
7
8
9
10
11
int main()
{
    // code
}

void tankerTruck()
{
    // code
}

// and so on 


A problem I see is that function declarations and function definitions aren't in agreement: specifically tankerRadius(). The declaration of that, above main(), should be:

1
2
3
4
5
void tankerRadius(float length, float gallons);

// or

void tankerRadius(float, float);


You also call tankerRadius() with a single parameter radius in main(), when it expects two parameters, neither of which are the radius.

Then, the function tankerTruck() contains two local variables of type int: length and gallons. These variables, being local, will "die" as soon as the function tankerTruck() finishes. What's more, they are not visible outside that function.

At this point I suggest reading:
http://www.cplusplus.com/doc/tutorial/functions/
I made a mistake when converting gallons into feet3. Actual formula:
radius in feet = sqrt[ (gallons * 77) / (length * Pi) ] / 24
Last edited on
Thanks Catfish, I definitely will look at that. I've got my book and about 20 pages open on my browser. I'm a little overwhelmed at this point, so thinking is really difficult right now. I've done away with the functions for now just so I can get the math inside my head. If this is the right way to do the math, please let me know. Thanks again for your help Catfish! You're becoming my hero right now lol


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 int main()
{
     int length, gallons;
     float radius;
     float diameter;
     
     
     cout << "Please enter the length in feet of the truck: ";
     cin >> length;
     cout << "Please enter the amount of gallons: ";
     cin >> gallons;
     
     radius = sqrt((77 * gallons) / (576 * M_PI)) * length;
     diameter = radius * 2;
     
     
     cout << "Answer: " << radius << endl;
     cout << "The diameter is: " << diameter << endl;
     
     system("pause");
     return 0;
}
Awesome, thanks for the correction miiniPaa, I'm making that correction now.

What's funny is I actually met a guy who said he was good at C++ and knew it, so I thought it he would be able to help me, but apparently he couldn't even get the first chapter figured out. I've been up for almost 24 hours trying to get this stuff done and still my progress is slim. This is the last project I have and then I can get some sleep.
I've been up for almost 24 hours trying to get this stuff done and still my progress is slim. This is the last project I have and then I can get some sleep.

From what I see, if MiiNiPaa's formula is correct (I'm too dumb to know) then you have completed the project.

If you're not required to write a version using more functions besides main(), then I would say skip it for now, and maybe get back to it when you have more energy, if it's important. Your "project information" as you call it doesn't mention extra functions?
Last edited on
That's true about not needing functions, but the more work I put into it, the better the grade will be. Although to be honest, at this point I'm just looking to pass the class. I had an A in C++, but this last bit has me scratching my head.

I'm thinking about paying one of those C++ sites to get these projects done for me and I'll learn it later today. Too pressed for time though.. Like the title says, I'm screwed haha!

Thank you again for your help though guys.
Topic archived. No new replies allowed.