phorce 131 Posting Whiz in Training Featured Poster

e text in the source code as "plain text" so it's language can be changed (english/swedish/ ....)

An example might explain better

Hey, basically, a language convertor?

You can use Google's Translate API for this.

https://developers.google.com/translate/

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

2, 67, 23, 5, 7, 34, 14, 4, 8, 62};

Hey,

Think something like this is what you mean.. Obviously, change it slightly!

#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {

int numArray[10] = {2, 67, 23, 5, 7, 34, 14, 4, 8, 62};
int arrayNum[10];

int num = 10;
int j=0;

for(int i=10; (i >= 0); i--)
{
    arrayNum[j-1] = numArray[i];
    if(j >= 10)
    break;
    j++;
}
cout << "Actual Order: ";
for(int k=0; (k < 10); k++)
{
    cout << numArray[k] << ' ';
}
cout << endl;
cout << "Reverse Order: ";
for(int i=0; (i < 10); i++)
{
    cout << arrayNum[i] << ' ';
}

}

Output: --

Actual Order: 2 67 23 5 7 34 14 4 8 62
Reverse Order: 62 8 4 14 34 7 5 23 67 2

Hope this helps you :)

phorce 131 Posting Whiz in Training Featured Poster

I had to do this as a first year project..

Can you atleast show that you have attempted it, so then people can help?

phorce 131 Posting Whiz in Training Featured Poster

than or equal to 40 and less than or equal to 50 is D
3.Marks greater than 51 and less than 70 is B

You should really attempt this by yourself. I don't know how the grades will be inputted (Whether it being through a .txt file etc) but this should help (Even if it is a little bit)..

#include <iostream>

using namespace std;

char algorithm(int theGrade)
{
    char theResult;

    if(theGrade < 40)
    {
        theResult = 'F';
    }else if(theGrade >= 40 && theGrade < 50){
        theResult = 'D';
    }else if(theGrade > 51 && theGrade < 70)
    {
        theResult = 'B';
    }else{
        theResult = 'A';
    }

    return theResult;
}

int main(int argc, char *argv[]) {

    int grade = 69;

    cout << algorithm(grade);

}
phorce 131 Posting Whiz in Training Featured Poster

Heyy thanks for your help, it worked! :)

Another part though:

FOR N = 0 TO NE / 2
 R(N, 1) = 0
 R(N, 2) = 0
 FOR E = 0 TO NE - 1
  A = A(E) * B(N) * C(E, N, 1)
  B = A(E) * B(N) * C(E, N, 2)
  R(N, 1) = R(N, 1) + A
  R(N, 2) = R(N, 2) + B
 NEXT E
NEXT N

-- Converted so far in C++

 vector<matrix>R(NS);
 vector<matrix>A(NE);
    for(int N=0; (N < NE/2); N++)
        {
            R[0][N] = 0;
            R[1][N] = 0;

            for(int e=0; (e < N1-1); e++)
            {

            }
        }

I don't get this bit:

A = A(E) * B(N) * C(E, N, 1)
B = A(E) * B(N) * C(E, N, 2)

Do I just push_back into A? So for example:

A.push_back(A(E) * B(N) * C(E, N, 1));
B.push_back(A(E) * B(N) * C(E, N, 2));

Thanks for your help again :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm trying to convert some code from BASIC to C++.. But, I'm stuck on a particular part..

REM CREATE A MATRIX C WITH (COS(DN) , -SIN(DN)) :
DIM C(NE, NS, 2)
FOR N = 0 TO NE / 2
 FOR E = 0 TO NE - 1
  DC = E / FE
  FEN = N * FE / NE
  DN = 2 * PY * FEN * DC
  C(E, N, 1) = COS(DN)
  C(E, N, 2) = -SIN(DN)
 NEXT E
NEXT N

Basically, I don't get the:

DIM C(NE, NS, 2)

Is this a vector with the size of NE, NS (Which is inputted)?

I also don't get this part:

 C(E, N, 1) = COS(DN)
 C(E, N, 2) = -SIN(DN)

Since if C was a vector, I wouldn't be able to push back to different data sets into the same vector.. I don't get the 1/2 differenciation. Also, if cos and sin are in C++, is there a -sin() in the math library?

Here is my code so far:

#include <iostream>
#include <math.h>
#include <vector>

using namespace std;
int main(int argc, char *argv[]) {

    const double PY = 3.14159265;
    double FE = 0;
    double NE = 0;

    cout << "Sampling rate" << endl;
    cin >> FE;

    cout << "Amount of Measures" << endl;
    cin >> NE;

    double NS = NE / 2 + 1; // Amount of Sunusoids 

    vector<double> C (FE*NE);

    for(int n=0; (n < NE/2); n++)
    {
        for(int e=0; (e …
phorce 131 Posting Whiz in Training Featured Poster

Hey - Thank you so much for your help. I've only just seen this again but it's solved now =)

phorce 131 Posting Whiz in Training Featured Poster

his headfirst trying to code it but bumped into several hurdles and recently started a thread abo

Hello,

I'm kinda confused.. So, basically, you have three drop down menues that contain information that is stored inside a table, and, depending on which item in the drop down menu they choose, changes the next one and the one after that?

As someone mentioned, this can be done using Ajax and have the data passed through that way.. This is a good solution to this problem as it doesn't require the page to be reloaded for the data to be loaded.

Let me know, I may be able to give you some pointers, if, this is actually what you want to do.

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm currently working on a project that basically reads some text and then performs basic Lexical Analysis on the text. I'm having a slight problem
with overloading methods.

So for example, I have a method that can read in the words from a txt file and another method which reads takes the text just from a string, but, I'm using the same method name, and, the same variable type so obviously it cannot be overloaded. For example:

#ifndef _readWords_h
#define _readWords_h

#include <iostream>
#include <vector>
using namespace std;

class Lexical
{
    public:

        Lexical();
        Lexical(string theFileName);

        vector<string> Parser(string fileName);
        vector<string> Parser(string theWords);

    protected:
        vector<string> words;
        string fileName; 

};

#endif

The method Parser cannot be overloaded. Now is there a way that I could overload this method OR should I have two more classes that inherit from this class and have Parser as a virtual function and call the correct class? E.g. readFromTXT, readFromString both inheriting from Lexical.

Any help would be greatly appriciated :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm looking for some advice (NOT CODING) on a project I'm hoping to start..

Basically, I'm hoping to develop some shell commands that work a tiny bit like Github (if you are familular with it)..
The language that I want to use is C++..

Could anyone offer any advice please? Anywhere I can start reading up on how to do such things..

Thanks :)!

phorce 131 Posting Whiz in Training Featured Poster

You need to provide some code so that we can help you

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I dunno if this is what you mean, but I was thinking something like:

<?php

    // connection information

    $select_query = "SELECT ent_id, mem_id, from_step, from_pos FROM step1_reentry WHERE status='E'LIMIT 1";
    $select_result = mysql_query($select_query);
    if(mysql_affected_rows() == 1)
    {
        while($row = mysql_fetch_array($select_result))
        {
            // retrun the relivent fields.
            // but do it in variables, so like $name = $row['name'];
        }

        // NOW you can do the UPDATE statement.
    }

?>

I dunno if this is what you mean, or if it will help.. :)

phorce 131 Posting Whiz in Training Featured Poster

Hello - Next to someones name (There is an up arrow or down arrow) :)

phorce 131 Posting Whiz in Training Featured Poster

Which solution worked?

Please mark this thread and solved and give rep to those who helped :)

phorce 131 Posting Whiz in Training Featured Poster

oops:
change the if statement to this:

if(isset($_SESSION['username']))
{
   // handle 
}

If that doesn't work then; just try putting this AFTER session_start() in index.php

var_dump($_SESSION['username']);

And see what the result is. If it's NULL then you know that you're not setting the session right.
I don't know because with some servers, it's how you process the linking; like a site that I was working on a while ago killed the sessions because I didn't handle the linking correctly. Give it a go anyway :)

phorce 131 Posting Whiz in Training Featured Poster

I don't understand the question, so you are able to login, BUT, in index.php it doesn't do the user part (sesson)?

Try this:

<?php
session_start();
include("connect.php");

//check, if user is loged in or not
if(isset($_SESSION[['username']))
{
    //log in(member)
    echo 
    "
     YOU ARE LOGED IN
     <input type='submit' action = 'logout.php'  value='logoff'>
    ";
}
else
{
//not loged in(not member)
echo 
"
YOU ARE NOT LOG IN!
<form name='form' method='post' action='login.php'>
<strong>Member Login </strong><br/>
<p id = 'error'>Print Errors here</p>
Username:<input name='username' type='text' id='username'><br/>
Password: <input name='password' type='password' id='password'><br/>
<input type='submit' value='Login'>
<input type='submit' action='register.php'  value='register'>
</form>
";
}
?>

Also, in your login script, try not setting the session as what is being posted in the form. Because it might not be case sensative; for example if I entered phorce then displaying the username (in the future) will display as lower case even though I registered the username in uppcase. Just saying :)

phorce 131 Posting Whiz in Training Featured Poster

ay, and one for the file, which after loading the file's contents into an array will call the

Thanks for the advice :) I'll give that a go!

I'm trying to make this into a Platform, which then people can use for Data Analysis so I need it to be structured correctly.

phorce 131 Posting Whiz in Training Featured Poster

Thanks for your reply. So the parser (function) would have an if statement that determined whether the parameter is infact a file or an array.. ?

phorce 131 Posting Whiz in Training Featured Poster

@simplypixie - My bad, I haven't done anyt wordpress in about a year. I refused to learn it!

phorce 131 Posting Whiz in Training Featured Poster

Hello,

Thanks for your reply...

Basically, the parser will allow for the data to be parsed through both file (e.g. .doc, .txt etc) as well as just an array so e.g:

<?php

   $this->Numeric->parser('file.txt');
   // OR
   $numerbers = array(1, 2, 3, 4, 5, 6);
   $this->Numeric->parser($numbers);
   ?>

Thanks :) but I don't want to change the name of the parser.. So it woudn't be like: parserTXT etc

phorce 131 Posting Whiz in Training Featured Poster

Hey,

So let's say I have a list of names:

    $narray[0]="Alfred";
    $narray[1]="Robert";
    $narray[2]="Deepak";
    $narray[3]="Teresa";
    $narray[4]="Joshua";
    $narray[5]="Chandni";
    $narray[6]="Sadiq";
    $narray[7]="Vladimir";

And with this list, I wanted to sort the names AND then print the names by ASC, or DESC then we need to handle what is being passed through the url (Take the value after the question mark):

 <?php

    $narray[0]="Alfred";
    $narray[1]="Robert";
    $narray[2]="Deepak";
    $narray[3]="Teresa";
    $narray[4]="Joshua";
    $narray[5]="Chandni";
    $narray[6]="Sadiq";
    $narray[7]="Vladimir";

        if(!isset($_GET['se'])) die('Please enter the type of sort');

          $type = $_GET['se'];

        //$type = 'ASC';
        // Or use a switch statement
        if($type=='DESC')
        {
            rsort($narray);
        }else if($type=='ASC')
        {
            sort($narray);
        }

        for($i=0; $i<8; $i++)
        {
            print $narray[$i] . " ";
        }
    ?>

Then whichever of the values you put into the url:

site.com/names.php?se=DESC

Vladimir Teresa Sadiq Robert Joshua Deepak Chandni Alfred

site.com/names.php?se=ASC
Alfred Chandni Deepak Joshua Robert Sadiq Teresa Vladimir

Hope this helps :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm going to be working on Lexical Analysis, but, both in Words / Characters as well as Integer values. The application will also allow input from both Text files, as well as passing the data through arrays, or variables. The Numeric analysis will be different from the Lexical Analysis in a few different ways, but they will each share the same method(s) of parsing in the data (In some way or another).

My first project with using the Lexical Analysis is to create an Application that enables me to pass in a piece of course work, which, parses in the data and then counts the number of words / characters there are, as well as checking for particular keywords that HAVE to be included in the assignment, and then after this, the particular assignment will be converted to PDF.

This is just one of the uses, but, in the future I want to be able to handle (for example) syntax highlighting..

I don't want help with code, I just need some advice on how to structure it..

I was thinking this:
1. Have an interface class that contains all the methods needed
2. Create a a base class that implements this particular interface
3. Create two more classes "Numeric", "Lexical" which inherit from the base class.

Would this work? Or would it better to have an interface for each of the Numeric, Lexical?

But the only problem is handling the methods for say, reading an entire …

phorce 131 Posting Whiz in Training Featured Poster

Urgh, haven't done any work with Wordpress in a while (Because it's just quite frankly horrible to work with)
BUT, from looking at your code, you open up an if statement, as well a while loop. Where do you close these? so e.g.

<?php

   endif();
   endwhile();

?>

I think the code is, but I'm not too sure.. This is why you could be getting the $end

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm working on an image-gallery type application and I have got the images to work, in that the gallery works and the image changes at the particular interval. BUT, I need a way to stop the images changing when you mouse over the event. Here is what I have so far, but, it does not want to seem to work. Any suggestions?

$(function(){
    $(this).mouseover(function(){
        $(this).toggle();
    });
    $('.fadein img:gt(0)').hide();
    setInterval(function(){
      $('.fadein1 :first-child').fadeOut()
         .next('img').fadeIn()
         .end().appendTo('.fadein1');}, 
      3000);
});
phorce 131 Posting Whiz in Training Featured Poster

Hey,

Yes, I would say it's safe, well, safer than using something like a cookie (Because a SESSION is server side). You could also store the users IP (or other validation checks) which are then checked everytime the data is then used. This could be one option. Also destroy the session after a certain time / inactivity; it depends on the nature of the site though.

Hope this helps :)

phorce 131 Posting Whiz in Training Featured Poster

Please post your FORM code e.g.

<form method="post" action="" >

  // form code
  // form code
 </form>

So we can help you more :)

phorce 131 Posting Whiz in Training Featured Poster

Hey,

Haven't ran it, so might not work.. But try this:

<?php 
$errors = '';
$myemail = 'emailaddress@gmail.com';//<-----Put Your email address here.

if(empty($_POST['contact[first_name]']) || (empty($_POST['contact[last_name]']) || empty($_POST['contact[email]']) ||empty($_POST['contact[phone]']) || (empty($_POST['contact[company]']) || 
(empty($_POST['contact[position]']) || 
(empty($_POST['contact[country]']) || 
(empty($_POST['contact[question]'])))))))

{
    $errors .= "\n Error: all fields are required";
}

$contact[first_name] = $_POST['contact[first_name]'];
$contact[last_name] = $_POST['contact[last_name]'];
$contact[email] = $_POST['contact[email]'];
$contact[phone] = $_POST['contact[phone]'];
$contact[company] = $_POST['contact[company]'];
$contact[position] = $_POST['contact[position]'];
$contact[country] = $_POST['contact[country]'];
$contact[question] = $_POST['contact[question]'];

if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
    $errors .= "\n Error: Invalid email address";
}

if( empty($errors))
{
    $to = $myemail; 
    $email_subject = "Contact form submission: $name";
    $email_body = "You have received a new message. ".
    " Here are the details:
    \n First Name: $contact[first_name] 
    \n Last Name: $contact[last_name]
    \n Email: $contact[email]
    \n Phone: $contact[phone] 
    \n Company: $contact[company]
    \n Position: $contact[position]
    \n Country: $contact[country]
    \n Question: $contact[question]"; 

    $headers = "From: $myemail\n"; 
    $headers .= "Reply-To: $email_address";

    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: http://www.domain.com/contacts');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>Contact form handler</title>
</head>

<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>


</body>
</html>
phorce 131 Posting Whiz in Training Featured Poster

Hey,

What language are you creating the Application in? I haven't ever tried doing this; so this is basically going off theory. But, you could try locating them through their longattiude and lattidude and then using Googles API try and search for the nearest Cafe around this data. This is just a thought though.

I don't know what you could do specifically in using PHP, since, if you go on the data provided by the IP then this may not be accurate as say the GPRS system build into the iPhone/iPad. I did read an article, which used Javascript/jQuery to retrive the users current location, however, this did prompt the user to accept it.

Hope this helps, again, just theory.

phorce 131 Posting Whiz in Training Featured Poster

Hello,

Quick question.. I'm trying to get the mean of a matrix (vector) now before I created a function that did it but I thought that it isn't really an effective way of coding. I've been looking at the accumulate function online and wanted to ask if this would work:

double Matrix1Mean = accumulate(matrix1.begin(),matrix1.end(),init)/(size_row*size_col);

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I have this matrix:

0 0 1 0
0 0 1 0
1 1 1 0
0 1 0 0

and I need to print out the block with the coords: (2,1) so in this case:
1 0
1 0

I have tried this:

for(int i=minRow; (i < 2); i++)
    {
        for(int j=minCol; (j < 2); j++)
        {
            cout << matrix1[i*2+j] << ' ';
        }
        cout << endl;
    }

As well as this:

for(int i=minRow; (i < 4); i++)
    {
        for(int j=minCol; (j < 4); j++)
        {
            cout << matrix1[i*4+j] << ' ';
        }
        cout << endl;
    }

But it doesn't work, does anyone have any suggestions? Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

This may sound really noobish, and I'm probably missing something really stupid.. But, I'm trying to calculate the differences between matrices, and the one with the smallest value (result) is the matching number.. But, for some reason my algorithm seems to be missing the smallest number and I can't figure out why..

Here is the code:

int min_val = 0;
double comp = 0;
const int ROW_BOUNDS(mat1Rows-mat2Rows+1);
const int COL_BOUNDS(mat1Cols-mat2Cols+1);

for(int i=0; (i < ROW_BOUNDS); i++) {
    for(int j=0; (j < COL_BOUNDS); j++) {
        m3.clear();
        for (int row(0); row < mat2Rows; row++){
            for (int col(0); col < mat2Cols; col++){
                //cout << matrix1[i*mat1Cols+row*mat1Cols+col+j] << ' ';
                m3.push_back( matrix1[i*mat1Cols+row*mat1Cols+col+j] );
                currentRow = i;
                currentCol = j;
            }
        }
        comp = compMatrix1(matrix2, m3);
        //printMatrix(m3, 2, 2);
        //cout << endl << " = " << comp << endl; 

        if(comp < min_val)
        {
            minRow = currentRow;
            minCol = currentCol;
            m4 = m3;
            min_val = comp;
            cout << min_val;
        }
    }
}    
//printMatrix(m4, 2, 2);

And here is the output:

0 0
0 0
= 2
0 1
0 1
= 4
1 0
1 0
= 0
0 0
1 1
= 2
0 1
1 1
= 3
1 0
1 0
= 0
1 1
0 1
= 3
1 1
1 0
= 1
1 0
0 0
= 1
It prints:

0 0
0 0
When the actual result should be:

1 0
1 0
Could anyone offer any help please?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

So here is the comparision function:

float compMatrix(vector<double>&matrix1, vector<double>&matrix2)
{
    int sum1 = 0;
    int sum2 = 0;
    int diff = 0;
    for(int i=0; (i < matrix2.size()); i++)
    {
        sum1 += matrix2[i];
    }

    for(int i=0; (i < matrix1.size()); i++)
    {
        sum2 += matrix1[i];
    }
    diff = sum1-sum2;

    return diff;
}

And the algorithm (in main)

int currentRow(0), currentCol(0),
            minRow(0), minCol(0),
            maxRow(0), maxCol(0);

        int min_val = 0;

        const int ROW_BOUNDS(mat1Rows-mat2Rows+1);
        const int COL_BOUNDS(mat1Cols-mat2Cols+1);

        for(int i=0; (i < ROW_BOUNDS); i++) {
            for(int j=0; (j < COL_BOUNDS); j++) {
                m3.clear();
                for (int row(0); row < mat2Rows; row++){
                    for (int col(0); col < mat2Cols; col++){
                        //cout << matrix1[i*mat1Cols+row*mat1Cols+col+j] << ' ';
                        m3.push_back( matrix1[i*mat1Cols+row*mat1Cols+col+j] );
                        currentRow = i;
                        currentCol = j;
                    }
                }
                double comp = compMatrix(matrix2, m3);
                if(comp < min_val)
                {
                    minRow = currentRow;
                    minCol = currentCol;
                    m4 = m3;
                }else if(comp == min_val)
                {
                    minRow = currentRow;
                    minCol = currentCol;
                    m4 = m3;
                }
            }
        }    

Here are the values I'm entering:

M1 =
0 0 1 0
0 0 1 0
1 1 1 0
0 1 0 0
M2 =
1 0
1 0

And when I run the program it says: Found the best between: (row): 2 And: (col): 2

But the resulting matrix is:
1 0
0 0

When it should be:
1 0
1 0

Because there is no difference at all.

Can you see where I'm going wrong?

Would really appriciate any advice …

phorce 131 Posting Whiz in Training Featured Poster

I don't understand, could you explain please?

phorce 131 Posting Whiz in Training Featured Poster

lp yours

Hey,

I've tried this:

for(int i=0; (i < ROW_BOUNDS); i++) {
        for(int j=0; (j < COL_BOUNDS); j++) {
            for (int row(0); row < mat2Rows; row++){
                for (int col(0); col < mat2Cols; col++){
                    float corr = difference(i, j, matrix2, matrix1);
                    if(corr < corrVal || corr < corrVal2)
                    {
                        row = i;
                        col = j;
                        corrVal2 = corr;
                    }
                }
            }
        }
    }

But it seems it doesn't find the right position.. E.g.

M1 =
0 1 1 0
0 1 1 1
1 0 0 0
0 0 0 0

M2 =
0 0
0 0

And it returns
row = 0;
col = 0;

Any advice?

Thanks

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm trying to determine where a small matrix would fit inside a big matrix.. But, the small matrix is not in the big matrix so I need to see how simular they are.. The one with the lowest value, is the best fit..

So my difference function is this:

float difference(int row, int col, vector<double> &matrix2, vector<double>& background)
{
    int matrix2_width = 2;
    int matrix2_height = 2;

    int background_width = 4;
    int background_hight = 4;

    int i=0; 
    int j=0;
    float diffSum = 0;
    float percentDiff = 0;

    if(col+matrix2_width >= background_width || row+matrix2_height >= background_hight)
        return 1;

    for(int i=0; (i < matrix2_width); i++)
    {
        for(int j=0; (j < matrix2_height); j++)
        {
            int sum1 = background[(row+j)*background_width+(col+i)];
            int sum2 = matrix2[j*matrix2_width+i];
            diffSum += abs(sum1 - sum2);
        }
    }
    percentDiff = diffSum/(matrix2_width*matrix2_height*255);
    return percentDiff;
}

And the Algorithm that I'm using:

 int mat1Rows(4), mat1Cols(4), mat2Rows(2), mat2Cols(2);
    const int ROW_BOUNDS(mat1Rows-mat2Rows+1);
    const int COL_BOUNDS(mat1Cols-mat2Cols+1);
    for(int i=0; (i < ROW_BOUNDS); i++) {
        for(int j=0; (j < COL_BOUNDS); j++) {
            for (int row(0); row < mat2Rows; row++){
                for (int col(0); col < mat2Cols; col++){
                    float corr = difference(i, j, matrix2, matrix1);
                }
            }
        }
    }

The only problem that I'm having is capturing the corrdiants of the matching block..

Could anyone offer any advice?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I have been reading an article on comparing data, and have been given this code:

for(i = 0; i < matrix1W; i++)
{
    for(j = 0; j < matrix2H; j++)
    {
        diffSum += abs(matrix2->pData[(row+j)*backW+(col+i)] - marix1->pData[j*matrix2+i]);
    }
}

Now it works when using arrays, but, I'm using vectors, is it possible to convert this code to perform the calculation on vectors? It doesn't like the "->" or pData??

Any ideas would be great, thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hey thanks for the advice, something like this:

    double compareMatrix(vector<double> &theMatrix1, vector<double> &theMatrix2)
{
    double matrix1Sum = 0;
    double matrix2Sum = 0;
    double simualirty = 0;

    for(int i=0; (i < theMatrix1.size()); i++)
    {
        matrix1Sum = theMatrix1[i] * theMatrix1[i + 1];
    }

    for(int i=0; (i < theMatrix2.size()); i++)
    {
        matrix2Sum = theMatrix2[i] * theMatrix2[i + 1];
    }

    simualirty = (matrix1Sum+matrix2Sum);

    return simualirty;
}
// main
    double corrVal = 0;
    int mat1Rows(4), mat1Cols(4),
    mat2Rows(2), mat2Cols(2);

    const int ROW_BOUNDS(mat1Rows-mat2Rows+1);
    const int COL_BOUNDS(mat1Cols-mat2Cols+1);
    vector<double> m3(2*2, 0);
    for(int i=0; (i < ROW_BOUNDS); i++) {
        for(int j=0; (j < COL_BOUNDS); j++) {
            m3.clear();
            for (int row(0); row < mat2Rows; row++){
                for (int col(0); col < mat2Cols; col++){
                    //cout << matrix1[i*mat1Cols+row*mat1Cols+col+j] << ' ';
                    m3.push_back(matrix1[i*mat1Cols+row*mat1Cols+col+j]);
                    double currentCorrVal = compareMatrix(m3, matrix2);
                    if(currentCorrVal > corrval)
                    {


                    }
                }
            }
        }
    }

But the only problem I can see with this is, once I've found the best match for the matrix2, I need change all the elements in matrix2 to "0" but, it has to be in the same position as it is in matrix1 because I need to output. If this makes sense? So basically:

Check if currentCorrVal > corrVal
   if true 
    store the position of the best fit matrix in matrix1
   if false
      iterate through again

Change all the elements in the highest result (matrix) to all 0's

If that makes sense?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hey (And my life just get's worse) ..

It appears that Matrix 2, doesn't actually exist inside Matrix 1 .. Well, it does, it just contains noise and such

Do you think I could pass m3 to a function that checks the simulairty of M3 to M2 and whichever has the highest simularity then this is the resulting matrix?

Thanks

phorce 131 Posting Whiz in Training Featured Poster

Hey thank you, it works on the test data (4x4), (2x2) but when I try it on actual data (1024x786) and the small matrix is: (36x49) it doesn't seem to work and just carries on printing..

    int mat1Rows(1024), mat1Cols(786),
    mat2Rows(36), mat2Cols(49);

    const int ROW_BOUNDS(mat1Rows-mat2Rows+1);
    const int COL_BOUNDS(mat1Cols-mat2Cols+1);
    vector<double> m3;
    for(int i=0; (i < ROW_BOUNDS); i++) {
        for(int j=0; (j < COL_BOUNDS); j++) {
            m3.clear();
            for (int row(0); row < mat2Rows; row++){
                for (int col(0); col < mat2Cols; col++){
                    cout << matrix1[i*1024+row*1024+col+j] << ' ';
                    m3.push_back(matrix1[i*1024+row*1024+col+j]);
                }
                cout << endl;
            }
            if ( m3 == matrix2 )
            {
                cout << "Equal!" << endl;
            }else{
                cout << "Not Equal!" << endl;
            }
        }
    }

Do you think I would need to change the ROW_BOUNDS, COL_BOUNDS?

Thank you again by the way :)

phorce 131 Posting Whiz in Training Featured Poster

This question makes no sense at all, what do you mean by 'theme'?

Why not just have a folder (Let's call it "themes") that stores all the documents to that particular theme then store the file path to that theme in the database?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

This might be wrong, I haven't ran it.. But, if this is all in the same .php file, then surely you've already defined $result above? So when you do this:

$query="select amount_id from payment where admission_no='$admission_no'";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)){ ** **// line 250
$amount_id=$row['amount_id'];
}

Maybe that is what is triggering it.

phorce 131 Posting Whiz in Training Featured Poster

So basically try this:

$success = mysql_query($final) or die(mysql_error());
echo "<table><tr>";

foreach($_POST['fields'] as $f){
echo "<th>".$f."</th>";
}
echo "</tr>";
while($row = mysql_fetch_assoc($success)){
echo "<tr>";
echo "<td>".$row['FIELD_NAME']."</td>"; // $r['username']; as an example
}
echo "</tr>";
}

echo "</table>";

I don't understand what "i" was doing there, or the foreach statement. Since the while loop will end when it returns false (or the query is ended).

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

Hey,

You could try using a header system (Let me explain):

Basically, have a file called: header.php which contains all the content around the where the different pages will exist (so like index.php, about.php etc) and then on each page you can call the header.php. This meaning that if you wanted to change the links then you can do this easily by just changing the header.php file and it will change every single page that has included the header..

Another solution could be to create a function:

<?php
 // links.php
function links()
{
   echo '<a href="link1.php">link 1</a>';
}
?>

<?php
   // index.php
     // include the links function
     include ('links.php');

     links();
?>

Hope this helps :)

phorce 131 Posting Whiz in Training Featured Poster

Hey

I don't know if this would work, but try it..

class Server {

    public: 
        Server();
        void SetMode();
    protected:
      static const int MODE_NONE;
      static int SERVER_MODE;

};

Also, in your class functions:

// set the mode in your main
void Server::SetMode(int theModeNone)
{
  SERVER_MODE = theModeNone;
}

// then in main
// have something like this:

Server s;

s.setMode(1);

Hope this helps, in your classes, try splitting the functions/variables seperately (Like the example) and using private/protected

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I have 2 vectors, and I'm trying to search/scan the first vector for the second vector.

Let's say I have this vector/Matrix:
M1 =

0 1 1 0
0 1 1 1
1 0 1 1
0 0 0 1

M2 =

0 1
0 1

Then I will search the M1 for M2 by scanning each value (Kind of like a binary tree) or until it's found the right solution. Now I'm using an algorithm like this:

const int ROW_BOUNDS = matrix1.size() - matrix2.size(); // 16 - 4
const int COL_BOUNDS = 4 - 2;

   bool found = false;

   for(int i=0; (i < ROW_BOUNDS); i++)
   {
      bool matchFound = false;

      for(int j=0; (j < COL_BOUNDS); j++) {
         cout << matrix1[i*4+j] << ' ';
      }
      cout << endl;
   }

But when I try to output the results (using the same data provided above) I get this:

0 1 
0 1 
1 0 
0 0 
0 1 
2.1536e-314 2.1536e-314 
0 0 
0 0 
0 1 
9.88131e-324 2.78134e-309 
0 0 
0 0 

But I have tried different calculations, different values and I get the same result. I'm wondering if anyone can see where I'm going wrong and offer some help?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

Thanks for the reply.. So basically, if I have: 0 in the vector, after the conversion the value would then be: (something like) 0.0000000e+000 which can then be written back to the file..

I know that I need to convert it back to an unsigned char, the problem is when trying to populate it, no values are entered:

void writePNG(vector<double>&theMatrix)
{
    vector<unsigned char> pixels(theMatrix.size());

    for(int i=0; (i < 512*512); i++)
    {
        pixels.push_back(theMatrix[i]);
    }

    cout << pixels[1];
}

Even when I try to use "reinterpret_cast<unsigned char>" it errors out.

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm having trouble with something..

I have a vector of doubles and I need to convert the vector to an unsigned char so then I can write the contents to a text file. I can do this when reading the data from a text file, just not from a vector.

void writeToImage(const vector<double>& matrix)
{
    vector<unsigned char> image(matrix.size());

    image.push_back(reinterpret_cast<unsigned char>(matrix[0]));
}

This was just a small example that I've been playing around with. But also have tried this:

void writeToImage(const vector<double>& matrix)
{

    vector<unsigned char> image(matrix.size());

    for(int i=0; (i < 512*512); i++)
    {
        image[i]=(unsigned char)matrix[i];
    }

    cout << image[0];

 }

Could anyone help me please?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

This type of application is going to require jQuery/Ajax and PHP.

phorce 131 Posting Whiz in Training Featured Poster

Robert, was there any need to post that? No. Grow up.

phorce 131 Posting Whiz in Training Featured Poster

Hey,

Can you post the actual files where the errors are on?

:)