deceptikon 1,790 Code Sniper Team Colleague Featured Poster

hmm, what's up with the flood of "I wanna be a script kiddie" style posts.

To be fair, script kiddies don't care about how it's done, they just want tools to do it so that they can seem like leet hackers. That's why we call them script kiddies; they run scripts without understanding them. This guy seems to be interested in understanding the details, which is a nice change in the attitude that you usually see.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This would be to prevent people from trying to legally urge daniweb to remove content that the author wanted to revoke.

Pretty much. The only pressure we tend to receive as concerns deletions is from schools and students. And the answer is always the same: members who post in violation of their school's policy do so at their own risk and their posts will not be removed at either their or their schools behest unless the post breaks one of our rules such that deletion is warranted.

It's probably safer and nicer to ask the author

That's the best approach as a simple courtesy to the author. I'll let Dani chime in with the full licensing stuff, but unofficially it's safe to assume that Daniweb won't seek legal action for using code you find on the forums in proprietary software. On top of being irrationally difficult to enforce, we're simply not that neurotic.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

it protect you and the ones that using your site.

Not really, it just saves us extra work. Daniweb's moderation team is easily the best I've ever seen, and I have no doubt we'd snuff out unsavory types in short order with or without this feature. But with the feature, it gives mods breathing room to participate as regular members instead of always doing moderation work.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

was the pseudocode put in the right order because I wasn't sure thats why I was trying to get hlp with this one I thought I did something very wrong.

Nope, it looks good. Once you fix the "semantic" errors it's solid logic:

input origprice
set discount = origprice * 0.20
set finalprice = origprice - discount
output finalprice
stop

You could simplify the language by removing the set keyword and assuming that the end of the file is equivalent to a stop keyword:

input origprice
discount = origprice * 0.20
finalprice = origprice - discount
output finalprice

Or by combining the variables into a single expression:

input origprice
output ((origprice * 0.20) - discount)

But all in all, what you have is fine.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually, if it implements tail recursion optimization, then you should be ok!

Not really if the goal is to avoid memory use. TRO still introduces hidden variables. Fewer variables, sure, but the purpose of a swap without a temporary is completely defeated.

Keep in mind that the primary goal of these tricks is to avoid the negligible cost of a temporary variable. If your solution doesn't produce this saving, it's a non-solution to the given problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

need help writing pseudocode

You've already done it. Barring a minor inconsistency where you create one variable name but use another (ie. origprice/price and finalprice/final), what you've posted is legitimate pseudocode.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I actually can think of one way that does not require any extra variables, works for any datatype and is also very natural.

There are no explicit variables, certainly. However, there's a strong chance that memory will still be allocated to each parameter for each recursive call. So technically you're using more memory than a traditional imperative swap with a temporary.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Besides, 5 posts, 5 days of membership, and 15 rep points is not that hard to earn.

IIRC, it's 5 posts + 5 days or 15 reputation points. So you can unlock functionality with the default rep allocation, or you can unlock it sooner by earning rep.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

While that may work in Java, it's horribly broken in C due to undefined behavior. Further, you've introduced a requirement to check for integer overflow.

For all of the mental gymnastics involved in devising ways to swap without a temporary (though these days everyone just Googles for solutions to look smart), nobody has come up with a general purpose solution that's even comparable to using a temporary, much less superior.

Finally, if you're micro-optimizing to this granularity, you've probably lost perspective as concerns performance and memory usage.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You realize when you have an actual exam, you won't be able to run for help, right?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

catch is a keyword in C++ (part of the exception handling mechanism), you can't use it as an identifier at all.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I like them both, actually.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The only situation I can think of where this might be useful for immediate mod attention is spammer bot naming and profile patterns. With the current system that's too rare to justify the cost of implementing a new feature.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

DataGridView only binds to one table at a time. Third party controls (such as Infragistics' UltraGrid) support multiple table binding, but if you want to go with standard controls the old DataGrid has some options you could find useful, or your could combine something like a TreeView with a DataGridView to produce something workable.

Here's an example I found that seems very similar to something I wrote myself a few years ago.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The default colomns in a datagrid are textboxes.

Annoyingly substandard textboxes if you need more than default behavior, but yes. ;) It's also an interesting exercise in frustration if you want to write an extension of the standard textbox column. I'm not surprised there are so many replacements for the datagrid and datagridview controls.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

After a cursory reading, it looks like the problem is to eliminate adjacent whitespace and enable word wrapping. This is clearly a homework assignment, and it's also an instructive exercise in string handling, so we'll require that you make an honest attempt first. If you get stuck, feel free to ask a specific question (in the C++ forum), and someone will give you a little push in the right direction.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well done. However, you have two glaring errors in the modified code. See if you can find them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Seeing all of you go through essentially the same process I did makes me feel all warm and squishy. Group hug! ;D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what should i know to develop a library like the C standard library

You should have a strong foundation in C, but not necessarily the uncommon features. As an example, here's a simplified partial implementation of the C library that I wrote. In my estimation, anyone with decent knowledge of C could follow it without too much trouble barring three areas:

  1. The math library uses unions in a way that could be considered advanced.
  2. stdarg.h is very hackish and specific to the target compiler.
  3. The internal components depend on an understanding of the Win32 API.

if im thinking of building my own OS "im just dreaming"

Hardly, but writing an OS is among the most complex projects, if you want it to be more than a toy.

should i create a NEw C for it cause as we know C for linux isnt C for windows ??

C is a standardized language, so C for Linux is exactly the same as C for Windows until you start using platform-specific libraries. That happens quickly since any non-trivial program will likely call into the OS.

if kernel is binary codes how those codes manage other codes "application" o.O ??

The kernel is itself a program. A low level program to be sure, but still just a program. As concerns your question, I'm not sure I understand. Could you clarify what you mean?

and what really happens when i press the …

iamthwee commented: show off +14
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I guess strings like "1 jan 14" or "01 1 2014" are allowed also?

The use cases I received at least were consistent in the ordering of the month and day, thankfully. If 1/1/2014 could be interpreted as MM/dd/yyyy or dd/MM/yyyy, I wouldn't have even bothered with a code solution and instead said that the users have to be consistent. There's simply too much ambiguity to resolve in that case. ;)

However, it's safe to assume a short date en-US formatted string with optional leading zeros for single digit month and year.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As I said before, if you're not binding these controls to a data set with foreign keys, you need to manually get the correct department from the query result and set the combo box in code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

TextChanged fires every time the text changes, which means you're doing a lot of unnecessary work. Keeping it simple, I'd add a search button that fills in your combo boxes so you have more control over exactly when it happens.

Following that, unless you have strong binding going down, you'll need to populate child combo boxes and explicitly select the correct item.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Disclaimer

Full disclosure, this is a problem I've recently encountered at work. I couldn't find a reasonable solution and ended up recommending a logistics approach rather than a full code approach to solve it. The code performs a subset of required functionality to give users more options, but doesn't account for all reported formats. If one of you manages to solve it then I'll likely contact you for permission to use the solution in production code. However, after spending quite a bit of time on this, I'm somewhat confident that it's an unsolvable problem due to ambiguity. Anyone who solves it will earn a lot of l33t points in my mind.

On to the challenge!

Challenge

Users have a text box for date entry, and you have no control over this text box. The string must be converted to a DateTime object so that it's a valid date later in the process. However, users are allowed to type strings that are not parsable by the DateTime class. For example (using 01/01/2014):

  • 1114
  • 112014
  • 01114
  • 0112014
  • 10114
  • 1012014
  • 010114
  • 01012014

There is no consistent range for valid years (noted because one of the cases practically requires verification of the year part).

The challenge is to write an interpreter that will take a valid date with any of the above formats and normalize it into a "MM/dd/yyyy" or "MM/dd/yy" format so that DateTime will parse the string correctly. For strictly ambiguous cases, note the assumption you've made, if any. For the …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you asking how to write your own or how the .NET ArrayList class is implemented? For the latter, that's easy to show because the code has been open sourced.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C# or VB.NET are both freely available. There are free compilers for C++ and Java as well. Those are among the most popular languages.

Mya:) commented: Thanks for fast reply! +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

no I just have a final exam and I dont have a time .. so plz helllp me :((

You can downvote as much as you want, but it doesn't change either our rules or the feelings of the community about cheaters.

Hopefully a failing grade will teach you that you can't rely on chumps to bail you out.

p.s. Thread closed as a violation of the homework rule. I don't anticipate you suddenly having a change of heart, and so I'll snub a hissy fit before it starts.

blackmiau commented: Wish some people would friggin' read... +2
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We require proof of effort when helping with homework assignments. Further, don't expect anyone to do the work for you. If you do, you're not going to meet your deadline.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As you point out the struct would get passed as a value, and if the struct got bigger so the passing would become more heavy.

This is true, but there's also the question of how heavy the object is and how often it's copied around. If it's not that heavy relative to a reference or you don't pass it often, the performance difference will be negligible.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's really the difference between a value type (struct) and reference type (class). For types that are suitable to both, I tend to prefer reference types for consistency. But that's more of a stylistic choice than anything.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

frmMain has a tabControl on the 12 tabs (1 for each month) and a datagridview showning the days and the times and hours worked frmEditMonth (used as a edit Dialog pop-up) allows the user to edit the hours worked

Minor design nitpick: If you find yourself with more than a handful of tabs, a tab control probably isn't the right way to display your data. I'd be more inclined to use a list box and a user control nested in a split container where selecting a month in the list box loads that month into the user control.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If there no official limit, I'd guess that the max would be the amount of free memory currenly available.

There's an official limit: the range of size_t. Obviously if you cannot tell memcpy to copy more than (size_t)-1 bytes, then that's the limit in a single call. Copying more than that requires multiple calls, but on a modern system size_t is typically either 32 or 64 bits. So the limit is quite large.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

To be honest I don't know, and never knew there was a max.

That's because it's high enough that if you reach it, you're doing something very very wrong. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Certainly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My preference is to store options in a settings object (application-specific) and then serialize it to an XML file in either the ProgramData folder or isolated storage.

This accomplishes three big things, in my opinion:

  1. The file is located in a place that isn't under tight security (like the app.config file would be).
  2. The file is human readable.
  3. When deserialized, it's easy to bind settings to the user interface.
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's the other way. Reputation adds a vote, but votes don't add reputation. Endorsements are a separate feature entirely, where people endorse you (hopefully) when you show expertise in a certain forum.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You mean like StackOverflow does? :)

I wouldn't say they punish bad answers any more than we do, excepting the capability of regular members with sufficient e-peen points having moderation power.

No sane forum I'm aware of actively punishes members for "bad posts" by removing features they already have or whatnot, and that's what I was thinking of. Imagine taking away sponsor perks with enough downvotes, that's more what I was thinking of in terms of punishment. In other words, a truly bad idea. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The first thing I notice is that the following accomplishes nothing (unless by "nothing" you wanted an infinite loop):

} while(*str != '\n'); // if empty str inputed -> stop do-while

You're using the >> operator to populate str, and that operator is delimited by whitespace. In other words, '\n' (which constitutes whitespace) will never be stored in str.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

it'll get more members involved giving good answers rather than some bs that some will give.

Doubtful. A lot of the bad answers are due to ignorance about the subject matter, which is part of the learning process. The only way to improve quality would be to punish bad answers, which is a horrible idea if we want Daniweb to succeed as it would discourage everyone from posting and go against Daniweb's core philosophy.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Good luck with that. On a side note, simply posting your homework assignment is unlikely to produce useful replies. We don't help students cheat.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Welcome aboard. We have similar roles at work. I started out as a pure developer but now have been moved to a support manager who can also pick up the slack in development needs. I guess I was too good at handling support calls. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Note that cin and cout are objects with a number of input and output methods on varying types. << and >> are overloaded operators for those objects that "simplify" the calling of I/O methods.

See also Nathan's reply, as it's a less pedantic and more practical answer. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Recent changes to the C and C++ standards allow for variables as array size declarators.

C++ still doesn't support non-const array sizes. C has technically supported it since 1999, but compiler support is currently sparse and promises to remain so. Further, C14 has made VLAs optional even for hosted implementations, so they're basically pointless in portable code across the board given that portable code must account for both support and lack of support. And in lack of support, you're right back to the pointer approach. Which means assuming lack of support results in simpler code.

I don't see any intros to newbies for posting guidelines and such.

Whe have basic and obvious rules, but otherwise anything goes. It's not wrong to reply to older threads, though the community tends to frown upon it unless you add something to the discussion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Don't use eof() as a loop control because it introduces a fencepost error. eof() returns true only after you try and fail to read from the stream. Instead, the >> operator will return a value that can be used as the condition without any operation ordering issues:

while (openfile >> number)
{
    cout << number << end;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I thought about change resizing step from 1 to 10, but I have to ask whether is it allowed.

Of course it's allowed, provided you don't have unusual restrictions from the assignment. If you're required to resize by a single element every time you grow, then there's not a whole lot you can do about the performance hit. Memory allocations are among the more expensive of CPU bound tasks.

There are typically three different methods of resizing in libraries:

  1. Increase the capacity by a fixed amount such as 16 or 32. This amount depends on expected average usage for the dynamic array. Not the best approach for a general purpose library. However, for string classes I've preferred this one because strings tend to be shorter in average use cases.

  2. Increase the capacity by half again the current capacity, so new_cap = old_cap * 1.5. This tends to be the most popular because it's a more conservative amount than doubling while taking into account that the larger the array grows, the larger it's likely to grow.

  3. Double the capacity as Moschops suggested. The problem with this one is it can allocate an excessive amount of unused memory as the array grows.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

mostly because we had no one on the dev team who was able to figure it out :)

I lacked sufficient time to figure it out and sufficient approval from you in editing the base parser. IIRC, the argument was that significant changes to the base library would make upgrades more difficult, which is true. So I left it at that. Fight battles you can win, right? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd go with a loop as well. You could do it using more advanced methods, but since this exercise is at the beginner level, it's better to keep things simple.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what's difference b/t polymorphism andinheritance

Polymorphism is an optional feature of inheritance. Your question suggests that you think they're independent, which they're not. Without inheritance (or a significant amount of hackish workarounds), polymorphism doesn't occur.

That's assuming of course that we're talking about polymorphism through virtual member functions rather than polymorphism through templating or overloading. I think that's a safe assumption though, as most people mean polymorphism through inheritance when they say "polymorphism".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

While swapping if overflow occurs how to manage it....?

Use a temporary variable of the same type, no overflow will occur in that situation. If you try using the arithmetic tricks, overflow is a risk and greatly increases the complexity of the swap for the negligible benefit of a few bytes saved memory. If you try using the XOR swap, swapping with self is a risk and slightly increases the complexity of the swap. XOR also demands that the swapped type be integral.

These tricks put undue restrictions on you, and the savings aren't worth it if you're writing a general purpose swap. So the answer is to just bite the bullet and use a temporary variable; they're not that expensive.

Don't try to be clever, write code that works.

ddanbe commented: Good point! +15
Mayukh_1 commented: That's why using temp variable is always safest..good point +1
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wouldn't bother qualifying the languages you know as being academic experience. Experience is experience, even if you weren't paid for it. However, I'd refrain from including languages that you don't feel you can comfortably hit the ground running with yet. You're not expected to be a guru, but you would be expected not to ask basic syntax or common library questions.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon: I said C#, not C++.

Yes, I know. And I also know that C++ throws new concepts at you willy nilly, especially if you're new to programming. The closer you get to modern C++, the worse it gets. It's the same story for any programming language, which was my point.

You can't write a simple Hello World program in C# without knowing something about classes.

By the same argument you can't write a simple hello world program in C++ without knowing something about includes, functions, namespaces, objects, and operator overloading. Or, as is common in education, you can call it boilerplate and learn the details later to the same effect.

@deceptikon, Can I ask what software you use for reverse engineering?

I currently use dotPeek for decompiling .NET assemblies. For native code I've nearly always used OllyDbg for disassembly. And various hex editors come in handy every now and again.