| | |
What is wrong with the following class definition?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 0
Please can anyone tell me in few words What is wrong with the following class definition? whait's missing, etc.
C++ Syntax (Toggle Plain Text)
Class Numeric { private: long x; public ... void set (long n) const { x = n; } long get () { return x; } const }
Last edited by Ancient Dragon; Feb 18th, 2009 at 9:00 am. Reason: add code tags
•
•
Join Date: Feb 2009
Posts: 21
Reputation:
Solved Threads: 0
I would appreciate if you or anyone else would have a good will and explain me several more questions. We actually don't need to write programs just to explain some things in c++ (classes)
this question for example
6. Suppose class X includes a data elements common declared as public. How can it be
accessed by all functions in the same name space ?
and these first 2 ones ..
1. Consider the following declarations
bool func1 (double, double&, double&);
bool func2 (double, double*, double*);
double x = 9.7, y = 0.0, z = 0.0;
bool res;
Call each function with arguments x, y, and z. The return value shall be assigned to the
variable res.
2. Please write and test a function strReverse() that reverses the order of characters in a given
string. The string is passed to the function as a read-only reference. The function returns a
read-only reference to the result.
I will need to present so all help would be appreciated.
this question for example
6. Suppose class X includes a data elements common declared as public. How can it be
accessed by all functions in the same name space ?
and these first 2 ones ..
1. Consider the following declarations
bool func1 (double, double&, double&);
bool func2 (double, double*, double*);
double x = 9.7, y = 0.0, z = 0.0;
bool res;
Call each function with arguments x, y, and z. The return value shall be assigned to the
variable res.
2. Please write and test a function strReverse() that reverses the order of characters in a given
string. The string is passed to the function as a read-only reference. The function returns a
read-only reference to the result.
I will need to present so all help would be appreciated.
I'll tell you how to get the strReverse() done. Since this is a home assignment I'll only tell you how you could do it.
First of all you need to decide whether you want to do it the string or char * (C-string) way.
If I was to do this in C-string way (the way I usually do it personally) I'd first get the text length. Next I'd make a loop that puts all characters backwards to a newly allocated char *, for example:
If this works then you almost have it done actually.
Of course you could find the solution easily on the web, but this isn't the way it should be done, is it?
Hope this helps.
First of all you need to decide whether you want to do it the string or char * (C-string) way.
If I was to do this in C-string way (the way I usually do it personally) I'd first get the text length. Next I'd make a loop that puts all characters backwards to a newly allocated char *, for example:
for(int i=length;0<=i<=length;i--){ /*your code*/ } If this works then you almost have it done actually.
Of course you could find the solution easily on the web, but this isn't the way it should be done, is it?
Hope this helps.
Last edited by venomxxl; Feb 17th, 2009 at 3:11 pm.
in your first post, you need to end the class with a ; after the closing brace
you would access it by creating an instance of the class in a declaration,
for example.
Now, you want to set the value "hello!" to the char* publicMember.
How would you do that if you had declared
access members of the object's class using a period after the object name.
C++ Syntax (Toggle Plain Text)
class name { ... };
cpp Syntax (Toggle Plain Text)
class clName{ ... public: char* publicMember; };
Now, you want to set the value "hello!" to the char* publicMember.
How would you do that if you had declared
char* publicMember in the scope you were working in? It works the same, you just have to identify that publicMember is a "member" of a class. This is not a static variable, so first you need an object, declared as an instance of your class... C++ Syntax (Toggle Plain Text)
clName objectName;
I wake up! And my mind's out, never again will I sell out. Converting vegetarians.
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
Into the midnight giving it to you, I don't know it just feels right.
This is the time of the revolution, Cooking the next step.
Converting vegetarians, minding the gap since 1996
![]() |
Similar Threads
- Another C++ N00B Begging For Help (C++)
- constructor with an array as an argument (C++)
- Change "<table..." definition with preg_replace_callback (PHP)
- NewBie to Java needs some Help PLEASE!!! (Java)
- String declaration in class definition (C)
- HELP writing structure and class definition - Visual C++ (C++)
- creating a class and declaring objects (C++)
- unresolved external symbol when using a hashtable class (C++)
- Error in c++ program (C++)
- Can't update a textbox in Visual C++ (C++)
Other Threads in the C++ Forum
- Previous Thread: How do I get classes within a class???
- Next Thread: 2D Vector Memory Problems
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





