ArkM 1,090 Postaholic

Of course, it's possible but templates per se do not bear a relation to your problem. You want polymorphism: the most powerful concept of OOP implemented in C++. There are lots of articles and tutorials on this topic (and there are lots of DaniWeb solved threads).
For example, look at http://www.cplusplus.com/doc/tutorial/polymorphism.html
and/or http://www.softlookup.com/tutorial/c++/ch13.asp
In other words, you need an array of pointers to MyBaseClass, not void* pointers!

ArkM 1,090 Postaholic

1. You may assign any type object pointer to a void* pointer variable without explicit conversion - no need in reinterpret_cast:

void* pvoid[3];
pvoid[0] = &mc1; // or what else

2. It's possible but what for? All three variables mc1, mc2, mc3 have absolutely different types. Can you provide some loop examples where such void* pointer array elements are sensibly processed?

ArkM 1,090 Postaholic

May be your VC++ 6.0 installation was not patched properly (upto Service Pack 6 or 5, I don't remember now). In actual fact there were errors in VC++ 6.0 but as usually I have found some workarounds...

Apropos, a possible reason of the strange output:

printf("%f\t%f\t%f\t%f\n",m_Length,m_Width,m_Height,volume);
// () missed after volume

It's impossible to detect this error in compile time. That's why awkward C++ streams are better than old good printf ;)

Frederick2 commented: thanks! +1
ArkM 1,090 Postaholic

Obviously, the presented output was printed by another (version of) program (no member names in this snippet printf).
Of course, VC++ 6.0 is too old compiler but I have worked with it many years and never have troubles with printf...

Try to replace printf to cout << and see what happens...

ArkM 1,090 Postaholic

And don't forget to terminate the last token when break the loop...

ArkM 1,090 Postaholic

Didn't you see that you show TWO open file dialog windows? You close the 1st dialog and immediately show the 2nd one in if expression...
What for the 1st line of your snippet?

Please, next time use code tag properly:
[code=c++] text

[/code]

ArkM 1,090 Postaholic

I need to write a small application which can be used to store html from any web server. I have written some code that is able to fetch HTML page along with header. I need to know is there any way to distinguish these headers from actual html content. Can I have the way to use this header to know file name and its size etc. which is already there in Headers.

Of course, anybody had worked on this: anybody wrote your browser, anybody wrote DaniWeb web-server engine. All these beasts generate and parse http headers ;)

HTTP message header lines are simple text lines: what's additional header do you want to process text lines? An empty line (CRLF) terminates header fields.
See:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Also you may download dlib C++ library:
http://dclib.sourceforge.net/
There is an example in the dlib distribution: a simple http-server. Read the code, run this example: it shows all http message header lines from your request.

The most interesting counter-question: are you sure that you say about HTTP message header? Or it's HTML header? Feel the difference (by the way, no HTTP word in your help request message body) ;)...

ArkM 1,090 Postaholic

Please, read your C++ book again (at least how to declare class variables and access its members).
It seems all you know about C++ at the moment: // comments and operator << ;)
Probably you can't understand the answer to your question now ( age.("name") = age; - it's cool! )...

ArkM 1,090 Postaholic

For example, i have char variable = "This is a simple text";
and i need to put word "Very" between "a" and "simple"
How to do it using standart C library?

Use strstr library function to search "Very" in the string. If it's found make a room at this point (shift right all chars started from the point with trailing zero byte - a c-string is an array of char, use memmove or write a for loop). Now move "simple" to the free room (by memcpy or memmove - don't forget to append blank after "simple" word).
That's all.
Write the code, debug it then come back on some troubles ;)

ArkM 1,090 Postaholic

It's unclear where global array definitions were placed. Probably, these #ifndef...char[][]={}...#endif chain was placed twice.
Place extern declarations only fragment in separated .h file, include it in .c modules where external arrays access needed. External arrays definitions (declarations with initialization) must be placed in one and only one source file (it's c-file, not h-file).
Next time try to describe your project file structure more clearly.
That's all.

ArkM 1,090 Postaholic

Alas, it's wrong solution because sizeof(T[])/sizeof(T) does not bear a relation to an array size: it's the same as sizeof(T*)/sizeof(T) . Remember: it's impossible to get an array size from type name[] declaration.
Look at:

template <typename T>
class Sequence
{
public:
    Sequence() {}
    Sequence(const T a[], size_t n): terms(a,a+n)
    {} // Use one of std::vector constructors
    void print() const { // illustrative
        for (size_t i = 0; i < terms.size(); ++i)
            std::cout << terms[i] << '\n';
        std::cout.flush();
    }
    //~Sequence(); // No need for the present.
protected:
    std::vector<T> terms;
};

int main()
{
    int arr[] = { 1, 2, 3 };
    Sequence<int> is(arr,sizeof arr/sizeof(arr[0]));
    is.print();
    std::string s[] = { "s1", "s2", "s3" };
    Sequence<std::string> ss(s,sizeof s/sizeof *s);
    ss.print();
    return 0;
}
ArkM 1,090 Postaholic

For example, download free Matrix TCL Lite 1.13 by Techsoft:
http://www.techsoftpl.com/matrix/download.htm
(it's not a recommendation, I never use this library but it's compact and simple;) ).
Comment 5 lines of abs definitions in downloaded matrix.h:

/* Do that, you can't compile it with VC++ when <complex> included
#if ( defined(__BORLANDC__) || _MSC_VER ) && !defined( __GNUG__ ) 
inline float abs (float v) { return (float)fabs( v); } 
inline double abs (double v) { return fabs( v); } 
inline long double abs (long double v) { return fabsl( v); }
#endif
*/

Now

#include <complex>
using namespace std;
#include "matrix.h"

typedef complex<double> Complex;
typedef math::matrix<Complex>  CMat;

int main()
{
    CMat m(2,2);
    m(0,0) = Complex(0,1);
    m(0,1) = m(1,0) = 0.0;
    m(1,1) = Complex(0,1);

    cout << m.Det() << endl;
    
    return 0;
}
// prints (-1,0)

Read package manual in pro_doc directory...

ArkM 1,090 Postaholic

i know that when i include <iostream> i include a header file not a library. That is why my question is how the compiler knows the associated library with that header.

So simple answer: it does not know that ;)
The compiler includes external symbol references to library function names in the generated object module. That's a linker job to assemble an executable module from all object modules and all libraries to resolve all external references in all object modules (compiled and extracted from libraries).
If you work with IDE there are default paths to all RTL libraries so IDE passes these paths to the linker (all C++ headers declare functions collected in these libraries). Sometimes you need to present additional library paths (for example, if you have used windows.h header file or other non-standard headers). You must know what libraries needed and where they located (from docs, of course)...

ArkM 1,090 Postaholic

The C++ Standard (16.2):

2 A preprocessing directive of the form
# include <h-char-sequence> new-line
searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.
3 A preprocessing directive of the form
# include "q-char-sequence" new-line
causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read
# include <h-char-sequence> new-line
with the identical contained sequence (including > characters, if any) from the original directive.

ArkM 1,090 Postaholic

... when we called constructor , it allocate memory for the object . right .

A constructor does not allocate memory for the object. It does not know how to do that. Think about:

class C { public: C(); C operator+(const C&); }
...
C c; // static storage
void f() {
     C c; // automatic storage
     ...
     C* pc = new C(); // dynamic storage
     ... *pc + C ... // unspecified temporary storage

It's the same C::C() called!

ArkM 1,090 Postaholic

Can you tell me which compiler(version) is suitable for doing exception handling?

Have you ever read Ancient Dragon's post?
Use Code::Blocks IDE with MinGW compiler (the same as frozen Dev-C++ IDE used):
http://www.codeblocks.org/

ArkM 1,090 Postaholic

Well, class System HAS a vector of Schools. In other words, every System object contains a set of Schools.
But class School IS a kind of System (by inheritance). So every School has a set of Schools?!..
Hmm...

ArkM 1,090 Postaholic

1. You have made a very bad style functional decomposition. Why an array is global? Define all processing functions with processed array and array size parameters. Never burden your functions with redundant external dependencies. You CreateArray function does not create an array (it was created by a declaration statement), it fills or initialize it!
2. Never use file_stream << ... << endl for bulk file output operations. The std::endl means "write new line and flush buffers". No need in file buffer flush operation in that case (it's too slow). Use file_stream << ... << '\n' pattern.
3. About palindromes. You may get every digit via n%10 ... n /= 10 expressions or make a text representation of the number via std::stringstream output or even old good sprintf function. Try to invent some approaches to palindromic test yourself then (may be) ask more help ;)...
4. Print 10000 numbers to the console... Oh, my God! WHAT FOR?! ;)

ArkM 1,090 Postaholic

...though it's usually a better idea to design your class so as to not need a default value.

It's not so easily to design an intrusive container class for elements without default constructor (no underlying arrays, for example).

ArkM 1,090 Postaholic

After reading up on them in terms of class hierarchy, they seem to just be almost like comments, to remind you that all classes use this sort of function

???!!!
It's a false statement (or I misunderstand the post).

ArkM 1,090 Postaholic

If other "modules" (mean and median) look like this function mode I can't imagine how you "have everything working but the mode".
1. It seems you must "find the mean, median and mode of an array of numbers". If so, why you get array values in the function mode body? You need special module (or function) to get array values then find and print mean, median and mode of this array by separate functions. No needs to read array values again and again in every function.
2. About "modular programming". You print array twice (before and after sorting) with for loops. Is it a good example of "modularity"? Where is printarray function (module)? ;)
3. Read the mode term definition again. For example, see http://www.socialresearchmethods.net/kb/statdesc.php):

The mode is the most frequently occurring value in the set of scores

You have a sorted array and now all you need: count occurencies of every value and return a value corresponded to max counter. That's a code sceleton:

int currvalue = a[0]; // start from the 1st element
int counter = 1;
int maxcounter = 1;
int modevalue = a[0];
for (int i = 1; i < n; ++i) {
    if (a[i] == currvalue)
        ++counter;
    else { // next value started...
        if (counter > maxcounter) { // new mode candidate
            maxcounter = counter;
            modevalue = value;
        }
        currvalue = a[i]; // ready to count next values
        counter = 1;
    }
}
// Check last value, copy code... …
ArkM 1,090 Postaholic
ArkM 1,090 Postaholic

You (and me) can create a homepage with Notepad only ;)

ArkM 1,090 Postaholic

hmmmm dude i was busy with some other issues.

Just the TIME to go on with that issues ;)...

ArkM 1,090 Postaholic

1. You got UNICODE string so convert it in (almost) ordinar C-string before pass it to std::string constructor.

char cstrValue[1024];
...
if (WideCharToMultiByte(
    CP_ACP, 0,
    rgValue,-1,cstrValue,sizeof cstrValue,
    0,0))
{
    // you got it! You may printf cstrValue
}

2. Don't pass std::string in printf directly, std::string object is not a pointer to string contents so your program has 100% chance to crash. Use c_str() member function:

printf("Path %s\n",path.c_str());

Why printf? cout << path << endl;

ArkM 1,090 Postaholic

If you define relative file name (not full path - for example, "name.txt" only) then it's not a Vista problem. At run-time the current directory is not the same as exe module directory so the program can't access external files via relative file names.

ArkM 1,090 Postaholic

int* a parameter treated as a local variable in the function body. See what happens when you call the function:

size_t n = 2008;
int* parr = new int[n]; 
// parr points to a new memory chunck of 2008 integers.
...
newInt(2008,parr,n); 
// pointer parr value initializes local a parameter of newInt
// (pass parameter by value)
// n passed by reference so it's possible to change it.
... function body works with copy of parr
// parr has the same value as before newInt call,
// but now it points to deallocated (by newInt) memory!

You can pass parr by reference too (declare parameter a as int*& a or pass a pointer to parr (declare parameter a as int** a and use *a = temp to change parr value.

ArkM 1,090 Postaholic

So I think I now have Ship*&, which should actually be Ship&.
Is there any way to convert Ship*& to Ship&?

Yes, of course: use unary operator *(). But I'm not sure that it helps ;)

ArkM 1,090 Postaholic

It's not an "old compiler" issue, it's normal behaviour for floating point data calculations. You have not the right to an "exact" result for these calculations. Only integral numerical types get "exact' results. The "obscure" value -5.77338e-017 is a good approximation for least valued bits of double type mantissa. Now remember that 0.9 and 0.96 numbers (periodical binary fractions) have no exact double representation at all...

Salem commented: Yes, e-017 is pretty close to 0 +23
Freaky_Chris commented: Thanks for pointing this out +1
ArkM 1,090 Postaholic

The C++ Standard:

A non-template constructor for class X is a copy constructor if its first parameter is of type X&, const X&, volatile X& or const volatile X&, and either there are no other parameters or else all other parameters have default arguments (8.3.6 ). Example: X:: X(const X& ) and X:: X(X&, int=1) are copy constructors.

Other alternatives of... what?...

ArkM 1,090 Postaholic

Storm in a teacap. Totally absurd code and its "rationale":

Account data = new Account[arraySize];

I tried to do that as a final resort because even public functioncs of the Account class are giving errors while reading into the customer, private member of Account. I get a Access violation saying the memory could not be read. Any suggestions? It seems like my Array, savings is not working properly.

Are you sure that an even number of errors helps you to write correct codes? You have run-time errors. Why you are trying to play with program syntax in that case? Access violations do not bear a relation to a private or public member access rules. Have you ever seen the Debug menu choice?

ArkM 1,090 Postaholic

You have invented a rather strange one-time list where new members are inserted in the head and the first traversal is at the same time the last possible one. After the 1st call of (incorrect) printarea the list becomes unusable. It losts all elements.

Well, non-destructive Dynamic::printarea looks like

void Dynamic::printarea()
{
    for (Shapelink* plink = lastone; 
         plink != 0; 
         plink = plink->next) {
        plink->item->print_area();
    }
}

There are lots of other defects in your code but it's another story ;)...

ArkM 1,090 Postaholic

What about Buffer Overflow? :P

Look at the requirements: if you forgot strcpy specification I can recall, try to search the target size there ;)

ArkM 1,090 Postaholic

Regrettably, it's not ArkM's algorithm. It's K&R code.
Thank you, Ancient Dragon: this code is OK, it copies null byte ;)

ArkM 1,090 Postaholic

Remember the K&R masterpiece:

while (*dest++ = *src++);

Unforgettable Algol 68's genes are still alive in C and C++ ;)...

ArkM 1,090 Postaholic

Wrong using of a POINTER constant defined as NULL macros in C:

while( str1[i] != NULL) /* wrong */
/* Right code: */
while (str1[i]) /* (I prefer this form); or */
while (str[i] != '\0') /* or */
while (str[i] != 0)

The C compiler can define NULL as (void*)0 or simple 0. In the 1st case you are trying to compare char promoted to int with a pointer to void.
Moral: NULL is not a zero alias in C, use NULL only for pointer values.

ArkM 1,090 Postaholic

1. That's because the modification (improvement) of getSmallest and getLargest functions was incorrect. It was wrong solution to assign a role of for loop counter to output parameter count (why "count" if it's an index of? ). Think: the 1st count value is 1 (must be 0) and the last is 12 (then you add 1 and print 13). Make obvious correction.
2. Look again to getAverage code: it's WRONG!!!
Ooh, that's right code:

double getAverage(double array[], int size)
{
    return getTotal(array,size) / size;
}
Foe89 commented: A little uptight but gave good hints without giving away the answer +1
ArkM 1,090 Postaholic
n = strlen(nummer);
for (int i = 0; i < n; i++) {
    if (nummer[i] <= '0' || nummer[i] >= '9') {
        for(int j = i; j < n; j++){
        nummer[j] = nummer[j + 1];
    ...
ArkM 1,090 Postaholic

Everytime I call getTotal I get some sort of syntax error.

???

ArkM 1,090 Postaholic

Only getTotal code is correct. All three other fuctions are wrong.
1. getAverage: use getTotal to obtain a sum of all elements then divide sum by the number of elements!
2. getLargest and getSmallest: why double largest = array[100]; ?! No such element in the array at all. Start from array[0] value then loop from index 1.

ArkM 1,090 Postaholic

Alas, your attempts to get direct access to the class Account private members display only your C++ and OOP knowledge (and programming skill level ;) ). The Account class designer declared public interface to ordinar class clients. Nobody should try to get more: that's class designer decision. Do you want to get customer data? Use getCustomer() member function. It returns a const pointer to C-string. Is it customer member value? Mind your own business, it's my private member - said class Account designer...

May be it helps you to understand one of the most fundamental OOP concepts - incapsulation ;)

ArkM 1,090 Postaholic
inline
char* Min(char* a, char* b, char* c) {
    return
        strcmp(a,b) < 0
        ? strcmp(a,c) < 0? a: c
        : strcmp(b,c) < 0? b: c;
}

;)

ArkM 1,090 Postaholic

Though I am stuck with how to append new data into existing employee database, I am really getting towards the end of the program. I will put the program (if its allowed) when its finished.

Never pack all the program functionality in the single monoblock main function. Remember "divide and power" principle. Functional decomposition is one of the most valued concepts especially in C programming.
Make int WriteRecord(const Record* prec, FILE* f) function. Let it writes five lines (from Employee to No. of projects worked) from Record data fields (and, for example, returns 0 on success and != 0 on failure or vice versa).
Make int NewRecord(Record* prec) function. Let it gets data fields from cosole (with prompting and data checks) and returns proper values on success or cancel.
Now you can write simple and clear code with these function calls. Don't forget that you must open file in append mode. Also you can't delete or update records in place (they have varying lengths), you need to write all records in the new (temporary) file - move old records, skip deleted records, append new records - then delete old file and rename the new one.

ArkM 1,090 Postaholic

Thank you.
Forgive "bad words". It was a joke.
But the variable e counts lines, not words (at least in the original snippet). That's why I don't understand your words about word numbers.
May be better post your current code again...

ArkM 1,090 Postaholic

Let's start from the beginning. Probably the best way to go is to define ReadRecord function. Let it gets the next person record from the file. A new record started from "Employee xx" line then four data lines followed. You know how to detect "Employee" word. Define struct Record, for example:

#define NSZ 50
typedef struct _Record {
    char emp[NSZ];
    char name[NSZ];
    ... /* add other data field */
} Record;

#define LSZ 512
int ReadRecord(Record* prec, FILE* f)
{
    char line[LSZ];
    int done = 0; /* return 0 == read failed or eof */
    if (fgets(line,sizeof line,f) && strstr(line,"Employee") == line) {
        /* read xx from this line then read next 4 lines */
        /* fill structure fields from these lines info */
        done = 1;
    }
    return done;
}

Now search file code looks like:

...
    Record rec;
    char name[NSZ];
    .... /* enter file name, enter name to be searched etc */...
    while (ReadFile(&rec,f)) {
        if (strstr(rec.name,name)) { // found!
            /* print info from rec fields*/
            break;
        }
    }

No matters how many records are in the file now...

I don't know why this is not counting lines and is counting words.

Sorry, I don't understand your question. Counting words? Where are those bad words?..

ArkM 1,090 Postaholic

assuming str is of type 'string', str is of type 'char'. chars will be considered negative whenever the top bit is set. It's not an issue if you are bitwise ORing, as you will get the correct result.

If it annoys you, feel free to cast to unsigned char, as necessary.

Inaccurate statement. The char type may be signed or unsigned, it's an implementation-dependent issue. All chars with true predicate c > '\0' && c <= '\x7f' (ascii-chars) are converted to positive integers, others may be positive or negative (or zero).
So before any manipulations with char bits assign char value to int or unsigned int to suppress possible left bit sign effect, for example:

int ich;
...
ich = (str[i]&0xFF); // absolutely portable code
ArkM 1,090 Postaholic

1. You never compare Name : Rose with fgets'ed line because fgets appends '\n' to a line, so it looks like Name : Rose\n . Solution: use strstr instead strcmp:

if (strstr(T,B[e])) { /* T found */
    ...
} ...

2. You are trying to copy FUTURE lines: you don't get them yet:

strcpy(K[0],B[e-1]);
strcpy(K[1],B[e]); /* current line*/
strcpy(K[2],B[e+1]); /* you will get it on the next loop! */
strcpy(K[3],B[e+2]); /* no such line here and now */
strcpy(K[4],B[e+3]); /* - * - * - * - */

Solution: there are lots of possible and obvious variants...
3. What happens if the file contains more than 50 lines?
Solution: obvious, for example:

for (e = 0; e < 50 && fgets(...); ++e) [ /* why e ??? */

4. scanf("%s"...) gets one word only. You can't get names like "Mary Ann" - why? Solution: use fgets(T,...,stdin) to get the name to be searched.

ArkM 1,090 Postaholic

It seems you don't understand me: the code IS NOT compiled with VC++ 2008 and I'm trying to explain you why. No need in any "workarounds", correct semantics error in the CODE (not in the g++): declare copy constructor as usually with const Vector<F>& parameter.

ArkM 1,090 Postaholic

1. Try to profile subset generator without any printing. There are ~1 million subsets (2^20) for N==20. To print 1 million lines... The program PRINTS all the time.
2. NextSubset code is obviously wrong: while(!Bitmask[i]&&i>=0) refers to Bitmask[-1] at the last loop. Present all class Subset definition.

mrboolf commented: thanks again: fast, precise and helpful +1
ArkM 1,090 Postaholic

I can't compile your code with VC++ 9 because it's an example of ill-formed C++ program.
If you define (wrong) copy constructor with Vector<F>& argument, it's impossible to initialize Vector<float> variable with Vector<double> initializator.
The only possible way to do that is:
1. Convert Vector<double> object to temporary Vector<float> object.
2. Use Vector<float> copy constructor with const Vector<float>& parameter, because C++ forbid to bind non-const reference to temporary objects.

No such constructor: you define your own copy constructor with non-const reference.

If you discard user-defined copy constructor, default (compiler generated) copy constructor will be used, that's OK.
If you discard conversion operator, you can't compile the program again (no copy constructor Vector<float> with const Vector<double> argument).

Summary: always define copy constructors with const arguments

Vector(const Vector<F>& source)

(except special cases when you know what happens ;) )...