I confused by saying C class when I meant C++ class. C does not have classes. Corrected.
Have you read the tutorial to which doug4 showed you? (Or the equivalent in your native language.)
Some of your problems with this code is that you copied mutexe's code offered in another thread. You changed it before you understood it.
By the way, why do you start new threads? I realize this is a "new" program, but you copied most of it from another thread. If you are going to do that, just reply in that thread so the context is understood.
So what compilation errors and warnings is your code displaying?
I get the following errors:
1><snip>\areacircumference.cpp(8): error C2143: syntax error : missing ';' before 'public'
1><snip>\areacircumference.cpp(17): error C2653: 'twoDShape' : is not a class or namespace name
1><snip>\areacircumference.cpp(32): error C2062: type 'void' unexpected
= |
Do you know how to interpret the warnings and errors your compiler gives you?
For example, my first error is in the file areacircumference.cpp at line 8. For this compiler the error is numbered C2143 but it does not matter. The error on line 8 is "syntax error : missing ';' before 'public'. The error stems from several lines before because we are in a function definition and not a class declaration.
Here is your code with many additional comments.
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
|
#include<iostream>
#include <cmath>
using namespace std;
void twoDShape() // Defines (and declares) a function named twoDShape
{
public: // the "public:" keyword only belongs in a C++ class declaration.
// This is a
double addonenumber(double rad); //--> Function Decleration
/* So twoDShape has no executable code. So calling it does nothing. */
};
// .cpp file - THE IMPLEMENTED FUNCTIOON
void twoDShape::addonenumber(double rad)
/* Defines a function named twoDShape::addonenumber which takes a double parameter named rad.
However there is no namespace named nor class declared twoDShape. */
{
const double PI = 3.14;
double circum=1;
double area=1;
// do the math
circum = PI * 2 * rad; // circumference of a circle
area = PI * pow(rad,2.0); // area of a circle
return void;
/* void is a keyword which is a type.
The return statement expects return <expression>;.
A type is not an expression.
Since this function is defined to return a void type, you could just use return;
However, since this is the end of the function and the return type of your function is void,
there is no need for a return statement.
circum and area will no longer exist or have values at the end of this function. They will "go out of scope". */
}
int main()
{
double rad;
double circum;
double area;
int i=1;
// display question
while (rad != -1)
{
cout << "\nWhat is your radius (-1 to stop) : " << endl;
cin >> rad; // except input
// display answer
if (rad != -1)
{
cout << "the area is " << area <<" and the circumference is" << circum <<endl;
cout<< twoDShape<<endl; /* Since twoDShape is defined above as a function,
this will display the pointer to the function twoDShape
if cout, which is an object of ostream,
has a member function for operator << with the parameter is void (*)().
void (*)() is the type for a pointer to a function with no parameters
and does not return a value. */
}
else
cout<< "Thank You!"<<endl;
i++;
}
return 0;
}
|