mitrmkar 1,056 Posting Virtuoso

Oh well, a simple thing turning out to be overly difficult.
One option for you might then be to build the project from command line. Most probably the Help system provides a detailed description on how to do that.

mitrmkar 1,056 Posting Virtuoso

so pretty much just change int Size[]

to

double Size[] at every place and it should show the decimal

Some other places too, like the Swap() function has to be changed to operate with doubles, and whereever you assign a value from Size[at_some_index] to a variable, change the variable receiving the value from int to double.

mitrmkar 1,056 Posting Virtuoso

are you positive

You are using count as an index into the Size array, which holds at max MAX_SIZE items, so
you must not allow: Size[MAX_SIZE] = somevalue; to happen, that would be out-of-bounds.

mitrmkar 1,056 Posting Virtuoso

You see, there isint such field, i just manage to go to IDE's Project/Options/Linker/Linking and there is radiobox only..

That's too bad then, because that property page is the place where this option for linking with additional libraries should be. I think I cannot help much more than suggest you to search for relevant topics (e.g. "Linker Linking" etc) in the IDE's help.

mitrmkar 1,056 Posting Virtuoso

i tried to add my lib by the way of Importing Type library

The .lib files are not type libraries, so forget that.

Basically you now just need to add the required library file to your project's linker input configuration, so that the linker finds the expected library code to pull in to your program.

As a test, try adding the library

sqlapibd.lib

in the IDE's Project/Options/Linker/Linking - Additional options -field. If you don't have that specific configuration item, try to find something similar in the project's options.

Then build the project and post the compiler/linker output

mitrmkar 1,056 Posting Virtuoso

You have a potential array-out-of-bounds condition there, you should change

in_size >> size;
while((!in_size.eof()) && (count <= MAX_SIZE))

to

while((in_size >> size) && (count [B]<[/B] MAX_SIZE))
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

about .c_str() what it does?

It returns a "const char *", a pointer to a null-terminated C-style string that the std::string internally holds. You should not modify the memory pointed by the pointer you get from calling c_str() i.e. consider it as read-only.

string str = "testing";
const char * ptr = str.c_str();
// the following prints out: testing
cout << ptr;

Here is one reference for std::string
http://www.cplusplus.com/reference/string/string/

mitrmkar 1,056 Posting Virtuoso

how could i arrange the output?

Use double quotation marks " " instead of ' ', for example;

ofile<<patient.name<<[B]" "[/B]<<patient.age<< [B]" "[/B] <<patient.gender<< [B]" "[/B] <<patient.fileNumber<< [B]" "[/B] <<patient.illness<< [B]" "[/B] <<patient.degree;

You can choose the length of the string as you wish.

>> but what if i want to gather all files in One file, how could i do it?
Write that file so that a single line of the file contains all data of a single patient.

mitrmkar 1,056 Posting Virtuoso

In
http://www.sqlapi.com/OnLineDoc/index.html
it says that for Borland, the following libraries are available to choose from

sqlapib.lib - for linking with release version of dynamic library (Borland C++)
sqlapibd.lib - for linking with debug version of dynamic library (Borland C++)
sqlapibs.lib - for linking with release version of static library (Borland C++)
sqlapibsd.lib - for linking with debug version of static library (Borland C++)

So for example, if you link with the debug version of the dynamic library, then you need to add the sqlapibd.lib library in Project/Options/Linker/Linking - Additional options.

I take that you have these files on your computer (?)

mitrmkar 1,056 Posting Virtuoso

I'm new to C++ with MFC..

You probably will find the CString class useful. See e.g. the CString::Format() function.

mitrmkar 1,056 Posting Virtuoso

the sort from smallest to largest

See the comment below ...

int main()
{
    int count;
    numbers_used = 0,

    <snip>

    // You are passing numbers_used, which is zero,
    // shouldn't you be using [B]count[/B] instead here?
    Sort(Size, numbers_used);
}

What do you mean by "setting up my widths" ?

mitrmkar 1,056 Posting Virtuoso

Do i have another mistakes??

Now that your code is in the shape in which it compiles properly, you can start testing your programs to see if they work as expected.

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

when i run the program and try to add a song, the addsong function always tells me that the item already exists.

That happens because the logic in if (titles[i].compare(t_title) && artists[i].compare(a_artist)) is wrong.
std::string::compare() returns zero if the items are EQUAL, so you need to rewrite that comparison.
See
http://www.cplusplus.com/reference/string/string/compare.html

mitrmkar 1,056 Posting Virtuoso

After i write newvalue the compiler run with out any result,only blank screen.

When the program enters the do-while() loop you have there, it does not ask for any new value, so it simply enters an infinite loop (as instructed). So you need to add code to get a new value from the user.

You are still having problems with correct usage of curly braces {} with your if-else blocks, i.e. the problem is not about a missing semicolon but instead lack of curly braces.

#include<iostream>
using namespace std;
int main()
{
    <snip>

    while(i<=n)
    {
        if(n%i==0)
        [B]{[/B] // <- the if block begins here
            cout<<i<<"*";    // This line is part of the if block
            n=n/i;           // And this line too is part of the if block
        [B]}[/B] // <- the if block ends here
        else
        {  // <- it really doesn't hurt to have even a single 
           //   line of code enclosed in braces, so ...
            i++;
        }
    }

    <snip>

}

it is clear that i put semi colon

The compiler error/warning messages can at times be somewhat misleading/confusing. If you have an IDE which has the error/warning codes documented, then looking them up in the documentation might prove helpful.

mitrmkar 1,056 Posting Virtuoso

You need to randomize the hillsize and gridref values within the loop in which you initialize the list.

mitrmkar 1,056 Posting Virtuoso

I'm trying to point out the errors in your code, so here we go ..

#include<iostream>
using namespace std;

int main()
{
    int value,check=1;
    cout<<"Enter a number: ";
    cin>>value;

    while(value>=0)
    {
        int newvalue;
        cout<<"Enter another value: ";
        cin>>newvalue;
        
        if(value>newvalue)
            cout<<" is increasing";
            check=0;    [B]// you are not using braces {}, hence your [/B]
            value=-5;   [B]// compiler chokes up on these two lines[/B]
        else
            value=nwvalue;

        if(check==1)
            value==-5    [B]// you probably meant: [B]value = -5;[/B] [/B]
        cout<<" this is not increasing order";
            else
        cout<<"This is increasing order";
    }

    return 0;
}

So, try to learn to use the curly braces {}, i.e the if-else statement above should be;

if(value>newvalue)
        {   [B]// <- if block begins here[/B]
             cout<<" is increasing";
             check=0;
             value=-5;
        }   [B]// <- if block ends here[/B]
        else
        {   [B]// <- else block begins here[/B]
             value=nwvalue;
        }   [B]// <- else block ends here[/B]

Lastly, you have been using the inline code tags (i.e. icode/icode), please switch to the simple (code/code) tags instead.

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

STL's sort() briefly introduced here ...
http://en.wikipedia.org/wiki/Sort_(C%2B%2B)

mitrmkar 1,056 Posting Virtuoso

i still get:
invalid suffix
expected ; before int

Then you most probably still use there a variable whose name starts with a digit, so please double-check the code.

mitrmkar 1,056 Posting Virtuoso

You seem to have a void getId() function, shouldn't that function return a pointer to the id member of the class?

You might then use it like

this->label->Text = gcnew System::String(abc.getId());

assuming that you have the instance abc of the Profile class available.

mitrmkar 1,056 Posting Virtuoso

all that time, the program wasn't working because of the shadow parameter thing (I had a few problems with awhile ago).

Hey .. now don't forget that pass-by-reference thing ...

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

The red parts are my changes.
The last line used to be "this->label2->Text = L"label2";" , showing "label2" in Form2.
But my change is not working and got error. I wonder how to fix it.

What is the error(s) you are getting? Might be helpful to post the compiler error(s) ...

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

Or use a vector, which you can add to arbitrarily
std::vector< std::string > studentID;

fin >> aStudent;
studentID.push_back( aStudent );

You need to add std::string aStudent;

mitrmkar 1,056 Posting Virtuoso

>> i defined it in 2 header files but if i take it out from one then it will say S is undefined
Define it only once, and use #include "where_S_is_defined.h" where needed (i.e. where you get the 'undefined' error)

mitrmkar 1,056 Posting Virtuoso

There is a mismatch with the Fill_Array() function,
prototype is

void Fill_Array(int Size[], int& count);

whereas the implementation is

void Fill_Array(int Size[], int& count, [B]int& number_used[/B])

In main(), you are using it in the manner which implies that you should remove the
'int& number_used' argument from the implementation.

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

Supposing that ProductType is a global scope variable, that might be a bogus memory leak report.

mitrmkar 1,056 Posting Virtuoso

It might prove helpful if you post the code showing how you actually are using strings ...

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

You are misusing the form class, you instantiate two objects of the Blank class in your code.
And you need to set the window text prior to showing the form ...

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

    // A single instance of Blank needed in this function
    Blank BlankFrm;

    // Set the window text before you show the form
    BlankFrm.Text = this->comboBox1->SelectedItem->ToString();

    // then show the form
    BlankFrm.ShowDialog();
}
mitrmkar 1,056 Posting Virtuoso
float AverageGrade(Student[], int nStudents)
{
    // This function receives the array Student[], why are you not
    // using it here at all?
    int i=0;
    float sumofgrades=0;
    float ave;
    // sumofgrades is zero at this point, since you initialized it to zero
    // couple lines ago ...
    // so you end up dividing zero by the number of students, always 
    ave = sumofgrades/nStudents;
    return ave;
    // Here you have one line of code that never gets executed ...
    i++;
}/* ; <- you had a semicolon here, that's not allowed */
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

Use the BIF_BROWSEINCLUDEFILES flag in the BROWSEINFO's ulFlags member.
http://msdn2.microsoft.com/en-us/library/bb773205(VS.85).aspx

mitrmkar 1,056 Posting Virtuoso

see getrusage(), e.g. here
http://linux.die.net/man/2/getrusage

adcodingmaster commented: good +0
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

m_dwVersion IS a member of AFX_MODULE_STATE, but only when you compile with _AFXDLL defined.

mitrmkar 1,056 Posting Virtuoso

I am unable to get the 2 digits of precision which I should have coded under the calculation function...

You are setting the precision on the 'cout' object, that has no impact on the ofstream object you are using. So configure the 'ofstream out' instead.