phorce 131 Posting Whiz in Training Featured Poster

Your code compiles for me. Are you sure you're passing something in the arguments? If I enter "Hello" into the argument then I get the following:

Hello 0Hello

If no argument is passed through, this code will segment, you should allow for this.

phorce 131 Posting Whiz in Training Featured Poster

Hey,

I learnt by starting to write what I was interested in.. So for example, the first application I built in PHP was a register and login system, from there I gained experience. There's no real "Best project to start learning" I would pick something that is:

1) Easy/less complex to do

2) Something that you're interesting in : Otherwise you will just get bored and fustrated. THINK of something you've seen online, or in the real world and try to put this into an application. (For example, with me it was "How does Amazon know what I was looking at the last time I visited?)

By having C++ / Python experience, this should help with the syntax.

Hope this helps you.

phorce 131 Posting Whiz in Training Featured Poster

... And the problem is?

phorce 131 Posting Whiz in Training Featured Poster

Call me crazy, but I'm pretty sure you misinterpreted "Do not use any string or array functions"
How can you store a letter (sentence, letter as in formal message) without at least allocating memory for it in some arbitrary place or another?

I don't see where in this assignment does it say print the sentence, so thereofre would a string or an array really be needed?

phorce 131 Posting Whiz in Training Featured Poster

I hate to do this, and I usually don't. But, the example you gave is off from what you gave in the example you gave. Please refer to this line: Here and this should answer your question.

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

Show what you have done so far?

phorce 131 Posting Whiz in Training Featured Poster

Hello,

There are a few problems within your code but, this stands out for me:

$sql="SELECT * FROM users WHERE username='{$user}' AND password='{$password}' LIMIT 1;";

Do you really need the LIMIT 1 here? I wouldn't say so, because, this SQL statement can only really return one row if you have set up your database correctly.. (I.e. primary keys.. Assuming that only ONE user can have that one USERNAME once). I would do this:

`$sql="SELECT * FROM users WHERE username='{$user}' AND password='{$password}'";

And a suggestion:

$result=mysqli_query($con, $sql) or die("Blah blah");

Hope this helps you a bit :)

As someone else mentioned on your other thread, try to use the OO mysqli.

phorce 131 Posting Whiz in Training Featured Poster

First off all, in my honest opinion I wouldn't "rate" myself in languages. Whatever the language/rating is. From my view, let's say I rated myself 10/10 for PHP.. That's kind of like saying: I know EVERYTHING about PHP Thus meaning with that attitude I might not be able to progress with things.. You CAN learn something new everyday about a language providing you're active in this, of course.

On a subnote, it's difficult to answer the question on study guides because everyone learns differently. This question is like asking: What is the best programming language ask 10 different people, you're more than likly to get 10 different answers. However, I learn a new language, or, learn more about a specific language by participating in projects; specifically that challenges me and interests me (I don't want to get bored!).. Do I think you should have a study guide to say:

  • Monday - C++
  • Tuesday - PHP
  • ....

No. Just think of projects, and, as well as this, make sure you participate in forums like Daniweb, interact and view the questions and attempt to answer them, even if it means opening up a text editor and compiling, you will/should lean.

Hope this helps a bit :)

Thanks

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I am having a few problems when trying to execute the a Makefile that will hopefully create a static library that I can use for future use. Here is my code below:

#-----------------------------------------------------------------------------
#   Usage of make file
#-----------------------------------------------------------------------------
# Clean operation:
#   make -f MakeClient clean
#
# Make operation:
#   make -f MakeClient
#
#


#OBJ = $(SRC:.cpp=.o)
OBJ_DIR = ./obj

OUT_DIR= ./lib
OUT_FILE_NAME = libclient.a

# include directories

# C++ compiler flags (-g -O2 -Wall)
CCFLAGS := -std=c++0x

# compiler
CCC = g++ 


# Enumerating of every *.cpp as *.o and using that as dependency
$(OUT_FILE_NAME): $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(wildcard *.cpp))
    $(CCC) -static $(LIB_DIR) $(LIBS) -o $(OUT_DIR)/$@ $^

#Compiling every *.cpp to *.o
$(OBJ_DIR)/%.o: %.cpp dircreation
    $(CCC) -c $(CCFLAGS) -o $@ $<

dircreation:
    @mkdir -p $(OUT_DIR)
    @mkdir -p $(OBJ_DIR)

.PHONY : clean
clean:
    rm -f $(OBJ_DIR)/*.o $(OUT_DIR)/$(OUT_FILE_NAME) Makefile.bak

And I get the following error(s):

g++  -c -std=c++0x -o obj/FFT.o FFT.cpp
g++  -c -std=c++0x -o obj/complex.o complex.cpp
g++  -static   -o ./lib/libclient.a obj/FFT.o obj/complex.o
ld: library not found for -lcrt0.o
collect2: error: ld returned 1 exit status
make: *** [libclient.a] Error 1

The problem seems to be associated with this line:

# Enumerating of every *.cpp as *.o and using that as dependency
$(OUT_FILE_NAME): $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(wildcard *.cpp))
    $(CCC) -static $(LIB_DIR) $(LIBS) -o $(OUT_DIR)/$@ $^

But cannot figure what the problem is.

Hopefully someone can help,

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Try the following:

int main( int argc, char* args[])

Instead of:

int main( int argc, char*, args[])

Hope this helps :)

Tumlee commented: Yup. +5
iamthwee commented: nice +14
phorce 131 Posting Whiz in Training Featured Poster

Daniweb rules clearly state that a thread cannot be requested to be deleted (Unless the rules have seriously changed). If the thread contains personal information then you can request this to be edited out from the thread.

Hope this helps :)

phorce 131 Posting Whiz in Training Featured Poster

What is the question / problem?

phorce 131 Posting Whiz in Training Featured Poster

First of all, it's good practice to declare your class variables like this:

protected: 
    int id;
    int section;
    int quiz1;
    int quiz2;
    int finalExam;
    static int count;

There are also private and public

Second problem, in the function

void set(static int counter ){
        counter = count;
    }

You are passing through a static int, this is not allowed since you're just passing through the variable, and, have already defined your static member above. So just do:

void set(int counter ){
        counter = count;
    }

NOTE:

Shouldn't it be count = counter since I assume you are passing in counter in order to set the static variable?

However, because in one of your tasks it states that you have to count the number of objects being passed through, I do not know how this would work in your example. A more common way would be to increment the static variable inside of the constructor, like so:

class Example {

    public:
    static int var;

    Example() {
        var++;

    }


};

int Example::var = 0;

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

    Example e1;
    Example e2;
    Example e3;

    cout << Example::var; // 3
}

Hope this helps, anymore questions, feel free to ask

phorce 131 Posting Whiz in Training Featured Poster

So basically, I'm working on a project that can require both arrays and vectors to be passed through in order to calculate the final outcome. Now, I'm using the constructor to calculate the values and I need to know whether or not it is possible to change the datatype of the values depending of that what is passed through the constructor. Example:

class FFT {

    public:

        FFT(<array> &values_to_be_passed_through || <vector> &values_to_be_passed_through)
        {
            this->val = foo;
        }


    private:
        vector/array vals_to_be_passed_through

};


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

    int arr[] = {1, 2, 3, 4, 5, ......., 10};

    FFT fft(arr); // this would work.

    vector<int> values = {1, 2, 3, 4, 5, ......., 10};

    FFT fft(values); // this would also work.   
}

I know what the return type of the function would always be. i.e. in this case, it would be a complex (I've already wrote this) but I need to alternate to allow for multiple datatypes to be passed through.

Would this be possible using templates?

I hope someone can help me :)

phorce 131 Posting Whiz in Training Featured Poster

Sorry guys, fixed the error. I believe it was to do with my code. But it's sorted :)! Thanks!

phorce 131 Posting Whiz in Training Featured Poster

Hey,

I've changed the type to just "date" and tried the following:

    $getWeeks = "SELECT * FROM FlipCards WHERE week >= DATE_SUB(NOW(), INTERVAL 1 WEEK)";

But still get no results shown, even though the date is actually: '2013-06-28' "28" is in this week. Argh, any suggestions?

phorce 131 Posting Whiz in Training Featured Poster

I have not visited PHP/MYSQLI for some time now, and, need some guidance on the following problem:

I'm trying to retrive all the data from the given week and just in that week. My table looks like the following:

id int(11)
type varchar(255)
week datetime

And as a test data I have the following:

1 Sport 2013-05-28 00:00:00

This is within this week, and, therefore should be returned, however, it does not return. Again, I am just getting back into PHP/MYSQLI so there may be a problem with my query, I just cannot seem to figure it out. Here is it below:

<?php

$mysqli = new mysqli("localhost", "root", "root", "Site");
if($mysqli->connect_errorno) {

    die("Cannot connect to the database");

}

$getWeeks = "SELECT * FROM FlipCards WHERE week => currdate - INTERVAL DAYOFWEEK(currdate())+6 DAY
            AND date < currdate() - INTERVAL DAYOFWEEK(currdate())-1 DAY";

$result = mysqli_query($getWeeks);

if(mysqli_affected_rows($result, $mysqli) >= 1)
{
    echo 'There has been a row matched!'
}
?>

Could anyone please suggest where I am going wrong? I believe it has something to do with the query.

phorce 131 Posting Whiz in Training Featured Poster

You are incrementing by 1, and, outputting the method. Also, your class is wrong:

#include <iostream>

using namespace std;

class B {

    public:
        B() { };

        int func() {
            return this->data++;
        }
    private:
        int data;
};

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

    B b;

    cout << b.func() << endl;
    cout << b.func() << endl;
}

Output: 0 1

If you have an int method data type then the compiler expects you to return an integer but in this case you outputted and then returned the integer which is probably why you were getting the output.

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

The chat feature is a a major factor, and not just "set" chat rooms either, provide the user the ability to make their own chat rooms, as well as having multiple rooms where people can speak about different topics. Even if this is not possible, or would take a lot of implementing then bring the functionality of the IRC into the domain, people like to talk. :)

Enhance the community features, and, trust the users - especially the ones with high rep and who have been around for a long time. For example, in a case the other day, a user was making threads that just had I need help, Please can you help me and this could have been resolved quickly (Either with enough negative downvotes then the thread is removed from public viewing OR deleted). Same with editing the question. Daniweb recieives a lot of members who have very little english and although I have learnt to translate the point they are trying to get across it can be frustrating at times posting back saying What? or What is it that you want to ask? whereas if members with a certain repuatation score could edit the thread to make it more understandable, this would provide a clearer question. (Let's be honest, if I'm looking for a specific question and I come across a daniweb page that someone has asked which isn't even readable english, I'm not going to even bother reading it).. Validity is important. This will give …

phorce 131 Posting Whiz in Training Featured Poster

I understand you need help, but, if you don't explain what it is you're trying to do then we cannot help you. Sit down, think about the question you want to ask and then post it and someone will be sure to help you :)

phorce 131 Posting Whiz in Training Featured Poster

What is your question? What are you trying to do? What are you finding difficult? We cannot help you if you do not provide enough details. Understand this!

phorce 131 Posting Whiz in Training Featured Poster

Your questions does not make sense. What do you mean

area of posters in the pan

Posters? Pan?

phorce 131 Posting Whiz in Training Featured Poster

Are you spamming the system?

If you have a question, then ask it! Do you want us to read your mind to find out the question?

phorce 131 Posting Whiz in Training Featured Poster

This is totally based upon my own opinion and is not to hit out at anyone, or, take favour in any other question based forum that may exist on the internet.

  • Boring at times, not very quick paced

At times it can be, and, this seems to be mainly due to the amount of time it takes for people to respond to questions. I come on here mainly to help people and seek other places to be ask questions. I feel as though, more fast paced and dynamic sites gain a higher reception and at a quicker pace. For example, in my experience it generally is easier if I'm coding away to just ask a question on another site and gain a quick reply that is not very discussion based i.e. What compiler are you using whereas on DaniWeb your question could not be replied to, or take hours for someone to reply. I know I will receive negative feedback for this, but, IMO this is the case.

There is very little to do other than post/reply to questions. The site claims to provide a community based questions and answers forum and yet there is actually very little for the community to do. There are times where I've come online and scanned through the questions to find the same type/style of questions being repeated or certain people have answered and thus makes me think meh no point even replying. There is a nice atmosphere and good vibe in …

phorce 131 Posting Whiz in Training Featured Poster

Hey, I think (And I maybe wrong, so anyone please do correct me i've been out of PHP doing C++ for a while) but your problem seems to be that you're trying to compare a string that has already been encrpyted against another.. E.g.

<?php

    session_start();

    ini_set('display_errors', 1);

    $Username = $_POST['Username'];
    //$Password = $_POST['Password'];
    $Password = "abc123";
    $CurPassword = crypt("abc123");
   // $CurPassword = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/DB/Hash');

    if(crypt($Password, $CurPassword) == $CurPassword){
        echo("MATCH");          
    }

    else{   
        echo("NO MATCH");   
    }

?>

This works, mainly because I am encrpyting plain-text ("abc123") and therefore not comparing against actual encrpyted (Not two way!) Anyway, I hope you resolve the issue and someone else may be able to throw something to this :)

phorce 131 Posting Whiz in Training Featured Poster

IMO I wouldn't crypt the password, more, hash them but it's up to you. I don't get why you're encrypting it, since hashing it to some extent should provide a safer solution.

L database, which I know is vulnerable to injection. Is a Flat File database like this still vulnerable, and how can I protect against it? At the moment, the only real security I have on the file is an HTAccess restriction and restricted file permissions.

Ideally you should be using PDO or mysqli (PDO should provide you with a safer option). I'm guessing this password is somehow stored inside a text-file? How many passwords are there going to be? If you assume there are going to be a lot of passwords, are you going to have multiple text files? If so.. This is not a safe route to go down.

P.S. Crypt isn't two way encription, which is very misleading. Which is probably why you're running into such problems.

Hope this helps you

phorce 131 Posting Whiz in Training Featured Poster

Hey,

Probably a silly question.. Have you tried echoing the $Username and $Password and $Curpassword to see if they contain the expected values?

phorce 131 Posting Whiz in Training Featured Poster

... And your question is?

phorce 131 Posting Whiz in Training Featured Poster

My example is having two global functions (not in any class), with same name and difference in type of parameter.

I kind of understand, check this out:

#include <iostream>
using namespace std;
double foo(double a, double b) {
    cout<<"foo(double a, double b)"<<endl;
    return a;
}
 int foo(int a, int b){
    cout<<"foo(int a, int b)"<<endl;
    return a;
 }
double Goo(float a, float b){
    cout<<"Goo(float a, float b)"<<endl;
    return a;
}
  int Goo(int a, int b){    
    cout<<"Goo(int a, int b)"<<endl; //this one
    return a;
  }

int main()
{
    foo(3.1,3.14); // Doesn't work
    Goo(3,3); //Works
}

Output:

foo(double a, double b)
Goo(int a, int b)
phorce 131 Posting Whiz in Training Featured Poster

No problem. If this answers your question, please mark this thread as solved.

Good luck with your project :)

phorce 131 Posting Whiz in Training Featured Poster

In your code there is an error:

 void set_Name(string n){
        string dvdName=n;
    }

Since you re-clare dvdName as a string. This is not correct. First re-design your class into a structure that is more Encapsulation:

Let's call this class "dvd.h"

class DVD_DB {
static int TotalDVD;
public:

    DVD_DB();
    void set_Name(string n);
    string showName();

    void set_price(int p);
    int show_price();

    void set_pricedDvdQuantity(int q);
    void get_quaintity();

protected:

    string dvdName;
    double dvdPrice;
    int dvdQuantity;

};

We do not need to have functions that are: void show_name(){ for example because placing cout commands inside the methods is very bad. You should use these in your main to output the desired result.

We can now make the actual implementation of this class, and, let's call this file: DVD.cpp:

DVD_DB::DVD_DB(){};

void DVD_DB::set_Name(string n)
{

}

string DVD_DB::showName() {
    return dvdName;
}

//....

//.....

And then in your main you can initialise an array of objects like so:

    DVD_DB *d = new DVD_DB[10];

    d[0].set_Name("foo");
    d[1].set_Name("boo");

    cout << d[0].showName();
    cout << endl;
    cout << d[1].showName();

I hope this gives you an idea. Get your main class structure working before you worry about operator overloading and other things.

phorce 131 Posting Whiz in Training Featured Poster

You should attempt to look at HTML5. There is a tag: Here

You can also use jQuery etc.. To manipulate and extend this feature more.

Is there a specific reason to why it has to be in PHP?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

What is the purpose of the example you are trying to give? Polymorphism is about change "poly" and thus meaning that the expected outputs for each can be changed depending on which object is called.

Look at another example (The one you gave does not really make sense to me).

Assume the follow:

If you have a class Animal:

class Animal {

    Animal(); // constructor 

    void speak();

};

We can assume that the every animal speaks, however, we know that a Dog and a Cat speak differently but we can use polymorphism to change the events or actions depending on the object:

class Animal {

    public:

        Animal(){};
        void speak()
        {

        };
};


class Dog : Animal {

    public:
        Dog() { };
        void speak()
        {
            cout << "Woof";
        }
};

class Cat : Animal {

    public:
        Cat() { };
        void speak()
        {
            cout << "Meow";
        }
};

int main()
{
    Dog d;
    Cat c;

    d.speak(); // "Woof"
    c.speak(); // "Meow"
}

Hope this makes a bit more sense. I just did not understand the example you gave.

P.S. In terms of your initial question regarding the code you submitted; it seems that you are not over-riding the functions correctly. I.e. you declare the first function foo of that as a double but then the second one as an int but you do not use classes. Polymorphism is a type of OO concept and the example you gave is not really OO even though it does have …

phorce 131 Posting Whiz in Training Featured Poster

Hello,

If you're reading a .wav file then you need to read the file properly; the .wav file contains both the "Header" information, as well as the actual "raw data" and you need to read these separately rather than the whole of the file.

You can check this website for more details on how to read a .wav file:

Click Here

This could be the problem that you're having when reading in the .wav file since you do not consider these values. From my experience, and, IMO you cannot just read a single .wav file into one massive chunk. For example, the "raw data" which I'm sure is what you want to manipulate contains both raw (native) as well as (double) values and thus depends on the bit-rate of the actual file.

I wrote a class for my finals which reads in both the raw data, as well as the header data. Message back if you would like to take a look at it, feel free to!

P.S. If you're attempting to do I am untimately, learning C++ to be able to manipulate a .wav files, just to write a script from scratch and be able to read file, and illustrate in a graphical interface like a spectrogram. then you should really consider using libraries, for example, something like this may involve the use of an FFT in order to convert the signal from the time domain into the freq domain which may involve some pretty intensive programming …

phorce 131 Posting Whiz in Training Featured Poster

Post what you have done far. No-one will do it for you

phorce 131 Posting Whiz in Training Featured Poster

Here is an example:

#include <iostream>

using namespace std;

bool uppercaseLetter(char ch)
{
    if(isupper(ch))
      return true;
    else
      return false;
}

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

    char ch;

    cout << "Please enter the character";
    cin >> ch;

    if(uppercaseLetter(ch))
    {
        cout << "Yes, its uppercase";
    }else{
        cout << "No, it's not uppercase";
    }


}

Try not to use cout and cin within a function, instead, pass the character char to the function which you have done in your example.

I hope this helps.

phorce 131 Posting Whiz in Training Featured Poster

What do you mean, nothing shows? Have you declared an object of this class?...

phorce 131 Posting Whiz in Training Featured Poster

Hey,

Try the following:

ini_get('safe_mode')

Before the function declation, if you've compiled PHP with --enable-safe-mode then defaults to On, otherwise Off. then this error would happen.

For more information, check the following: Here

Hope this helps you.

phorce 131 Posting Whiz in Training Featured Poster

idea to try and write a program that will help other people write C++ programs

I don't think you should be doing this just now, IMO because as you said you're a beginner yourself - Teach yourself before you start writing tutorials etc.. :) Of course, it might be a learning curve for you to try and write and understand the logic but like you said, there would be a lot of errors.

I don't know what you're asking, anything specific?

phorce 131 Posting Whiz in Training Featured Poster

Hey guys!

Just a quick question really: What happened to the spell check when you write in the forum posts? It seems to have gone for me D: even though I recieive the feature in other forums (no names) it's just annoying sometimes because I have to concentrate really hard on spelling (Sorry if there any in this!)

Also, is there any plans on building a real-time notification bar?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

I agree, kind of. However, I don't personally get too caught up on reputation points (They don't pay the bills!!) so therefore, it doesn't effect me what Person A and Person B has. My ethos is that you should want to help someone regardless of how many reputation points you get/have.

The amount of times "newbies" have come along, asked a question and recieived a really good response from someone to recieive no reputation is shocking but members still seem to do it.

My own personal opinion it's too much hassle to do what is suggested and you should WANT to help regardless of any reputation changes you may have.

Good day :)

phorce 131 Posting Whiz in Training Featured Poster

[removed]

phorce 131 Posting Whiz in Training Featured Poster

Could you please provide me with the ACTUAL data values that you have? You can post them onto pastebin

If it's taking a massive amount of time to run, you should look at optimising your algorithm so that it best fits to match your needs. C++ is very quick, however, it does depend on the system and the compiler that you are using and whether or not you are having any memory leaks and/or you are handling things in memory. You may find it a lot easier to read these values inside a 2D array and do your sorting that way.

Because your question was not broad and you were not seeking someone to do the work for you, post your values and I will take a look to try and improve the performance of this for you.

NOTE: Your program should not be running for more than 5 minutes with 100 values. There is something wrong here.

phorce 131 Posting Whiz in Training Featured Poster

Eh? Explain your question in more detail. This is very unclear!

phorce 131 Posting Whiz in Training Featured Poster

Just throwing this out there, this may not be the solution.

In this line you set the following interger to be a random number, where do you get this number from?

const int SIZE = 500000;

But, where you call your quick sort you call the following:

quickSort(test, 0, SIZE-1);

This would therefore assume that the last value is at position 500000 - 1 what if the array contains only 100 values? Would there be a position 499999? This is probably where your code is segmenting. You should also probably set the size of the array, i.e. how many values are inside the array and have this value to be the total number of elements that the array can handle. So for example, I entered your 100 values that you supplied and did the following:

quickSort(test, 0, 99);

Where we can assume that 0 is the first value inside the array and 99 is the last value, this printed out a result. Please see my attatched file.

You should debug your code, find out where it is going wrong.

Good luck :)

phorce 131 Posting Whiz in Training Featured Poster

Do you mean something like:

<?php
    $arr = array('mango','apple','orange','bat','cat','mat');

    foreach ($arr as $a)
    {
        echo $a . '<br />';
    }
?>
phorce 131 Posting Whiz in Training Featured Poster

You can do this by just having a function that returns a boolean:

Something like so:

bool checkExists(string file)
{
    ifstream file_to_check (file.c_str());
    if(file_to_check.is_open())
      return true;
    return false;

    file_to_check.close();
}
int main(int argc, char *argv[]) {

    string file = "file.txt";

    if(checkExists(file))
    {
        cout << "The file exists, sorry";
        exit(0);    
    }

    // handle the ifstream out
    //
    //
phorce 131 Posting Whiz in Training Featured Poster

It is unclear to what exactly you want to do in terms of "Speech". Do you just want to output what they are typing? For example:

typed: a
the voice would say: "A for apple"

This wouldn't be too difficult, however, if you wanted to implement an algorithm that can identify what someone is saying, then it would be more difficult so probably best to use a library if you have no background in Signal Processing (The mathematics are intensive).

Post back a full description (in a lot more detail) to what it is exactly you want to do.

phorce 131 Posting Whiz in Training Featured Poster

Your problem is on this line:

$result=mysql_query("select * from omr_result");

You cannot declare, or, set variables inside the class this way. You shoud consider trying to implement this inside a function:

public function query()
{
    $connect = mysql_query("SELECT * FROM something");

}
phorce 131 Posting Whiz in Training Featured Poster

I don't really understand what you are trying to do, or, the question here.

You need to store the values in an array /matrix/ You can read the values inside a 1D arrayint* matrix = new int[R*H] which can then act as a 2D array. But where do you get the value of '10' from the dataset that you provide?