deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm hesitant to help you now that I know your intention for learning assembly is hacking.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sorry, we don't allow discussion of hacking on Daniweb.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't know whether that is the correct count.

Unfortunately, I don't have direct access into the production database to query those records. However, if the count changed from being wrong to being (supposedly) correct, it may just be a delayed display issue. Perhaps the cache isn't being updated as quickly as it should.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i.e.,if it was 0 and person downvoted and then undo downvoted then net vote recied for a post is showing 0 that is correct but the post is displayed in down voted section.

I'm not sure I understand the problem. Are you seeing a post with 0 in your posts voted down page? Can you link to a specific post that has the problem?

And also activity is increased.

That's by design.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

define('DB_NAME', 'lol);

Count the single quotes in that line.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

PS. I like your Avatar.

Thanks. I like the paradox of Derpy and logic.

Are you a student of Aristotle?

Not directly, he died shortly before I could ask for any classes. ;) If you want to be technical about it, anyone who's had any exposure to western philosophy at all is a student of Aristotle as he's one of the founders of that school of thought.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not advocating for an obsessive compulsion to declare variables at the narrowest scope that is humanly possible, as you seem to imply that I do.

That's what I inferred from your example, which is what I believe to be excessive localization of declarations:

cout << "enter a" << endl;
float a = 0.0;
cin >> a;

cout << "enter b" << endl;
float b = 0.0;
cin >> b;

cout << "enter c" << endl;
float c = 0.0;
cin >> c;

The reason I brought it up is because you were offerring it as a superior example to a beginner, who might take that kind of thing to heart and go overboard with it. So I felt a tempering perspective was warranted.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Based on your code, how do I store it in prog based on my code?

Honestly, I don't think you're ready for the headache of managing dynamic memory. That's why my example used an array rather than a pointer. And since this is school work, it's unlikely that you won't be able to get away with an array that's "big enough" for any reasonable test data.

On a side note, this is really bothering me:

/* character or EOF flag from input */
int *ch;

Remove the asterisk, you shouldn't be using a pointer here.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

At its simplest you'd have something like this just to store the characters:

#include <stdio.h>

#define EXPR_MAX 255

int main(void)
{
    FILE *in = fopen("c:\\test1.txt", "r");

    if (in) {
        char expr[EXPR_MAX];
        size_t n = 0;
        int ch;

        while ((ch = getc(in)) != EOF) {
            expr[n++] = (char)ch;
        }

        fclose(in);

        /* Now n characters are stored in expr and can be processed in memory */
    }

    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And if you want to debate the issue, take it up with Herb Sutter, Andrei Alexandrescu and Bjarne Stroustrup.

This reeks of appeal to authority; if you have an argument to make, make it. I've already read anything you're likely to be thinking of from those authors, and it didn't change my mind.

I don't disagree that declaring variables reasonably close to the beginning of their logical lifetime is a good idea. I do disagree that variables should always be declared immediately before their first use, which is what it seems like you're advocating. The former when used judiciously can greatly enhance code clarity compared to always declaring variables at the top of the function (the other extreme, which I'll mention again I'm not advocating), but the latter can make code harder to read and understand by forcing you to switch between declaration and execution mindsets.

Let's take your replacement for the original code and reorganize a few declarations to make it read better (in my opinion). There are three general chunks of related code: the input of operands, the calculation, and output of the result: Untitled38
It's obvious that a, b, c are related, so lumping them together makes more sense than interspersing them between the input statements. Technically they can be viewed as having a lifetime of the entire function, and therefore it makes sense to put them at the top.

The calculation is a separate logical unit, but still uses …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

First you need to add a template parameter list to all of your classes and functions. Then you need to make sure that all uses of vector and deque include template arguments. After that you need to replace all instances of int as your stored data type to the template parameter. Finally, because these functions are now templates, you will want to merge the .h and .cpp files for each class into just a single .h file.

This is how vector.h would look after doing all of those things:

// vector.h
#ifndef VECTOR_H
#define VECTOR_H

template <typename T>
class vector
{
private:
    T *data;
    int vSize;
    int capacity;
    void overflow(); // handle overflow situation

public:
    vector(int s);
    T elementAtRank(int r);
    void insertAtRank(int r, T newData);
    void removeAtRank(int r);
    void replaceAtRank(int r, T newData);
    int size();
    bool isEmpty();
    ~vector();
    void print();
};

template <typename T>
vector<T>::vector(int s)
{
    data = new T[s];
    capacity=s;
    vSize=0;
}

template <typename T>
vector<T>::~vector()
{
    delete data;
}

template <typename T>
T vector<T>::elementAtRank(int r)
{
    if(r>=capacity || r<0)  // protect data from overflow
        return T();
    return data[r];
}

template <typename T>
int vector<T>::size()
{
    return vSize;
}

template <typename T>
bool vector<T>::isEmpty()
{
    return (size()==0);
}

template <typename T>
void vector<T>::replaceAtRank(int r, T newData)
{
    if(r>=capacity || r<0)
        return;
    data[r]=newData;
}

template <typename T>
void vector<T>::removeAtRank(int r)
{
    if(r>=capacity || r<0 || isEmpty())
        return;
    for(int i=r; i<vSize; i++)  // shift every element to its left
        data[i]=data[i+1];
    vSize--;
}

template <typename T>
void vector<T>::overflow()
{
    capacity*=2; …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since you hash define NUM_ITEMS, you don't really need to pass it to functions.

What if the caller wants to use something other than NUM_ITEMS without redefining it? Passing the size provides greater flexibility, and just because you can do something doesn't mean you should. You can use NUM_ITEMS all over creation, but that doesn't mean it's a good idea.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So...is your question how to turn these classes into templates?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Ignoring variations of the following, you can initialize it manually member-by-member, copy it from an existing object, use an initializer list, or define a constructor.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What are you trying to accomplish? The answer to that is what determines how you initialize your structure.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Using the initializer list you can take advantage of initialization rules:

#include <iostream>

using namespace std;

struct a {
    double id;
    int tag;
    char array[10];
};

int main()
{
    a var1 = {100, 1, "The City"};
    a var2 = var1;

    cout << "var2.id = " << var2.id << endl;
    cout << "var2.tag = " << var2.tag << endl;
    cout << "var2.array = " << var2.array << endl;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You should use <iostream> and <cmath> (all C++ standard headers don't have the .h, and all those taken from C (like math.h, stdlib.h, stdio.h, etc.) also omit the .h and are prefixed with the letter c).

It's also important to remember that some compilers (Microsoft's in particular) "helpfully" don't require std qualification on a large portion of the C library. But if you rely on that your code will not be portable and will fail to compile on other compilers without a using directive. But a using directive isn't generally considered to be a good practice with new code because it defeats the purpose of namespaces.

The return value should be 0 if the program executed correctly, and something else otherwise.

The final nail in the coffin for void main() was standard C++'s feature that allows you to omit the return statement and a return value of 0 will be assumed. This only works for the main() function, but it means you can do this:

int main()
{
}

And the code is perfectly legal and portable across the board. It even saves you a keystroke over void main(), so there are no excuses anymore.

You should declare your variables as close as possible to where you first use them

That's debatable. I understand the intention, but if a function is large enough that declaring variables at the top of each scope can be described as error prone, you should probably do …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But can you tell me why in the definition of f1 (in your code) p's address has not been passed and still it's passed by reference?

The entire point of using another level of indirection is so that you can access the original object. If you already have that level of indirection in place, there's no need for another. In other words, if the object you have is already a pointer to the object you want, you don't need to pass any addresses.

On a side note, what you're doing is not pass by reference, it's passing a pointer to simulate the effect of pass by reference.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm sorry, I'm unable (translation: unwilling) to decipher your txt speak. Please use real words.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My comment was in general, not directed at anyone in this thread. Though there are certainly many levels of craziness when it comes to preference. Some people are more reasonable, and others are irrationally stubborn.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, it is possible but it is not recommended.

Why?

It is better to have dynamically allocated array in this case.

Again, why? Please assume that the compiler supports C99, since the obvious "it's not portable" prior to C99 is obvious.

int *array = malloc(i*sizeof(int)); // alloc enough memory for the array

A cleaner way to do this without listing the type twice is by using a quirk of the sizeof operator:

int *array = malloc(i * sizeof *array);

Because sizeof doesn't evaluate the expression given as an operand, you're not dereferencing the (at this point) uninitialized pointer. It's not so big of a deal in cases where you're declaring and allocating all in one statement, but consider cases where the type changes and you do the allocation elsewhere. Then you'd need to grep the code looking for any instance of sizeof(int) in reference to that variable and change the type.

free array;

free() is a function:

free(array);
tux4life commented: Nice tip about sizeof ;) +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Assuming the time part of your date is consistent (such as midnight), it's a simple check against getdate():

"select * from usernames where [Username] = '" & TextBox2.Text & "' and [Password] = '" & TextBox1.Text & "' and [ExpiresOn] >= getdate()"

You might also consider using parameterized queries instead of string concatenation for security reasons (and to make the query easier to read).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So you're supposed to do this project, but you're asking for someone to send it to you? I'm sorry, but that sounds a lot like you're asking others to do your project for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's both funny and sad the kind of ire people can have over an operating system debate.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon I had responsiveness issues on my S3. Turns out it was due to Samsung's crappy TouchWiz interface. If you flash it with a basic Android ROM it's snappy as hell :) (Bit like Laptops you buy form superstores that come bogged down with all their branded crap)

My responsiveness issues relative to iOS have been with straight Android, as recent as ICS. So while you're certainly right that manufacturers (Samsung especially) have been egregious with their crapware, that's not always the answer when someone mentions UI lag.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Obfuscation is quite a common practice, especially in .net where disassembly of libraries is incredibly easy.

Obfuscation only deters a casual reader. Anyone who's seriously interested in the code will have only a little more difficulty figuring it out from an obfuscated disassembly. Further, no professional in their right mind would manually obfuscate code rather than take advantage of a tool.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

According to the manual WriteLine() returns void, you can't assign that to answer[i].

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How would you do it on paper? The first task is to understand the problem and solve it manually, step by step. Then you'll be in a better position to translate those steps into C++.

ddanbe commented: The way to answer! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but you learn by understanding the old ones before diving into the new ones, right?

Not really. Outdated syntax is of historical interest, but if you want to learn how to program in a language, you should learn the latest version of the language.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We're working on it, no worries.

tux4life commented: Like a boss! :D Wise words in the signature too ;) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Pointers are built-in types, they don't have constructors per se. If you want your ppointers to be null, make them null explicitly.

student *head = 0;
student *tail = 0;

Assuming those pointers are members of another class then you can certainly use the default constructor to make them null.:

class foo {
public:
    foo(): head(0), tail(0) {}
private:
    student *head, *tail;
};
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I prefer the iOS experience. Android has responsiveness issues whenever I use it, and that slight delay seriously affects the experience. Responsiveness issues seem few and far between on iOS.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It was an independent forum and Daniweb acquired it a few years ago. So PFO became a (neglected) sister site to Daniweb.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not so stereotypical as to conform to a label. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i dont know how to go about it

Please read this thread. It's about C#, but the general message is very relevant.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

continue is a keyword in C++. Use a different name.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's not as much a matter of being an Excel expert as it is whether you want to accomplish this from the Excel UI itself or with a third party program. Since this question is in the computer science forum, I'm unable to determine if you're writing custom software to accomplish this (in which case it should go in the appropriate programming language forum) or need Excel scripting advice (where it would best be moved to the Hardware & Software forum).

As far as doing it from Excel's scripting options, it's a relatively simple matter of looping over the desired row and clearing a cell if it compares equal to another. For example:

Sub ClearCells()
    Dim i As Double

    With Sheets("Sheet1")
        For i = 1 To 10
            If .Cells(i, "A").Value = .Cells(i, "B").Value Then
                .Cells(i, "B").Clear
            End If
        Next
    End With
End Sub

This will clear cells in the B column if they're equal to the A column for the first 10 rows in the first worksheet.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Keep a running sum of the numbers, that way you can keep a single variable for the currently entered number and reuse it in a loop.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I assume you're asking about the ternary operator. This:

'left': (direction === 0) ? '-100%' : '100%'

Is roughly equivalent to this:

if (direction === 0) {
    'left': '-100%';
}
else {
    'left': '100%';
}

So it's just a expressionized version of an if..else statement.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

_getcwd() is a win32 api function. Not sure the replacement for *nix

getcwd() in <unistd.h>. ;) For processing the contents of a directory, you'd probably end up using opendir(), readdir(), and closedir():

DIR *dir = opendir(".");

if (dir) {
    struct dirent *info;

    while ((info = readdir(dir))) {
        cout << info->d_name << '\n';
    }

    closedir(dir);
}

The Windows equivalent would use FindFirstFile(), FindNextFile(), and FindClose():

WIN32_FIND_DATA info;
HANDLE h = FindFirstFile(".", &info);

if (h != INVALID_HANDLE_VALUE) {
    do {
        cout << info.cFileName << '\n';
    } while (FindNextFile(h, &info));

    FindClose(h);
}

That information could be gleaned from AD's links, but the above boils it down to the core operations.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I would appreciate it if someone can put more detailed comments in this source code to help me better understand it.

Sorry, but no. There won't always be someone around who's both capable and willing to read, understand, and recomment large amounts of code just to make things easier on you. Further, the comments a lot of us would put in probably wouldn't help you any more than the comments already there. Just work through the code bit by bit until you understand it better.

If you have specific questions about a small part of the code, then feel free to ask about it. But asking others to go through a significant amount of effort because you don't want to properly work through the code yourself is very inconsiderate.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Try removing the semicolon.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Manually? With Excel scripting? Using third party code using an Excel library? Your question is specific as far as what you want to happen, but vague in terms of how you're looking to accomplish it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what is the PFO page...?

http://www.programmingforums.org/

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Handle the form closing event.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Of the listed languages, Perl is the closest to C/C++. Python and Lua are syntactically in different families.

By the way, if by "hacking" you mean breaking into systems and such, please note that Daniweb does not allow that kind of discussion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start by listing the features you want to support, as those will tend to dictate your implementation more than anything.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here's a simple example:

#include <iostream>

class foo {
public:
    virtual void action() const { std::cout << "foo\n"; }
};

class bar: public foo {
public:
    virtual void action() const { std::cout << "bar\n"; }
};

class baz: public foo {
public:
    virtual void action() const { std::cout << "baz\n"; }
};

void do_action(const foo& obj)
{
    obj.action();
}

int main()
{
    do_action(foo());
    do_action(bar());
    do_action(baz());
}

The magic is in do_action(). It doesn't care what object in the inheritance hierarchy it's given as long as that object provides the correct interface (ie. it inherits or overrides action()). This means that you don't need to have three different overloads of do_action() that a foo, a bar, and a baz, respectively. It all just works with a reference to foo through virtual functions and dynamic binding.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Everything must be declared before it's used. A function prototype is the function signature without a body and terminated by a semicolon:

#include<conio.h>
#include<stdio.h>
#include<math.h>

int input_data1(void);
void display(void);

void main(void)
{
    input_data1();
}

int input_data1(void)
{
    int input;
    printf("\n\n**************CPU Scheduling*************\n");
    printf("|\tChoose CPU Scheduling:\t\t|\n|\t1. Shortest Job Next\t\t|\n|\t2. First Come First Serve\t|\n|\t3. Round Robin\t\t\t|\n|\t4. All CPU Scheduling.\t\t|\n*****************************************\n");
    scanf("%d",&input);
    return input;
}

void display(void)
{
    input_data1();
}

Alternatively, you could define your functions prior to their first use. A definition also constitutes a declaration:

#include<conio.h>
#include<stdio.h>
#include<math.h>

int input_data1(void)
{
    int input;
    printf("\n\n**************CPU Scheduling*************\n");
    printf("|\tChoose CPU Scheduling:\t\t|\n|\t1. Shortest Job Next\t\t|\n|\t2. First Come First Serve\t|\n|\t3. Round Robin\t\t\t|\n|\t4. All CPU Scheduling.\t\t|\n*****************************************\n");
    scanf("%d",&input);
    return input;
}

void display(void)
{
    input_data1();
}

void main(void)
{
    input_data1();
}