So I made the mistake of not even attempting the program before asking for help, so I started on it. This is my current code so far and I have a few questions:
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
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const double PI = 3.14159265358979323846;
struct Cone
{
double height;
double radius;
};
int main()
{
struct Cone *ptr;
double height;
double radius;
Cone new;
input();
return 0;
}
void input()
{
int height, radius;
cout << "Enter height of the cone followed by the radius." << endl;
cin >> height;
cin >> radius;
}
void setUp()
{
}
int getVolume(int *ptr)
{
int Volume;
Volume = ( PI * radius * height ) / 3;
return Volume;
}
void output()
{
}
|
My program directions are - - -
The volume of a cone is given by the formula:
V = N r2 h / 3
For the value of N use:
const double PI = 3.14159265358979323846;
Declare a structure named: Cone
containing:
height a double, the height of the cone
radius a double, the radius of the base of the cone
Create the following functions:
main
* Contains three variables:
o A pointer named ptr which points to a Cone structure
o A double named height
o A double named radius
* Uses new to obtain space for the data structure
* Calls the the input, setUp, and output functions
* Deletes the space that was obtained using new
input:
* Takes the height of the cone and radius of the base as reference
parameters
* Reads the height and radius from the user
* Has a return type of void
setUp:
* Takes three parameters by value: height, radius, and a pointer to
the Cone
* Puts the data into the data structure
* Has a return type of void
getVolume:
* Takes one parameter by value: a pointer to the Cone
* Computes the volume
* Returns the volume
output:
* Takes one parameter by value: a pointer to the Cone
* Calls the getVolume function to get the volume
* Prints the height, radius, and volume in a neat format
* Has a return type of void
Put the main function first.
Use the function and variable names specified above.
Arrange the functions in the order listed above.
Test your program with the following data:
height 6
radius 2
So my question(s) is "Uses new to obtain space for the data structure" How do I express this in code? And when something has a return type of void that is just ending the function with a } correct? And in the lab I posted above it uses "parameters" very often, is that just another word for variable? Also I was wondering if I used the ptr pointer correctly that points to cone.
Thanks!