deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start by printing a block of x's:

for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 15; j++) {
        cout.put('x');
    }

    cout.put('\n');
}

From there you can play around with ideas on how to identify the corner blocks and instead of printing an x, print a space. The real benefit of this exercise is that part, so I don't want to reveal too much as that would defeat the purpose.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Oftentimes we'll even catch and handle such things before even seeing the report. That happens for me, if it even gets reported before we catch it. ;) That said, if you ever see spam or rule violations, please don't hesitate to report them with the flag bad post feature.

That thread survived almost an hour, which is a rarity with our stellar mod team.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Two issues:

  1. You never populate x and y. You need to input those values using cin.
  2. The = operator is for assignment. When comparing values, use the == operator.

Compare and contrast:

#include <iostream>

using namespace std;

int main()
{
    int x;
    int y;

    cout << "Enter an integer number : ";
    cin >> x;

    cout << "Enter an integer number : ";
    cin >> y;

    if ((x<7 && x>-2)&&(y == 5 || y == 10))
    {
        cout << "within range" << endl;
    }

    if (!(x<7 && x>-2)&&(y == 5 || y == 10))
    {
        cout << "out of range" << endl;
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Help yes, do it for you no. Please show some proof that you've made an honest attempt to do this homework problem on your own.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You didn't point out exactly where you're talking about in that document, but I'm guessing you mean the template functions. If a parameter in a template function uses one of the template type parameters, calls to that function will deduce the type of the template parameter based on the type of the argument:

template <typename T>
void foo(T arg)
{
    cout << arg << '\n';
}

int main()
{
    foo(123);     // T deduced as int
    foo(123.456); // T deduced as double
}

This doesn't work for template classes because there's nothing to deduce. Of course, if you're okay with using a strict template type parameter, you could use typedef or a C++11 alias:

typedef test<string> test_t;

test_t a("hello");
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The best tree algorithm depends on what you want to do. So...what do you want to do? :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's on the list. IIRC it's kind of tricky to calculate the size of the hover area and scroll accordingly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If that's the goal, you might consider simply removing all commas from the string rather than trying to parse and validate it as a double. Then you can use strtod to do the validation and conversion.

kay19 commented: For helping/tips +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The closest you can get without using the preprocessor is providing a default type:

template <typename a = string>
class test
...

test<> a("hello");
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd wager that the ultimate goal is to extract a double from the string, but I'll defer to the OP to confirm my assumption.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Still doesn't explain how you get a crazy looking string like 2,43,,111.11 from 243,111.11. Why so many commas??

He's not conditionally ignoring commas and always treating them as digits. The distance calculation is also off due to including commas in it rather than just digits, so commas are misplaced.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sounds like you just want to pad to 2 digits with 0 as the pad character:

cout << setw(2) << setfill('0') << hour
     << ':'
     << setw(2) << setfill('0') << minute;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do I have to create additional for loops statements for each digits and check for comma's/decimal?

If you want to do it manually, yes. However, input streams already support this feature by imbuing the stream with a locale that can recognize a thousands separator. The default "C" locale won't, but if you use the current locale (represented by a name with an empty string), you can read numbers using your system's locale settings:

#include <iostream>
#include <locale>
#include <sstream>
#include <stdexcept>
#include <string>
#include <typeinfo>

using namespace std;

template <typename T>
T parse_formatted(const string& s, locale loc)
{
    stringstream parser(s);
    T result;

    // Set input formatting to the specified locale
    parser.imbue(loc);

    // Attempt to extract a value
    if (!(parser >> result)) {
        throw std::invalid_argument("Unrecognized format for " + string(typeid(T).name()));
    }

    return result;
}

int main() try
{
    string line;

    if (getline(cin, line)) {
        // Parse values using the current system locale
        double value = parse_formatted<double>(line, locale(""));

        cout << "Raw: " << fixed << value << '\n';
    }
}
catch (std::exception& ex) {
    cerr << ex.what() << '\n';
}
Begginnerdev commented: Nice example +9
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but as you should understand already, this is a rather undocumented section of programming

Actually, it's very well documented if you know what to look for. Specifically, when directly writing machine code you need to do two things:

  1. Understand and create the formatting of PE (Portable Executable) files. This will be the boilerplate that allows Windows to execute your code.

  2. Understand the opcodes that correspond to an assembly language of your choice for the CPU architecture. Using a hex editor you can insert those opcodes manually (ie. "program" in machine code) just as an assembler would.

Alternatively, you could read the source code for an assembler to see how it parses and assembles things, since programming in machine code is tantamount to replacing the assembler with your own brain and fingers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Keep sharing these type of things.

I have a bunch of things like this that are hard earned through experience. I was thinking either a series of posts or tutorials each covering one specific topic in detail where the topic is the kind of thing you'd typically learn through painful experience or from talking to experienced programmers.

nitin1 commented: please share those things. excited to know those things +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If comboBox2 is tied to comboBox1 without binding, you'd need to programmatically select the new value in comboBox1 when comboBox2 changes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can set SelectedIndex, if that's what you're asking.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes. What code do you have so far? Please note that nobody will do this for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And, we aren't tricked that easily either.

A good thing to mention. A lot of us have been posting to forums like this for many years. We've seen a lot of good tricks and even more bad tricks. For the most part, we can tell the difference between an honest person looking to learn and a leech looking for freebies.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Should I loop through tiles and delete each one? Or is there a better way?

Yes, and. :) With your current setup, you have little choice but to loop through the vector and delete each pointer. However, a better setup would be to use smart pointers (shared_ptr or unique_ptr) from the get go.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here's an example that may help. Note that it's not a complete solution to your problem, just a similar example:

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

int draw_card()
{
    return 1 + rand() % 100; // [1,100]
}

int main(void)
{
    int wins = 0, losses = 0;

    srand((unsigned)time(NULL));

    // Game loop: plays infinite rounds of HiLo
    while (1) {
        int card = draw_card();
        int guess;

        fputs("High(1) or Low(2)? ", stdout);
        fflush(stdout);

        // Get a sanitized guess
        while (scanf(" %d", &guess) != 1 || (guess != 1 && guess != 2)) {
            puts("Invalid option");
        }

        // Clear extraneous characters from the stream
        while (getchar() != '\n');

        // Check the guess, notify, and update stats
        if (guess == 1) {
            if (card >= draw_card()) {
                puts("You win!");
                ++wins;
            }
            else {
                puts("You lose");
                ++losses;
            }
        }
        else {
            if (card < draw_card()) {
                puts("You win!");
                ++wins;
            }
            else {
                puts("You lose");
                ++losses;
            }
        }

        // Give the user the option to quit
        fputs("Play another round? (y/n): ", stdout);
        fflush(stdout);

        if (tolower(getchar()) != 'y') {
            break;
        }
    }

    printf("Final Score: wins(%d) losses(%d)\n", wins, losses);

    return 0;
}
Pashan commented: you are awesome! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Dev-C++ is no longer under active development. If you want a simpler interface than Visual Studio, Code::Blocks and CodeLite are both excellent choices. They also both use the MinGW library just like Dev-C++.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In India, schools have unfortunately standardized around Turbo C/C++.

It's an unfortunate reality that we have to deal with constantly. The result is that C++ programmers graduating from Indian schools are woefully under-skilled due to reliance on outdated tools. C++ has evolved significantly since Turbo C++.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Break down the requirements into manageable chunks. I'd do it like this:

  1. Play a single round of HiLo with numbers from 1 to 100.
  2. Modify the program to play infinite rounds.
  3. Modify the program to keep score or wins and losses.
  4. Modify the program to let the user stop after each round.
  5. Modify the program to use "cards" instead of a simple number range. Reshuffle the deck on each round.
  6. Modify the program to use a full deck before reshuffling.
  7. Profit!

This incremental approach keeps things simple as you only have to worry about a subset of the requirements at any given time. Further, when adding new requirements, you already have a fully working program to build upon.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A common task in C or C++ is to get a string from somewhere and convert it to an integer. "Use atoi" is a common suggestion from the unwashed masses, and on the surface it works like a charm:

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

long long square(int value)
{
    return value * value;
}

long long cube(int value)
{
    return value * square(value);
}

int main(void)
{
    char buf[BUFSIZ];

    fputs("Enter an integer: ", stdout);
    fflush(stdout);

    if (fgets(buf, sizeof buf, stdin) != NULL) {
        int value = atoi(buf);

        printf("%d\t%lld\t%lld\n", value, square(value), cube(value));
    }

    return 0;
}

"So what's the problem?", you might ask. The problem is that this code is subtly broken. atoi makes two very big assumptions indeed:

  1. The string represents an integer.
  2. The integer can fit in an int.

If the string does not represent an integer at all, atoi will return 0. Yes, that's right. If atoi cannot perform a conversion, it will return a valid result. Which means that if atoi ever returns 0, you have no idea whether it was because the string is actually "0", or the string was invalid. That's about as robust as a library can get...not!

If the string does represent an integer but the integer fails to fit in the range of int, atoi silently invokes undefined behavior. No warning, no error, no recovery. Do not collect $200 and go straight to jail, your program is completely undefined from that point forward.

By the way, don't expect any support …

Ancient Dragon commented: excellent +14
nitin1 commented: hey! you and your way of explaining things is out of the world. excellent!! +3
ddanbe commented: Deep knowledge! +15
mike_2000_17 commented: Interesting! +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Those that have broader ideas and need detailed and solid information will always use forums.

Will they still use forums if none of the good forums can fund themselves well enough to stay up?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If he's 18 then you probably cannot covertly monitor the computer without his permission. Check the laws in your area to confirm this.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's a strong chance that what you want to do is illegal. How old is your child? Do you own the computer?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have some seriouos gamer friends at work (we are a tech company w/ very savvy users) and they won't get AMD video gear simply because they don't perform as well as nVidia cards.

It's very much dependent on the game. Some games run better on AMD, some on nVidia, and even then the difference isn't huge. I think your friends have an irrational bias, or only play games where nVidia benchmarks better. ;)

I'm not partial either way, but I've had good results with AMD in the past, and that's why this build uses Radeon cards.

For serious gaming gear, don't go for less than 1000 watts!

When the draw will probably be less than 800W even after overclocking? Seems like overkill to me.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yeah well nobody has bothered to reply and I guess someone has send you to comment on this as no one has even bothered to reply...!!!

I merely noticed that you bumped all of your questions as I was perusing the forum.

One side you're saying 6 days is a long time and on the other you said that I'm nagging for replies because I was not getting them fast enough (Are you even sure about what you are saying ???)

Quite sure. 6 days is a long time on an active forum, which means if you haven't gotten a reply in that time, chances are good nobody knows the answer or wants to reply. I fail to see how this is difficult to understand.

I never said that Daniweb offers any guarantee (3 years is a long time to understand that)

Your behavior suggests that you feel entitled to answers. Is it unreasonable for me to mention that Daniweb makes no guarantee?

So, is this the way we all should go over this community meant for supporting people in the areas where they've got their expertise and you would tend towards no longer expecting an answer ???

It seems that your anger is getting in the way of rational thought. You posted a question to a group of volunteers. Nobody volunteered to answer. Now you're getting pissed off when I suggest that you shouldn't expect an answer and to consider alternatives.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You already asked for help. Either nobody knows the answer or nobody who knows the answer has bothered to reply. Nagging for replies because you're not getting them fast enough is more likely to be counterproductive.

Daniweb offers no guarantee of help, so if you're not getting the help you need, I'd suggest looking for alternatives. 6 days is a very long time on an active forum like this one, so I'd tend toward no longer expecting an answer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Any replies ???

Clearly not. :rolleyes: Please don't bump your posts, it's rude.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

while you sit idely in your parents basement on the computer all day judging peoples lives keep in mind the rest of us have real jobs and real concerns to worry about and we work long hours and barely make ends meet so don't ever assume you know what were going through you dont know what we've been through plain and simple

In your rage post, I think you may have missed the glaring contradictions. You tell us not to assume stuff about you while you do exactly the same thing in the same sentence. Somehow that doesn't encourage me to respect your opinion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Read long integers as strings and store the digits of the number in the vector in reverse order.

Then straight C++ won't be enough. The 32-bit limit on long and even 64-bit limit on long long may not be sufficient to store the final value. You need something like GMP or Boost.Multiprecision to extend that limit indefinitely.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Flute.

nitin1 commented: you have told me long time back :D +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

your first line's got a error,

I also explicitly stated C++11, which you clearly aren't using. :rolleyes: Prior to C++11 it's not as simple, but still doable:

vector<string> v;
long result = 0;

v.push_back("123456789");
v.push_back("12345");

for (vector<string>::iterator it = v.begin(); it != v.end(); ++it) {
    string x = *it;

    reverse(x.begin(), x.end());

    stringstream ss(x);
    long temp;

    ss >> temp;
    result += temp;
}

long long was added in C++11, so now you really need to be careful not to overflow long or use a big number library to avoid overflow.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

With C++11 it's super trivial:

vector<string> v{ "123456789", "12345" };
long long result = 0;

for (auto x : v) {
    reverse(begin(x), end(x));
    result += stoll(x);
}

Of course, you do need to take into consideration whether the summed values will fit in the result. You may want to consider a big number library that allows arbitrary integer lengths.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when is a destructor of a class called?

When the object goes out of scope or a pointer to the object is deleted.

I'm assuming that when I pop a vector, that will make the pointer no longer valid, is this where the destructor gets called?

Yes, assuming that the object stored in the vector is an object and not a pointer to an object that was dynamically allocated. If you use new or new[], the onus is on you to call delete at the right time.

It's hard to say why your code is locking up without seeing a relevant skeleton.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you are worried about what's on the screen for others to see, just use a for loop printing a bunch of empty lines.

I'd wager that 10 times out of 10, when someone wants to legitimately use clrscr it's to repaint a console based menu or faux graphical layout. Which is why I suggest that such usage is unnecessary and time would be better spent with a proper GUI library.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's nothing stopping operator[] from throwing an exception, but I'd be a bit surprised if an implementation does so outside of debug mode. C++'s design model has been that you don't pay for what you don't use, and operator[] has traditionally been an unchecked operation. That's why the at member function was added, to provide a checked operation without forcing people to always pay for the possibility of a throw.

As such, you cannot depend on operator[] throwing. You can depend on at throwing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

At that granularity, everything is efficient. However, tricks for swapping without a temporary variable have a higher chance of not being as efficient due to potentially confusing the compiler's optimizer.

The lesson to be learned is that it's not worth trying to optimize a few bytes from a single scalar object. You'll get far better returns on the investment of reducing memory usage from large aggregates or optimizing algorithms with a larger impact on performance.

Also, it's rare when you can achieve both space and speed savings; most of the time you can only get one at the cost of the other.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

WCF is really just a more powerful sibling of web services. HTTP is the transport protocol of the web, and SOAP is a messaging protocol for packaging data. Serialization takes raw data and converts it to a convenient storage or transport mechanism like binary or XML.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The code will compile, but the subscript operator for std::vector does not throw an exception. To get an out of range exception you must use the at member function.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can get a list of processes and parse the result, but it's highly OS dependent.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd use public transportation if it were convenient and cheap for my area...but it's not.

I'd ride my bicycle to work in a heartbeat...if it weren't a death trap.

So I drive my car.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd use a tuple for heterogenous and/or fixed aggregates. Otherwise I'd use a list. Of course, there are always exceptions, but that's a generally universal guideline.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm putting together a new gaming machine, but would like some opinions on the motherboard since I'm weaker in that area. Here are the minimum requirements based on other components I've pretty much nailed down for my needs:

  • i5-3570K CPU (LGA1155 socket) -- already purchased, hard requirement
  • 16-32GB DDR3-1600Mhz RAM (240-pin DIMM) -- not a hard requirement except for the GB
  • 2 Radeon HD 7970 Graphics Cards (probably Gigabyte GV-R797OC-3GD) -- model not a hard requirement

Everything else can be customized based on the motherboard, but things like the case and coolers will depend on the mobo. I know that's not a whole lot to go on, but it is what it is. What would you recommend?

On a side note, I've been looking at the ASUS Sabertooth Z77 as a strong contender.

My current planned setup: http://pcpartpicker.com/user/Marikallees/saved/2x25

Thanks guys!

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but dont come on a site trying to make people feel bad about the issues they have had with breast feeding.

As opposed to coming onto a techical site asking an obviously impossible to answer question about politics? I'm almost tempted to view this thread as a trolling attempt.

Dearden commented: not helpful +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

getch reads a single key press. If you don't want to press Enter, how do you plan to know when an integer (that takes multiple key presses) ends?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's a little tricky because integers can be represented with multiple characters. Unless you only need a single digit, how do you plan to signal the end of the integer using raw input?