I'm just beginner in c++ and seek for help. I learn about separate compilation.Try to observe files below:
Poji1.h
#ifndef POJI1_SPEC
#define POJI1_SPEC
class Poji1 {
public:
Poji1();
void ConvToCent(double* temp);
private:
int j;
};
Poji1.cpp
#include %26lt;iostream%26gt;
#include "Poji1.h"
Poji1::Poji1()
{
j=0;
}
void Poji1::ConvToCent(double* temp)
{
int j;
for(j=0; j%26lt;6; j++)
{
*temp++ *=2.54;
}
}
lain.cpp
#include %26lt;iostream.h%26gt;
#include "Poji1.h"
void main()
{
double dblarr[6]={21.0,32.1,43.2,54.3,65.4,76.5...
int j;
Poji1 P;
for (j=0; j%26lt;6; j++)
{
cout%26lt;%26lt;endl%26lt;%26lt;"dblarr["%26lt;%26lt;j%26lt;%26lt;"]="%26lt;%26lt;dblarr...
}
P.ConvToCent(dblarr);
for(j=0; j%26lt;6; j++)
{
cout%26lt;%26lt;endl%26lt;%26lt;"dblarr["%26lt;%26lt;j%26lt;%26lt;"]="%26lt;%26lt;dblarr...
}
}
The errors are:
%26gt;ch -u ./lain.cpp
ERROR: member function '::Poji1()' not defined
at line 8 and ERROR: member function '::ConvToCent()' not defined at line 13 in file C:\Documen. Help!
Separation compilation problem ; C/C++?
need to make your functions public.
Reply:Kai says he's not going to answer that question
Reply:Just two hints. 1. C++ object members are private by default, not public. 2. When you use multiple files look up the extern key word.
I won't say any more, lest this be for a class.
Tuesday, July 14, 2009
Needed clarification in C and C++..?
Can i make the my user defined function as a part of C or C++ library? If so please guide me the procedure..
Can i define my own pre-processor directive and place my user-defined function in that directive?..Please tell me the procedure too..
Thanks..
Needed clarification in C and C++..?
Make a file called abc.h
Put your function in it.
Include abc.h into your source file using the preprocessor directive:- #include "abc.h"
If abc.h is in the same directory as C/C++ source file no need to give path else give path.
Reply:Create a file filename.c that includes your own functions, but without a main() function being defined.
Compile it. An error appears saying "main moudule
missing."
This indicates that .obj file of your C program is created.
Now you can use #include "filename.c" as a header.
See to that your filename.c file is placed in the current directory.
Thank you.
baseball cards
Can i define my own pre-processor directive and place my user-defined function in that directive?..Please tell me the procedure too..
Thanks..
Needed clarification in C and C++..?
Make a file called abc.h
Put your function in it.
Include abc.h into your source file using the preprocessor directive:- #include "abc.h"
If abc.h is in the same directory as C/C++ source file no need to give path else give path.
Reply:Create a file filename.c that includes your own functions, but without a main() function being defined.
Compile it. An error appears saying "main moudule
missing."
This indicates that .obj file of your C program is created.
Now you can use #include "filename.c" as a header.
See to that your filename.c file is placed in the current directory.
Thank you.
baseball cards
Please write a code in c++?
Write a C/C++ program which contain four user define functions mul(), readmat1(), readmat2(),and Display()
readmat1 () function read first matrix (array) from user readmat2 () read second matrix (array) from user
Display() function display these two matrices and mul() multiply the two matrices (arrays) and display the
Resultant Matrix (array).
Write main function and call all these function in it.
Please write a code in c++?
Hi,
Pls check out this link for the complete program and logic
https://www.cs.tcd.ie/Glenn.Strong/CS1/1...
Hope this helps to you..!!!
Saravanan.
readmat1 () function read first matrix (array) from user readmat2 () read second matrix (array) from user
Display() function display these two matrices and mul() multiply the two matrices (arrays) and display the
Resultant Matrix (array).
Write main function and call all these function in it.
Please write a code in c++?
Hi,
Pls check out this link for the complete program and logic
https://www.cs.tcd.ie/Glenn.Strong/CS1/1...
Hope this helps to you..!!!
Saravanan.
How to create librariees in c?
i am told that if i want to use user defined functions of one c program can be used in the other c program, i have to store them in library. i don't know how to create the libraries in the language c. can any one tell me how to create libraries in c?
And also can any one suggest me the best reference book for the language c?
How to create librariees in c?
The best reference book would be "Let us C"
http://www.fallensword.com/?ref=1105967
And also can any one suggest me the best reference book for the language c?
How to create librariees in c?
The best reference book would be "Let us C"
http://www.fallensword.com/?ref=1105967
In C Function - before initializing a char variable, the char contains same junk - why?
With in a C program, I have a local C Function. In this function, I define a local char pointer. Before initializing the char, the char contains same junk value, even if I run millions of times - why?
How come the memory space contains the same junk char value - always?
In C Function - before initializing a char variable, the char contains same junk - why?
I'll give you the general answer. It'll be uninitialized because nothing initialized it to begin with. If it appears to be uninitialized every time you run, it could be the physical address is changing on each run. Now in your case, it sounds like you're looking at the same physical address each time, overwriting it, and re-running to see the data you overwrote. Either the overwrite failed, or between runs perhaps something else used the space. Your debugger can verify the overwrite if you dump the address space contents before leaving your program. As far as what uses that space after, there are software tools that let you watch writes to an address, but as you can imagine they're very intrusive and may end up changing the behavior you're seeing.
Reply:That's the way C language operates. Before initialization, your variable contains unexpected data.
This is a source of many bugs actually. Other programming languages might prohibit you from using unassigned variables (such as C Sharp)
Hope this helps.
Reply:Ok, as you know a local variable's value is stored on the stack--and you're asking why the uninitialized value of a local character variable doesn't return random data. The simple fact is that you are initializing values on the stack and then re-using them when you call the the function and examine the value of the local variable. As suggested in another answer, you can prove all this to yourself using a debugger. I like gdb that comes with gnu-c. Examine your stack and addresses that your local variables point to, etc. The debugger is an excellent way for you learn C and all of its nuances.
Good Luck
How come the memory space contains the same junk char value - always?
In C Function - before initializing a char variable, the char contains same junk - why?
I'll give you the general answer. It'll be uninitialized because nothing initialized it to begin with. If it appears to be uninitialized every time you run, it could be the physical address is changing on each run. Now in your case, it sounds like you're looking at the same physical address each time, overwriting it, and re-running to see the data you overwrote. Either the overwrite failed, or between runs perhaps something else used the space. Your debugger can verify the overwrite if you dump the address space contents before leaving your program. As far as what uses that space after, there are software tools that let you watch writes to an address, but as you can imagine they're very intrusive and may end up changing the behavior you're seeing.
Reply:That's the way C language operates. Before initialization, your variable contains unexpected data.
This is a source of many bugs actually. Other programming languages might prohibit you from using unassigned variables (such as C Sharp)
Hope this helps.
Reply:Ok, as you know a local variable's value is stored on the stack--and you're asking why the uninitialized value of a local character variable doesn't return random data. The simple fact is that you are initializing values on the stack and then re-using them when you call the the function and examine the value of the local variable. As suggested in another answer, you can prove all this to yourself using a debugger. I like gdb that comes with gnu-c. Examine your stack and addresses that your local variables point to, etc. The debugger is an excellent way for you learn C and all of its nuances.
Good Luck
How to write an exponetial equation in C code/language?
i am trying to define the following funtion in C code could some please tell me the exact syntax on how to declare this
f(x) = e^(-x^2)
this is how someone told me to do it but it doesnt work
#include(math.h)
y= exp(-x,2)
How to write an exponetial equation in C code/language?
the function is
pow(base, exponent);
and you DO have to include math.h
First define e
const float e = 2.78; //proabably want to be more exact
int x;
x = 10;
pow(e, pow(x, 2)); //This caluculates e to the value of x (which is 10) squared.
Reply:exp(pow(-x,2));
artificial flowers
f(x) = e^(-x^2)
this is how someone told me to do it but it doesnt work
#include(math.h)
y= exp(-x,2)
How to write an exponetial equation in C code/language?
the function is
pow(base, exponent);
and you DO have to include math.h
First define e
const float e = 2.78; //proabably want to be more exact
int x;
x = 10;
pow(e, pow(x, 2)); //This caluculates e to the value of x (which is 10) squared.
Reply:exp(pow(-x,2));
artificial flowers
These are all true/false questions for C programming?
1. The preprocessor directive #define RING 1 tells the C preprocessor to replace each occurrence of the constant RING with 1.
2. The fourth element of an array named bob is bob[4]
3. All arrays with 10 elements require the same amount of memory.
4. A function with return type void always returns the value 0.
5. A function prototype tells the compiler nothing about the value that is returned by the function.
6. When an array is passed to a function, the address of the array is passed to the function and a copy of the elements is made for the function to manipulate.
These are all true/false questions for C programming?
Good luck doing your own homework!
(And neither of the two answerers below is 100% right, btw.)
Reply:1). true
2). false
3). true
4). false
5). true
6). false.
Ok now you won't learn anything from these true/false answers...
Reply:Why can't you do your own homework?
Reply:1 t
2 f
3 t
4 t
5 f
6 t
2. The fourth element of an array named bob is bob[4]
3. All arrays with 10 elements require the same amount of memory.
4. A function with return type void always returns the value 0.
5. A function prototype tells the compiler nothing about the value that is returned by the function.
6. When an array is passed to a function, the address of the array is passed to the function and a copy of the elements is made for the function to manipulate.
These are all true/false questions for C programming?
Good luck doing your own homework!
(And neither of the two answerers below is 100% right, btw.)
Reply:1). true
2). false
3). true
4). false
5). true
6). false.
Ok now you won't learn anything from these true/false answers...
Reply:Why can't you do your own homework?
Reply:1 t
2 f
3 t
4 t
5 f
6 t
Subscribe to:
Posts (Atom)