mitrmkar 1,056 Posting Virtuoso

Anyone interested in programs written in similar fashion can take look at here
http://www2.de.ioccc.org/years.html#2004

mitrmkar 1,056 Posting Virtuoso

The reason why it did not compile is that you still have arrays of Strings (vardas, pavarde and adresas), although in the previous post it appeared otherwise - hence the compiler rightfully complained "Structure required on left side of . or .*", when doing e.g. os << vardas.c_str() To fix it just use plain String variables as shown below...

struct gydytojas 
{
   String vardas; // [25];
   String pavarde; // [35];
   String adresas; // [50];

Those 3 lines above are the only ones you need to change.

mitrmkar 1,056 Posting Virtuoso

If you cannot get it figured out, then zip the complete BCB project and post it here.

mitrmkar 1,056 Posting Virtuoso

I think you should forget trying to use a String to store and restore a color.
Instead, you can simply use a member variable of type System::Drawing::Color to save the original color and restore it back when necessary.

So in your Form class, add a member variable like; System::Drawing::Color ColorSaved; Then when you uncheck the checkbox, save the current color first

ColorSaved = textBox1->BackColor;
textBox1->BackColor = Color::Gray;

Then when you check the unchecked checkbox, restore the saved color textBox1->BackColor = ColorSaved;

mitrmkar 1,056 Posting Virtuoso

Sorry, it should be String^ NumberNew = gcnew String(Number1.str().[B]c_str()[/B]); stringstream::str() returns a std::string, hence that c_str() is needed there.

mitrmkar 1,056 Posting Virtuoso

So it seems that the decimals is dissapearing in the conversion.

atoi() converts a character string to an integer meaning that no decimal points are available. The stringstream is capable of doing the conversion, so you don't need to use any of the C-library conversion routines.

std::string Number3 = "0.31";
stringstream Number1(Number3);
double Convert;
Number1 >> Convert;
String^ NumberNew = gcnew String(Number1.str());
MessageBox::Show(NumberNew);
mitrmkar 1,056 Posting Virtuoso

Getting really confusing ...
given that line 210 contains "os << obj.vardas.c_str()" and actually produces the error message, does not make much sense, seems like the compiler would be completely unaware of the class itself. On the other hand, compiler errors can be quite misleading at times, so the initial reason may also be elsewhere.

Hmm .. you might as well try to see if specifying TForm1:: makes BCB happy (though I doubt it), i.e.

friend ostream& operator<<(ostream& os, const TForm1::gydytojas & obj)

mitrmkar 1,056 Posting Virtuoso

Hmm .. there were some severe errors that need to be fixed first (didn't notice those at first, sorry), byt anyway ..

friend ostream& operator<<(ostream& os, const gydytojas& obj)
{
         os << obj.vardas.c_str()  // need to add call to c_str() 
            << obj.pavarde.c_str() // because ostream knows nothing
            << obj.adresas.c_str() // about AnsiString
            << obj.gydid
            << obj.amzius
            << obj.specialyb
            << obj.telefonas
            << obj.asmkod  ;  // <- semicolon needed only here 

          return os;
}/* ; <- semicolon should not be here because this function is defined inside the gydytojas class */
mitrmkar 1,056 Posting Virtuoso

It might help if you post the code and the complete error message BCB gives.

mitrmkar 1,056 Posting Virtuoso
struct gydytojas {
    <snip>

  friend ostream& operator<<(ostream& os, const gydytojas& obj)
  {
      // In this function you have to write the data you want
      // in to the ostream os.

      // for example, write the integer values
      os << obj.gydid
          << obj.amzius
          << obj.specialyb
          << obj.telefonas
          << obj.asmkod;

      // All written ... return the stream object
      return os;
  };

  // You cannot pass a const gydytojas obj here,
  //  since you intend to load data into it
  friend fstream& operator>>(fstream& os, /*const */ gydytojas& obj)
   {
       // Todo: load the data ...
 
      return os;
     };
  };

I suspect that Salem has it right pointing out the String array usage, i.e. given that vardas actually translates to 'first name' (does it?), you should/could change it to
string vardas;
or
String vardas;
And the other variables alike too.

mitrmkar 1,056 Posting Virtuoso

What is the value of no_of_corners at the point where you do
CoordinateArray.resize(no_of_corners);
no_of_corners seems to be a member variable, I take that you are initializing it to zero before using it anywhere (?).

mitrmkar 1,056 Posting Virtuoso

... so any other member function of this class who need this data can have the access of the data after this function call, without passing it as a parameter, is this correct?

Yes it is.

As I need the 2D vectors to be returned and used as inputs to some other functions from other classes, so is this the correct way of passing by reference: std::vector<std::vector<double> > & getRefMapInfo();
std::vector<std::vector<double> > & getRefCoordinateArray();

Yes, and if a function is not supposed to modify a vector it receives, you can use a const reference, e.g. function() receives the vector as read-only void function([B]const[/B] std::vector<std::vector<double> > & vect);

mitrmkar 1,056 Posting Virtuoso

An example is BestScanPositions.at(0) is 0 and BestScanPositions.at(1) is also 0. Then BestCols.at(0) is 19 and BestCols.at(1) is 16!!! Weird, eh?

Just guessing .. could it be that you actually do the 'offending' loop twice or more without clearing the vectors' content in between?

mitrmkar 1,056 Posting Virtuoso

vardas is an array of 25 Strings. So if you want to keep it that way, you need to use
something like: gydmas[1].vardas[[B]some_valid_index_here[/B]] = Edit21->Text;

En1ro commented: Thanks for help ;) +1
mitrmkar 1,056 Posting Virtuoso

I suggest that you familiarize yourself with the concept of passing by reference, including passing by const reference. And while you are at it, check out returning by reference too.
Now you are passing vectors by value into functions that are supposed to modify the input, however, that simply will not work.

To me it appeared that you are in the belief that the following
case would not work:

std::vector<std::vector<double> > aFunction( void )
{
    // Grab the needed vector here ...
    std::vector<std::vector<double> > aVector;

    // Modify the vector here as you wish ...
   for( ... )

   // All done, return the vector
   return aVector;
}

int main()
{
    // A vector 
    std::vector<std::vector<double> > MyVector;
    // Go do the stuff ...
    MyVector = aFunction();

    return 0;
}

It works however.

mitrmkar 1,056 Posting Virtuoso

static actually is not a good word to use here. Let's say for simplicity's sake that, if you have a pointer to a struct/class to work with, then you use the -> operator to access member variables/functions through that pointer.

mitrmkar 1,056 Posting Virtuoso

Consider the following

// A variable of class cdrom on the stack
cdrom cdrom1;
// invoke the loadinfo() member function
cdrom1.loadinfo();

// Allocate a variable of class cdrom on the heap
cdrom * cdrom_ptr = new cdrom;
// invoke the loadinfo() member function
cdrom_ptr->loadinfo();
mitrmkar 1,056 Posting Virtuoso

You could turn Ancient Dragon's code into a function and then use it to process your input file line-by-line. It could look something like (the function is here AD())

void AD(char * record, char * record_out)
{
    char *p1 = record;
    char *p2 = record_out;

    // Rest of the original code here ...
}
// In your main(), the while loop
while (fgets(record, sizeof(record), fin))
{
    // A buffer local to the while() loop, of same size as the record array
    char record_out[sizeof(record)] = {0};

    // Process the line
    AD(record, record_out);

    // Display what we got
    puts(record_out);
}
mitrmkar 1,056 Posting Virtuoso

Here is one (sort of) short article discussing floating point comparisons
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

mitrmkar 1,056 Posting Virtuoso

>> I got a syntax error saying that the declaration(s) shadows the parameter.
That really seems to be happening there ...

void initialize(int& fcounter,int& mcounter,double& fsumGPA,double& msumGPA)
{
    int fcounter = 0; // a local variable is initialized here, this has no 
                 // effect on the fcounter variable you pass in to the function
    int mcounter = 0;  // same here
    double fsumGPA = 0; // and here
    double msumGPA = 0;  // and here
}

So instead you need to use

void initialize(int& fcounter,int& mcounter,double& fsumGPA,double& msumGPA)
{
    fcounter = 0;
    mcounter = 0;
    fsumGPA = 0;
    msumGPA = 0;
}

Your input data seemed OK.

mitrmkar 1,056 Posting Virtuoso

Shouldn't you change the initialize() function to initialize the variables you pass in?
Now you initialize four variables local to the function ...

void initialize(int& fcounter,int& mcounter,double& msum,double& fsum)
{
    int mcount = 0;
    int fcount = 0;
    double malesum = 0;
    double femalesum = 0;
}

The blank screen comes back up, but it just disappears a second afterwards.

That is expected since you are not displaying anything on screen (e.g. by means of cout)

The only result I am getting is the sumFemaleGPA in the output when I open the output file.

What is exactly in your input file?

mitrmkar 1,056 Posting Virtuoso

You are doing integer math, change to floating point instead (i.e. from int to double or float).

mitrmkar 1,056 Posting Virtuoso

Can I get an example of it. Do you mean the "&" sign?

One example is sumGrades(), inside that function you modify fcounter, mcounter, msum and fsum. However, none of these are passed in by reference (&) so the sumGrades' code does not have the intended impact. So you should change to

void sumGrades(int & fcounter,int & mcounter,double & msum,double &fsum,ifstream& inData,ofstream& outData,char gender,double gpa)

There may be other such functions too, I did not look too closely.

One correction yet to your SumGrades() function, you probably want to change

inData>>gender>>gpa;
    while (inData)

to

while (inData>>gender>>gpa)  // loop while there is data for gender and gpa
mitrmkar 1,056 Posting Virtuoso

Sure you can write your C++ code using notepad, it's a text editor after all.
But you need to have a compiler/linker to turn the code into a program which you can then run.

mitrmkar 1,056 Posting Virtuoso

the process is repeated to get gcd as 3

Ermm, so eventually everything rolls up into a "qt7-qualified czsm" (?)

mitrmkar 1,056 Posting Virtuoso

Okay here is the pseudo code for hcf, credit to Euclid.

Umm, I think I got the hcf part of it (thanks hammerhead), but how to figure out 'lcm of 2 nos' just beats me :-/ ...

mitrmkar 1,056 Posting Virtuoso
c++noobie commented: Thank you very much. You helped me solve this. +1
mitrmkar 1,056 Posting Virtuoso

I think I got it.

Yes, it seems like you got it ...

mitrmkar 1,056 Posting Virtuoso

>> Where am I going wrong?

You have not defined the swap() function, you only have a prototype for it.
So you really need to provide the code for the swap() i.e. fill in the missing part
which does the actual swap ...

void swap(int arr[], const int left, const int right)
{
    // here you need to swap the two values,
    // at the given indexes (left, right),
    // hint: use a temporary int variable to do it, e.g. 
    // int temp;

}

Then as to the sort

void selection_sort(int a[], int n)
{
   int i, j, smallest;
   int temp;
   for (i = 0; i < n-1; i++) {
      smallest = i;
      for (j = i + 1; j < n; j++) {
         if (a[j] < a[smallest])
            smallest = j;
      }
        // swap the values at the indexes 'i' and 'smallest'
        swap(a, i, smallest);

// Note that the above call to swap() performs the same thing
// that the below three lines would do if those were not commented out
//      int temp = a[i];       // You don't need this line
//      a[i] = a[smallest];   // You don't need this line
//      a[smallest] = temp; // You don't need this line 
   }
}
mitrmkar 1,056 Posting Virtuoso

Are you sure that your input string is null terminated?

mitrmkar 1,056 Posting Virtuoso

>>function named swap that takes exactly three arguments (the array name and the two >>subscripts of the array whose values are to be swapped).
>>The swap function should not return any value.
>> Add both the prototype and the definition of swap to the program.

Your prototype's subscripts are wrong, you are trying to pass arrays of references to int,
instead the subscripts are simple integers telling the indexes whose data is to be swapped,
so

void swap(int [], int& [], int&[]);

turns into

void swap(int [], const int, const int)

The subscripts are declared as 'const', you could do also with plain non-const ints, i.e.

void swap(int [], int, int)

Then the selection_sort, the call to the swap() function is now readily in-place

void selection_sort(int a[], int n)
{
   int i, j, smallest;
   int temp;
   for (i = 0; i < n-1; i++) {
      smallest = i;
      for (j = i + 1; j < n; j++) {
         if (a[j] < a[smallest])
            smallest = j;
      }

        // swap the values at the indexes 'i' and 'smallest'
        swap(a, i, smallest);
//      int i, smallest;
//      int temp = a[i];
//      a[i] = a[smallest];
//      a[smallest] = temp;
   }
// A missing curly brace in your original code caused the
// [B]'swap' : local function definitions are illegal[/B]
// error message ... 
// You cannot define a function inside a function, ever, so
// here ends the selection_sort() function ...
[B]}[/B]

Here is the swap function to be filled in ...


       
mitrmkar 1,056 Posting Virtuoso

runMatrix is a member function of library, so you need to either
1) instantiate an object of that class and call it like libraryObj.runMatrix(...)
or
2) if the runMatrix is a static function, then call it like library::runMatrix(...).

mitrmkar 1,056 Posting Virtuoso

You are probably trying to copy memory to a destination which is too small in size.

At the time that assertion fails, you may find the offending piece of code by viewing the call stack.

mitrmkar 1,056 Posting Virtuoso

The output i am getting on the VB interface = ¯õ#;‘ƒ9s„‡Ñ'Ý¢@ýýýýÝ (21 bytes)
What can cause the problem...

There is no terminating null byte in the string, allocate 1 byte more and terminate the string yourself, e.g.

char* plaintext = new char[size + 1];
plaintext[size] = 0;
kartouss commented: Very helpful +1
mitrmkar 1,056 Posting Virtuoso

Change

char sk[4][4];

to

char sk[16];
mitrmkar 1,056 Posting Virtuoso

If you want to keep using the array 'char s[100]', you can explicitly copy the
ostringstream's content into the array.
I.e ..

strcpy(s, outs.str().c_str());

Or use the >> operator, i.e.

outs >> s;
mitrmkar 1,056 Posting Virtuoso

You cannot do it like that, 'word' is there a pointer to a char.
So, try with an array of chars instead

char word[21] = "";
scanf("%20s",word); // at max, 20 characters get scanned to the 'word'
mitrmkar 1,056 Posting Virtuoso

No, you need to get a working understanding of the keyword 'extern' in C/C++.

mitrmkar 1,056 Posting Virtuoso

The problem is that there probably is no definition of the variable muscleTendonLength anywhere (hence the linker really is unable to do its job).
See
http://c-faq.com/decl/decldef.html
and place the definition

dpMuscleTendonLengthStruct* muscleTendonLength;

somewhere suitable in your code. You may also want to initialize the definition of muscleTendonLength to e.g. NULL.

mitrmkar 1,056 Posting Virtuoso

on linux platform, After sending the signal SIGINT using cntrl+C, the numbers are printed from 1 to 100000. In case I press cntrl+c again during the time my code is executing the for loop for pirnting numbers between 1 and 100000, it doesnt have any effect on the printing.

Are you 100% sure that e.g. "Inside Signal Handler" doesn't get printed the second time at that time?

on windows if i press cntrl+c second time, the Exe stops immediately.

That is because Windows has restored the handler i.e. your handler is not in effect anymore after the initial Ctrl+C got handled.

How call I disable the signal catching second time.

You might re-install the handler inside the handler itself.
However, on Windows you'd probably be better off using SetConsoleCtrlHandler().
http://msdn2.microsoft.com/en-us/library/ms686016.aspx

Note that your handler function's signature
void intr_hdlr(void);
is not correct. You should be able to call signal() without casting the handler argument like you do now.

mitrmkar 1,056 Posting Virtuoso

You need to tell the IDE to link with the Winmm.lib library also, so open
Project/Properties/Configuration Properties/Linker/Input
and append winmm.lib in the Additional Dependencies field.

Also, use the first block of code you've tried, i.e.

PlaySound(TEXT("test.wav"), NULL, SND_ALIAS | SND_APPLICATION);

mitrmkar 1,056 Posting Virtuoso

Try taking a look at here
http://en.csharp-online.net/CheckedListBox
to get an idea about what a multicolumn listbox is.

mitrmkar 1,056 Posting Virtuoso

Like vijayan121 already pointed out, you need to use the Show() method instead of the ShowDialog(). So try ...

private: System::Void button2_Click_3(System::Object^  sender, System::EventArgs^  e) 
{
	 this->form22instance.Show();
	 this->form4instance.Show();
}
mitrmkar 1,056 Posting Virtuoso

You already know how to read the file in one char at a time and convert it (to upper case), i.e.

while( (c = infile.get()) > 0 )
{
    outfile << (char)toupper(c);
}

One thing you could do is to write a function which behaves like toupper(), i.e. takes one character as an input and returns the processed character, so you might code yourself an encrypt() function and use it like ...

while( (c = infile.get()) > 0 )
{
    outfile << (char)[B]encrypt[/B](c);
}

And from there on, you'd probably could quickly derive the counterpart decrypt() function.

mitrmkar 1,056 Posting Virtuoso

You need to use an infile.clear() call, since you are working with same ifstream object throughout the program. See
http://www.cplusplus.com/reference/iostream/ios/clear.html
Try also to understand and learn how to use the eof(), fail(), good() functions.

case 7:
infile.open(myFile.c_str(), ios::in);
[B]infile.clear();[/B]

Note that, when you add words to the file, add a newline also, otherwise you'll have just one long word.

mitrmkar 1,056 Posting Virtuoso

Are you sure that the file actually contains any data?

A minor note, in your 'case 7' block, the 'continue;' is inside the if block which checks whether the infile is open, you should move 'continue;' outside of the if block.

mitrmkar 1,056 Posting Virtuoso

Instead of

this->richTextBox1->Select( richTextBox1->Text->IndexOf("how"), 3);

use

this->richTextBox1->Select( [B]startPos[/B], 3);

i.e. you were simply always getting the first index of the string 'how'.

mitrmkar 1,056 Posting Virtuoso

You have to use the IndexOf() in a loop, like

for(int startPos = richTextBox1->Text->IndexOf("how");
     -1 != startPos;
     startPos = richTextBox1->Text->IndexOf("how", startPos + 3))
{
    // something here
}
mitrmkar 1,056 Posting Virtuoso

In your THREEDICE.H add the following forward declaration

#define THREEDICE_H
[B]class onedie;[/B]
class threedice
...

Then the statistics() function is a bit odd, if you think it will be called from e.g. main(),
it probably should look like

int main()
{
    const int roll_count = 200;
    int rolls[roll_count] = {0};
    // I'm not actually sure what the allresults should be
    int allresults[roll_count] = {0}; 
    // Then you can make the statistics() call ...
    statistics (rolls, roll_count, allresults);
    return 0;
}

void statistics (int rolls[], int count, int allresults[])
{
    threedice tryerluck;
    for(int i=0;i<count;i++)
    {
        tryerluck.rollem();
        rolls[i]= tryerluck.getsumFaces();
    }

    // and maybe do something here with the allresults too    
}
mitrmkar 1,056 Posting Virtuoso

I think you could use directly the IndexOf() method, i.e
richtextBox1->Text->IndexOf("how")
and once you get the index (or -1, if not found), you probably already know how to select the text in a TextBox.