phorce 131 Posting Whiz in Training Featured Poster

What have you done to understand the problem? Do you expect someone to do your problem? If it's "simple" and "not hard" then surly you would be able to do this yourself?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

So you need to mark this as solved, if your question has been answered. (There should be an option 'mark this thread as solved) and then, at the side of each of the members username, there is an arrow up and down click the up arrow if someone has helped you, or the down arrow if you feel the post is bad or just generally didn't like it.

Hope this helps :)

cambalinho commented: thanks +0
phorce 131 Posting Whiz in Training Featured Poster

I suppose you could do the following:

class Test {

    public:

        Test() {

        }

        Test(std::string val)
        {
            value = val;
        }

        std::string show(){
            return  value;
        }
    protected:

        std::string value;

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

    std::string vala = "Hello a";
    std::string valb = "Hello b";

    Test a(vala);
    Test b(valb);

    cout << a.show() << endl;
    cout << b.show();
}

What you're asking here is:

test a;
test b;

void a::Show()
{
   cout << "hello a";
}

void b::Show()
{
   cout << "hello b";
}

It is basically saying that there is a class called a and a class called b and these are therefore not obects you would create in main. For example: What if you had an array of objects going from a, b, c.... then would you therefore need to invoke a member class for each object? No, this isn't object oriented programming. You could have classes that call different member functions depending on the object that is called, this, however, is called Polymorphasim.

cambalinho commented: thanks +0
mike_2000_17 commented: Keep it up! +14
phorce 131 Posting Whiz in Training Featured Poster

I believe what you are meaning here is Polymorphism?

Here is an example:

class Base {

    public:

        Base() { }
        virtual std::string speak() { return 0; } 
};

class Dog : public Base {
    public:
    Dog() { }
    std::string speak() {
        return "woof";  
    }
};

class Cat : public Base {
    public:
    Cat() { }

    std::string speak() {
        return "meow";
    }
};
int main(int argc, char *argv[]) {

    Dog d;

    cout << d.speak(); 

    Cat c; 

    cout << c.speak();
}

Depending on which object I define, determines the output and therefore will change.

Also, it is not good standard to have cout << in any class members.

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

The only reason the US wants to take Military action is to nuke the hell out of Syria, thus killing innocent people and all to show Iran and the rest of the world what such a powerful country the US is.

The security council and the UN should come up with a peaceful resolution without getting involved.

phorce 131 Posting Whiz in Training Featured Poster

In checkLogin.php you could try putting:

session_start(); since everywhere you use sessions, should include this.

phorce 131 Posting Whiz in Training Featured Poster

If you feel your question has been answered, could you mark it as solved and give rep to those who you think has helped you?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

by that i meant do you know of any good ways to learn C++ or Java and any good websites.

Try Here Or just search for C++ tutorials to help get you started. Once you are familiar with the basics, you can start building up and up and up (OOP) =)

we had to make a bridge traffic light signal work by controlling both sides of the bridge

There we go! Get yourself a Raspberry Pi, some LEDS and a breadboard.. You can develop your C++ skills in recreating this, it would be a fun project to do as well!

phorce 131 Posting Whiz in Training Featured Poster

1) the course is called Computer AS/A level so i take it that wont teach me the skills i need? so instead of this course what course would you recommend for going on to studying compuer science at university?

This is correct. At least, from my point anyway. Most of the experiences that I've had is that people come into the University enviroment from studying AS/A-Levels and do not know about programming, or, the mathematics behind computing and therefore struggle. It is also important to note that the first year of your University course is a year where everyone has the ability to get onto the same level as everyone else (remembering, everyone has come from a different background!)

That being said: I don't think you should rule out AS/A-Levels and speak to your teachers about the content of the course, and, in your own time, use it to study the things that you will need in order to allow for progression.

2) Yeah Java and C++ are the languages i would like to get into its just i have no real way to learn the languages. So if you have any pointers it will be highly appreciated :)

It's really hard to say which one I recommend choosing first as I do not know your programming background. Specifically, I choose NOT to read from books as these are often written from the prospective of the person writing them so you end up in some way …

phorce 131 Posting Whiz in Training Featured Poster

Okay, it seems like you're from the UK and you're in the United Kingdom so here is some advice:

1) Try to stay away from A-Levels (especially in Computing!) Most Computing courses at A-Level will not teach you the vital skills that you need in order to progress onto further education and your future work. You should ideally choose the type of Computer Science related topic. However, specifically in the UK Universties most of the courses depend on programming and therefore this becomes a major importance of this. Choose College after your school days are over.

2) Do not learn VB or C unless you have a series view of doing it, as, you are not likly to do any of these languages when you decide to go to University to study Computer Science. Instead, you should attempt to read up on C#, Java and C++ as these are the most favoured languages to guide you.

3) Learn other technologies. Again, Computer Science courses are pretty open on the types of Operating systems you can use. It's always a good idea to learn Linux and the GCC compiler because this will always come in handy when you decide to go into University or infact, work.

4) Depending on the Universit(s) you plan to go to (Do you have any idea?!) To study this Computer Science course, you should look at their course content and see what is expected from you. I.e. Computer Programming: What languages? What type of Porgramming will …

phorce 131 Posting Whiz in Training Featured Poster

You need to do some research on Templates. This clearly would not work in main because there is no way at run-time to determine what types are the variables. (In this example, anyway).

The correct thing would be to do the following:

#include <iostream>
#include <cstdlib>
#include <string>


using namespace std;

template<typename T>
T declareVariable(T theVariable)
{
    T temp = theVariable;

    return temp;
}
int main()
{
    string value = declareVariable<string>("hello");

    cout << value;
}

Notice how in main I can now allow for the variable to be declared so the compiler knows at run time?

I can therefore do this for an interger as well:

int value2 = declareVariable<int>(123);

This should be the solution :)

phorce 131 Posting Whiz in Training Featured Poster

Remember, Google / DaniWeb are your friends.

phorce 131 Posting Whiz in Training Featured Poster

No problem :) Please make this thread as solved and give rep to those who helped you

phorce 131 Posting Whiz in Training Featured Poster

Just realised the above code wouldn't work. This will:

#include <iostream>

using namespace std;

class Foo {

    public:

    Foo()
    {
        counter++;
    }

    static int getCount()
    {
        return counter;

    }
    protected:
    static int counter;
};

int Foo::counter = 0;
int main(int argc, char *argv[]) {

    Foo f;
    Foo b;
    cout << Foo::getCount() << endl;
}

My bad :) http://ideone.com/X5GPKA e.g.

phorce 131 Posting Whiz in Training Featured Poster

@bob - Some others may have a better more effective method to do this, but, just inside the while loop you can create an if statement that checks to see if the number is == 0 and if so, put the number back to 7.. Here:

 if(guessnumber == 0)
      {
         guessnumber = 7;
      }

Hope this helps :)

phorce 131 Posting Whiz in Training Featured Poster

@bob - Here you go

//****************************//
//*****DO NOT TOUCH THESE*****//
//****************************//
import java.util.*;
import java.io.*;

class NumberGuessingGame{

  public static int num;    //variable to hold randomly generated number
  public static int guess;  //variable to hold user inputs
  public static String ans; //variable to hold user input for y/n
  public static int guessnumber = 7; //variable to hold number of guesses
  public static int correctguess; //variable to hold number of correct guesses

  //the main method
  public static void main(String[] args) throws IOException{

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 

    //introduction
    System.out.println("Welcome to the Number Guessing Game!");

    //loop to allow the user to play again
    ans = "y";
    while(ans.equals("y")){
      numberGenerator();
      System.out.println("\nI have generated a random number between 1 and 100.  Please guess what the number is.");

      //TASK 1: limit the user to only 7 guesses
      guess = Integer.parseInt(br.readLine());

      //TASK 2 & 3: write in the conditions for when the user's guess is too high, too low, or correct
      //if the guess is correct, the user should not be able to keep guessing
      if(guess > num){
        System.out.println("Your guess is too low.");
        guessnumber--;
      }
      else if(guess < num){
        System.out.println("Your guess is too high.");
        guessnumber--;
      }
      else if(guess < 0){
        System.out.println("You have entered a number below 0. Would you like to try again? (y/n)");
      }
      else if(guess < 100){
        System.out.println("You have entered a number above 100. Would you like to try again? (y/n)");
      }
      else if(guess == num){
        System.out.println("CONGRATULATIONS! You have guessed the number correctly! Would you like to play again? (y/n)");
        correctguess++;}

        if(guessnumber == 6){ …
phorce 131 Posting Whiz in Training Featured Poster

This isn't the code I suggested you to use. Anyway, it looks like on line line 27 you terminate the while loop, so therefore, it cannot go any further inside the program. Remove this }

Indent code!!!

P.s You also need to implement the functionality of guessnumber for the program to allow for the number of guesses allowed. I'll give you a hint to this, since I get told off for giving out the answer..

If we Increment a number, we add ++ so i++ and if I was (0) it would increment upwards. 0, 1, 2, ....., 10

In this case, we need to decrement.

I hope this helps.

phorce 131 Posting Whiz in Training Featured Poster

@Bob mhm weird. Post the code that you're currently trying to run and I will take a look at it.

phorce 131 Posting Whiz in Training Featured Poster

@bob - What version of Java are you running? On my machine, it runs completely fine..

phorce 131 Posting Whiz in Training Featured Poster

Surely something like this..?

If you have a static variable called "counter" and then increment it by 1 each time the constructor is called then this should work.

#include <iostream>

using namespace std;

class Foo {

    public:

    Foo()
    {
        counter++;
    }

    int getCount()
    {
        return this->counter;

    }
    protected:
    static int counter;
};

int Foo::counter = 0;
int main(int argc, char *argv[]) {

    Foo f;
    Foo b;
    cout << Foo::getCount() << endl;
}

The above is just an example to demonstrate. :)

phorce 131 Posting Whiz in Training Featured Poster

@bob - You need to be able to terminate the program if the user enters "n" after the first guess.

Therefore just after line 80 inside this program you should enter: System.exit(0); to stop the program from repeating itself and therefore exit from the loop.

phorce 131 Posting Whiz in Training Featured Poster

@JamesCherrill - My bad. I was in a rush and therefore wanted to fix the problem over offering any tits or solutions how to fix the above code.

There are a lot of errors and syntax flaws within the submitted code and in no what what I typed was meant in an insulting way, my apologisies if this come across like so.

The code that I gave, should, no longer give you an infinite loop (From the last time I compiled it).

You should therefore break the code up. For example:

 if(guess > num){
                System.out.println("Your guess is too low.");
              }
              else if(guess < num){
                System.out.println("Your guess is too high.");
              }
              else if(guess < 0){
                System.out.println("You have entered a number below 0. Would you like to try again? (y/n)");
              }
              else if(guess < 100){
                System.out.println("You have entered a number above 100. Would you like to try again? (y/n)");
              }

You do not need so many else if statements, since, the output for each one of these is the same? If the output was different then I could understand why you would need more than one statement, however, 1 function which returns a Boolean depending on whether the guess is right or wrong SHOULD be enough. I.e.

if(numberGuessed)
{
   // this is true;
}else{
   // this is false;
}

Please feel free to post back if there are any more suggestions you would like making.

phorce 131 Posting Whiz in Training Featured Poster

It's been a while since I've looked at Java, so, forgive me if this does not work. In brief, what you're trying to do is delcare a method within a method - This is not allowed hence the error you're getting.

I have fixed the error, however, since you're declaring "NumberGuessingGame" as a public class, it therefore should exist in it's own file.

EDIT: I have also fixed the loop error (Yes, I'm in that good of a mood!!)

//****************************//
//*****DO NOT TOUCH THESE*****//
//****************************//
import java.util.*;
import java.io.*;

class NumberGuessingGame{

  public static int num;    //variable to hold randomly generated number
  public static int guess;  //variable to hold user inputs
  public static String ans; //variable to hold user input for y/n
  public static int guessnumber = 7; //variable to hold number of guesses
  public static int correctguess; //variable to hold number of correct guesses


  //the main method
  public static void main(String[] args) throws IOException{

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 

    //introduction
    System.out.println("Welcome to the Number Guessing Game!");

    //loop to allow the user to play again
    ans = "y";
    do{

        numberGenerator();
        System.out.println("\nI have generated a random number between 1 and 100.  Please guess what the number is.");
        guess = Integer.parseInt(br.readLine());

        //TASK 2 & 3: write in the conditions for when the user's guess is too high, too low, or correct
              //if the guess is correct, the user should not be able to keep guessing
              if(guess > num){
                System.out.println("Your guess is too low.");
              }
              else if(guess < num){
                System.out.println("Your guess is …
phorce 131 Posting Whiz in Training Featured Poster

This piece of code is a Class, which forms part of the OO techniques built into PHP. OO in itself is a very large subject, so, it would be impossible for me to write a massive post explaining it all, but, you can try the following links:

PHP Class
OOP

Within the code we have this:

public $config = array(); The public in this example tells the interpereter what the restrictions are of accessing this member (where the member is $config) and it's just assigning an array to this value. I assume you know what Arrays are? If not, there are tutorials online which will help to explain this.

IMO I think you should stay away from classes, and object-oriented programming until you know the basics of PHP or language syntax, logic and structure. Try not to download code, that you do not understand. :)

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

@iamthwee - Were they? I never ever noticed them ha!

phorce 131 Posting Whiz in Training Featured Poster

One thing I don't like/agree with is this:

6aa64fae3f4217234af3109222f1884f

1) It seems like a popularity constest. I'm all of recognising peoples achievements in this way but, really, really?

2) What's to stop someone looking at a particular forum, seeing who is the most active / experienced and then them annoying them via PM's in a hope their question would get a reply sooner.

Just food for thought :)

phorce 131 Posting Whiz in Training Featured Poster

Please could you include an example to your problem? It's kind of hard to find out where you are going wrong, but, here is an example (of what I assume you are trying to do):

// Test.h 

class Test {

    public: 

      Test(); // constructor 

      void doSomethingCreative();

};

And then your implementation of this class:

#include "Test.h" // assuming the header file is called "Test.h"

Test::Test()
{
   // constructor implementation
}

void Test::doSomethingCreative()
{
    // Method implemenation
}

At compile time, we just need to compile the .cpp file over the .h So, therefore your main will look something like so:

#include <iostream>
#include "Test.h"

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

   Test t;

   t.doSomethingCreative();
}

To compile, again, using GCC would be something like:

g++ Test.cpp main.cpp -o main
./main

Hope this helps slightly.

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

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

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

Is it th 256 or the 512 model? I know some distros do not seem to like the 512mb for some strange reason. I've never heard of this problem though, you may want to install another distro or re-install the current distro you have if you haven't done any serious work with it yet:

Check here!

Sorry I couldn't be more help. Hope you get this solved though

phorce 131 Posting Whiz in Training Featured Poster

Sorry, which distro is this?

I assume that you're working with a Raspberry Pi? But, I have never heard of this distribution.

phorce 131 Posting Whiz in Training Featured Poster

@PriteshP23 How do you expect SESSION to work, when you initialise a session, but, don't actually define anything as a session?

phorce 131 Posting Whiz in Training Featured Poster

@PriteshP23 - We have our own lives, and, we choose to help people. It is rude (and probably against the rules) to demand you want your code looking at and fixing. You haven't even told us what is going wrong (What are the error messages? If any..)

NOTE: We don't have your server, nor access to your database and we are not compilers / intepreters that can just read through your code and process it. TELL US what is going wrong with the code.

phorce 131 Posting Whiz in Training Featured Poster
$query="SELECT post,link from pagination ORDER BY id DESC
LIMIY $pageLimit,".PAGE_PER_NO;

Needs to be:

$query="SELECT post,link from pagination ORDER BY id DESC
LIMIT $pageLimit,".PAGE_PER_NO;

Should work :)

Please don't use mysql_* commands, they're being depreciated.

phorce 131 Posting Whiz in Training Featured Poster

What doesn't "work" you need be more specific!

Questions / points:

1) Does this even execute?

$CON // connection works

2) Don't use mysql_* these commands are being depreciated.

3) Where do you set the sessions? For example:

<?php
    session_start();
    $_SESSION['Phorce'] = "Phorce";


    echo "User: " . $_SESSION['Phorce'];

    session_destroy();

    echo "User: " . $_SESSION['Phorce'];

4) In "logout.php" if you want to destroy a session, why are you creating a new session just to destroy it? You create the session at the beginning of your script.

phorce 131 Posting Whiz in Training Featured Poster

First off:

void main( )

that's bad, you should use

int main()

This is also bad:

for (int x = i; x < 50; x++)

you shouldn't implicity hard-code these values, it should be the SIZE of the array and not 50 (even though your array length is 50) .. What if more values are added?

EDIT: Just re-read the function, my bad.

phorce 131 Posting Whiz in Training Featured Poster

No problem :)!

Please mark this as solved, if you have any more questions feel free to ask / post! Good luck

phorce 131 Posting Whiz in Training Featured Poster

You can't pass the vector as an array.. Your problem is here:

void counter(vector<int> count[]);

Do this:

void counter(vector<int> &count); // sending reference

Also, you can't allocate memory for a vector like this:

vector<int> list[5];

Instead you can do this:

vector<int> list(5, 0); // size of 5, pushes back 0's

Here, the code:

#include <iostream>
#include <vector>

using namespace std;

void counter(vector<int> &count);

int main (){    
        vector<int> list(5, 0);
        counter(list);

        return 0;
}

void counter(vector<int> &count){
        int i, j=0;

        for(i = 0; i <= count.size(); i++){
                j++;
        }

        cout << "There are " << j << " elements.\n";
}

Hope this helps :)

phorce 131 Posting Whiz in Training Featured Poster

Hey,

I don't think you can do this.. I'm guessing your database information is in the file, so therefore, the connection code needs to be there as well.

$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die('Oops connection error -> ' . mysql_error());
    mysql_select_db(DB_DATABASE, $connection) or die('Database error -> ' . mysql_error());

if these details are correct, you can then include/require/require_once the file and a connection to the database will be established WHICH will enable you to execute queries.. It doesn't know what DB_SERVER etc is/where it's stored.

EDIT: Can you post what is stored inside "connect_db", removing passwords etc.. =) Also, it's not a good idea to use mysql_* anymore as it's being depreciated.. Use mysqli_* etc..

phorce 131 Posting Whiz in Training Featured Poster

But, if you need to enter an ID.. why are you entering 323 over 0900527??

I don't understand what it is you're trying to do!

Here, try this:

<?php

    function _checkFileExists($url)
    {
        $headers = @get_headers($url);
        if($headers[0] == 'HTTP/1.1 404 Not Found') {
            return false;
        }else{
            return true;

        }

    }

    $url = "http://www3.uic.edu.ph/images/100x102/";
    $id = "0900527.jpg";

    $res = $url . $id;

    if(_checkFileExists($res))
      echo 'It exists';
    else
     echo 'Sorry, it does not exist';
?>
phorce 131 Posting Whiz in Training Featured Poster
if(file_exists($complete))
{
    // true
}else{

  // false
}

EDIT: It doesn't look like "http://www3.uic.edu.ph/images/100x102/232.jpg" exists, or, you do not have permission.. Is this your School/College by any chance, and works for you when you sign into the service?

phorce 131 Posting Whiz in Training Featured Poster

http://www3.uic.edu.ph/images/100x102/1242343.jpg

Doesn't exist, or, you do not have permissions to access it.

Please can you vardump / echo $complete...

Also, what does "file" do? :S

phorce 131 Posting Whiz in Training Featured Poster

Hey,

I don't think it is possible with Arrays (Someone correct me?) I've only ever seen/used counting the elements as they have been inserted.

Can you not use STL vectors?

phorce 131 Posting Whiz in Training Featured Poster

Your first problem is you delcare a constructor (in your .h file) but you don't reference it in the class functions (.cpp)... So put this:

Burger::Burger()
{

}

Your other problem is the fact you don't tell the compiler where the functions are (in which class) you declare an object of "yum" so use it..

double val1 = yum.hamburgerCalc(yum);
double val2 = yum.cheeseburgerCalc(yum);
double val3 = yum.dcheeseburgerCalc(yum);

I don't understand your code. You have a main, then more class functions.. I hope this isn't all in one file.

phorce 131 Posting Whiz in Training Featured Poster

Couldn't you just have a count set to = 0 at the beginning and each time a value get's inserted into the array, it increments by 1? Or, if you just need to know whether someone has entered something - Have a Boolean? Here's an example anyway:

#include <iostream>

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

    int numbers[8];
    int count = 0;

    for(int i=0; (i < 3); i++)
    {
        numbers[i] = i+i+2*i;
        count++;
    }

    cout << count; // prints "3" only 3 elements added to an 8 integer array

}