deceptikon 1,790 Code Sniper Team Colleague Featured Poster

p is a pointer to char, not int. So when you increment by 1, it increments by 1 byte instead of the number of bytes in an int. I think you should throw that book away if that program is a sample of its quality.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but my problem that i can move/manipulate the cursor left, right, down, up in the output screen.

I don't understand.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This game is an amusing diversion. Like Ali 2101 said, kbhit() is the easiest way to check for a key press in compilers that support it. You can also fake kbhit() with the Win32 API, but that's not necessary in this case.

Here's a sample game that does something similar:

#include <iostream>
#include <random>
#include <string>
#include <cctype>
#include <ctime>
#include <conio.h>
#include <windows.h>

using namespace std;

namespace 
{
    void SetPos(int x,int y)
    {
        COORD coord = {(SHORT)x, (SHORT)y};
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    
    void ShowAt(string const& s, int x, int y)
    {
        SetPos(x, y);
        cout << s << flush;
    }
    
    class GameChar
    {
    public:
        GameChar(char value, int x, int y): _value(value), _pos(x, y) {}
        
        int Value() const { return _value; }
        void Clear() const { cout << "\b "; }
        int Next() const {return _pos.Y + 1; }
        void Advance() { _pos.Y = Next(); }
        
        void Show() const
        {
            Clear();
            SetPos(_pos.X, _pos.Y);
            cout.put(_value);
        }
    private:
        struct ScreenCoord
        {
            ScreenCoord(int x, int y): X(x), Y(y) {}
            int X, Y;
        };
    
        char _value;
        ScreenCoord _pos;
    };
}

int main()
{
    string const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int const SPEED = 500;
    int const MAX_X = 40;
    int const MAX_Y = 10;
    
    mt19937 rgen((unsigned)time(nullptr));
    int answers[2] = {0};
    bool done = false;
    
    ShowAt("Match the letters before they hit the bottom:", 0, 0);
    ShowAt(string(MAX_X, '-'), 0, MAX_Y);
    
    while (!done)
    {
        GameChar ch(alphabet[rgen() % alphabet.size()], rgen() % MAX_X, 1);
        
        for (; ch.Show(), ch.Next() <= MAX_Y; ch.Advance(), Sleep(SPEED))
        {
            if (kbhit())
            {
                ++answers[toupper(getch()) == toupper(ch.Value())];
                break; …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so it means any kind of list i use, its iterator will return the pointer of the nodes of the list..

Not really. It means that iterators in C++, at least the ones following convention, are an abstraction of pointers. They overload operators in such a way that they have a subset of pointer operations depending on the type of iterator. All iterators have a dereference operator to access the "pointed to" object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is there is any other language which is safe from decompiling

Better question: Why are you worried about decompiling?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

One example: You may want the lifetime of the object to not be restricted to the scope in which it was declared. Dynamic memory has a lifetime of when you allocate it to when you release it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd guess that you forgot to dereference the iterator:

QString current = *it;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In C# you read an integer with

age=int.Parse(Console.ReadLine());

:P That should answer some more questions in case you have them. Was stuck at the same problem when i started with C#.

Good luck!

int.Parse() will throw an exception if the string is null or doesn't represent a valid integer. It's not safe to assume that Console.ReadLine() will return anything usable by int.Parse(). You could wrap the whole thing in a try..catch, but that's kind of a waste when TryParse() avoids any need for exception handling.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're focusing too much on the 'how'. Explain what the program does and someone can help make suggestions.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

std::vector and std::string do a lot of work internally. You'd probably be better off converting the 'what' instead of the 'how'. Ask yourself what the code is trying to accomplish and write C code to do it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Be aware that 2 digit dates *will* cause overlap between the 1900s and the 2000s, but if you have a hard lower bound on the 1900s, like 1970, you can check for that explicitly and be good until the same year in the 2000s:

// Works until 2070
if (year < 70)
    year += 2000;
else
    year += 1900;

There's not a good solution other than using 4 digit dates everywhere.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

An easy way to use variadic template functions is with direct recursion:

#include <iostream>

using namespace std;

void foo()
{
    // Base case for variadic recursion
}

template<typename T, typename... Args>
void foo(T first, const Args... remaining)
{
    // Use the first argument
    cout << first << endl;
    
    // Recursively pass on the remaining arguments
    foo(remaining...);
}

int main()
{
    cout.setf(ios::boolalpha); // To make bool args print right
    
    foo(1, "test", 3.14159, 'Q', true, 6);
}
triumphost commented: Doesn't work but thanks anyway Rep+1 +6
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But what is meant by "Reads at most maxlen characters from the stream".

If you give it a maxlen value, that's all it will read.
If you set the parameter to 10, it will read 10 characters from the stream.

It will read up to 10 characters, but never any more. If there are fewer than 10 characters in the stream then they'll all be read. That's what 'at most' means in this context.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In Turbo C you can use gotoxy(), and for the highlighting you'd probably use textcolor(). Read the documentation for further details about those two functions.


inb4 don't use Turbo C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What does the Qt documentation say?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
scanf("%lf", &hourWorked);

Now you have the opposite problem. hourWorked is an int, so you should use %d in scanf().

scanf("%f", &hourlyRate);

And here it should be %lf because hourlyRate is a double and not a float.

I posted working code before, and I'll do it again. Please read it carefully:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int hourWorked;
    double hourlyRate;
    double total;

    total = 0;

    double salary;


    printf( "Enter hour Worked: ");
    scanf("%d", &hourWorked);

    while (hourWorked != -1) {
        total = total + hourWorked;

        printf( "hourly Rate: " );
        scanf("%lf", &hourlyRate);

        salary = total * hourlyRate;
        printf( "The salary is %f\n\n", salary );

        // Initialize hour worked.
        printf( "Enter hour Worked: ");
        scanf("%d", &hourWorked);
    }

    system("PAUSE");
    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

just continue and review when necessary only???

If you remember something clearly, there's no need to review. It's only when forgetting something keeps you from understanding new material that you need to go back and review what you forgot.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

None of those are standard C++ functions. What library are you using to get them, or what compiler are you using if they're extended library functions?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
scanf("%d", &hourlyRate);

%d is for integer input. For double input use %lf.

printf( "Miles gallons  was %d\n\n", salary );

Just like scanf(), printf() expects you to tell the truth about what type of variable is being printed. salary is a double, but %d says that it's an int. That technically causes undefined behavior, and you want to use %f instead.

On a side note, scanf() and printf() format specifiers are not the same. %f works for float *and* double when it comes to printf(), but scanf() differentiates them with %f for float and %lf for double. So be careful. :)

I also noticed that you ask for the new hours worked too soon inside the loop. That should be moved to be the very last step:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int hourWorked;
    double hourlyRate;
    double total = 0;
    double salary;

    printf( "Enter hour Worked: ");
    scanf("%d", &hourWorked);

    while (hourWorked != -1) {
        total = total + hourWorked;

        printf( "hourly Rate: " );
        scanf("%lf", &hourlyRate);
        
        salary = total * hourlyRate;
        printf( "Miles gallons was %f\n\n", salary );

        printf( "Enter hour Worked: ");
        scanf("%d", &hourWorked);
    }
    
    system("PAUSE");
    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd say continue where you left off, and review previous chapters as necessary.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's not possible without writing your own preprocessor that adds appropriate escape characters for the stringizing operator.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Every time I run my program, and enter a character, my program prints the correct output (for example if I enter 'n' the first time, my program outputs "you've deposited 5 cents"), but then it also outputs the default message every time ("Whoops you've entered the wrong command, please try again."). Why is it printing this?

Look very closely at what keys you press when you enter a character. Say it's 'n' the first time. Don't you also hit the enter key? That's the character your program is reading the second time.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Replace var with whatever type name you're assigning to the variable. var row in source.Rows would become DataGridViewRow row in source.Rows . You'd know that if you actually read some of the links from that search instead of just determining that var wasn't supported on your older compiler.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

age is never set to anything other than 0. What you probably wanted was something more like this:

int age;

Console.Write("Please enter your age: ");

if (int.TryParse(Console.ReadLine(), out age))
{
    if (age >= 65)
    {
        Console.WriteLine("You are entitled to discount");
        Console.ReadKey(true);
    }
    else
    {
        Console.WriteLine("You are not entitled to discount");
        Console.ReadKey(true);
    }
}
else
{
    Console.WriteLine("Invalid age");
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

They're both mid level languages.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Perhaps consider something more like this:

string GridToXml(DataGridView source, string root, string element)
{
    var doc = new XmlDocument();

    doc.LoadXml("<" + root + " />");

    foreach (var row in source.Rows)
    {
        var element = doc.CreateElement(element);

        foreach (var cell in row.Cells)
        {
            element.AppendChild(doc.CreateElement(cell.OwningColumn.HeaderText));
            element.LastChild.InnerText = cell.FormattedValue;
        }

        doc.Firstchild.AppendChild(element);
    }

    return doc.OuterXml;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

and how does user signals EOF (sorry a newbie!...)?
I suppose by pressing Ctrl+c or forcibly ending the program.
Please correct in case i am wrong.

It depends on the operating system, but Windows uses ctrl+z and Linux/Unix-based OSes use ctrl+d. Those two are the most common; let me know if you're not using either of them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It will go on forever unless the user signals EOF or there's a stream error of some sort.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have been trying to take input until empty string is entered(simply press enter) ?

The >> operator doesn't recognize whitespace except as a delimiter on both sides. If you just press enter, it's ignored while the >> operator waits for non-whitespace. To check for a blank line you would use getline():

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string buff;
    
    while (getline(cin, buff) && !buff.empty())
    {
        cout << "'" << buff << "'" << endl;
    }
}

But that doesn't have the same behavior as the >> operator if you want to read words instead of lines. What kind of behavior do you want for user input?

The extraction operator returns a reference to the stream, not a boolean value.

But the stream object has a conversion to boolean when in boolean context. Prior to C++11 the conversion was to void* and then to boolean from there, and in C++11 there's a direct conversion to bool.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The questions you've asked are the purpose of the "How would you test a toaster" interview question:

  • Can you think logically through the requirements for the toaster?
  • Can you devise testing steps that put the requirements through their paces?
  • Can you think of plausible edge cases that weren't considered in the design?
  • What standard QA processes would you use to handle all of this?
  • Are you consistent and thorough throughout the entire process?

These things are what interviewers are looking for, not so much the resulting test plan that you might produce in practice.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think the calculations are too complicated. Try this:

// Get the total months for full years worked
tm = (eyear - syear) * 12;

// Remove months not worked from the first year
tm -= (smnt - 1);

// Add months worked from the last year
tm += emnt;
    
cout << " years " << (tm / 12) << " months " << (tm % 12) << endl;

There are a number of ways to handle the odd months, the above assumes that the edge months are inclusive. So if the starting date was 1-31-2003 and the ending date was 12-1-2003, it would still come out to a full year of employment. To get more precise you would need to include days, or make an assumption about how many days are worked in those two months.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This Daniweb tutorial explains what is happening and how to fix it: "Flushing" the input stream

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Show me your attempt and I'll show you mine.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think the "forum index link" isn't such a but idea but after reading deceptikon's post it seems it would be a lot of work for Dani to make it possible
though Dani is currently working on Daniweb's new version so I think it's better if we hear it from her of what she thinks about this

Actually, that change will border on the trivial when the new system is released, at least as far as the code itself goes. But I'm told there was a lot of research into the design of the site, and I'm not privy to the details.

I like to be able to see every category and which category has unread posts.

I have a few thoughts:

  1. We could show the read status of a category from the category menus at the top of each page.
  2. We could change the New Posts button on the purple bar into a menu filtered by forum.
  3. We could leave the New Posts button a straight up button, but add filtering by forum to the results.

Viewing the read status from places other than a forum view or the forum index is a good idea as long as it doesn't increase loading time excessively.

I can also mark the whole forum read from that page.

You can mark a whole forum read from the forum view, but the link is at the bottom of the page. Off the top of my head I …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It took a surprising amount of work to get Dani to put that tiny forum index link at the bottom of every page, so I'll ask what she'll probably ask. Why do you need to get to the index so badly that there has to be an immediate link from every part of every page?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

did I miss something here??

There are too many variables named t. There's the global t and the local t in main()'s loop. It's recommended not to use the same name more than once for nested scopes. It's very easy to get confused.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is it possible that multiple instances of a function can exist?

Yes:

fact(5);
fact(5);

Those are two instances. It would help to learn how function calls are typically handled if you don't know already. Knowing about the call stack helps to differentiate between definition of a function and execution of it at run time.

It basically keeps calling the method until n is equal to 1 as we have set the IF condition and then it reverse evaluates the factorials until it reaches the factorial of 4 and then finally multiply it by 5 in order to give 120.

Well, I can't say that's wrong. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The way I see things, constantly calling fact(n - 1) when the method tries to return will result in an infinite amount of times the method being called without returning anything.

Each call invokes a new instance of the function with new arguments. The effect is as if you did this:

int fact1()
{
    return 1;
}

int fact2()
{
    return fact1() * 2;
}

int fact3()
{
    return fact2() * 3;
}

int fact4()
{
    return fact3() * 4;
}

int fact()
{
    return fact4() * 5;
}

Recursion just makes the syntax for that process simpler.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but if I don't use stdafx. vs would give me a precompiled header error.

You can turn off precompiled headers in the project settings.

it is a win32 console project..

Anything except an empty project will add Microsoftisms. When you're trying to write portable code, I'd recommend starting with an empty project.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

eq->pt_tree[row][col] = value; is equivalent to *(eq->pt_tree[row] + col) = value; .

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so, are there another function(beside coutt) inside std?

Everything in the standard C++ library is wrapped inside the std namespace.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

(*eq->pt_tree[0]) = 2; .

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Try --(*eq->pt_tree[c]); .

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Only Dani can undo reputation, to the best of my knowledge, as it's not built into the vBulletin interface even for community admins. However, you can negate it by waiting until tomorrow and then applying positive rep to another post. It's not perfect, but at least that would make the net effect on his reputation points zero.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
istream& my_getline(istream& is, string& s)
{
    istream& result = getline(is, s);

    if (!result.eof())
    {
        s.push_back('\n');
    }

    return result;
}

Presto magico!

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is there any other function that would including the end line character?

istream& my_getline(istream& is, string& s)
{
    istream& result = getline(is, s);

    s.push_back('\n');

    return result;
}

Presto!

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What do you mean by "work in docs"?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Depending on the topic of your threads, I'd say one of the Microsoft Windows sub-forums or Web Development sub-forums would be the best fit as it stands now.

Adding a forum isn't technically a huge deal, but there needs to be sufficient demand first. Otherwise we'd end up with the eyesore of a low activity forum on a site that already has an overwhelmingly large number of forums.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
template<typename T>
Point<T> Point<T>::plus(Point<T> operand2) {
	Point temp;
	temp.set_x(get_x() + operand2.get_x());
	temp.set_y(get_y() + operand2.get_y());
	return temp;
}