6,741 Posted Topics
Re: How good of a timer are you trying to write? If it's a boo-boo practice exercise or you don't need sub-second granularity, the standard <ctime> library is more than sufficient. Just wrap a few function calls in a class and call it good. | |
Re: >1. What are all the "long" functions for? Do I have to use "long"? They're for the date and time calculations. You don't have to use long, but it helps to avoid integer overflow. >2. (just trying to understand this program) what are your "e"s and "s"s? Poor naming. s … | |
Re: >aside from that i am not that proficient in c, i'm more into java Last I checked, homework assignments were meant to help you learn the subject matter. Thus, claiming that you aren't proficient isn't exactly a good reason not to try. | |
Re: This is one area where arrays and dynamic arrays are different. To pass an actual array as a function parameter, the following syntax is used: [code] T (*param_name)[COLS] [/code] Alternatively, you can use the empty dimension syntactic sugar: [code] T param_name[][COLS] [/code] The first dimension can also hold a size, … | |
Re: When you run the program, watch your hands carefully and count how many keys you hit. I suspect you're assuming that the Enter key is somehow treated differently when in reality it too is extracted by getchar as the '\n' character. -38 is fully expected when '\n' is 10 and … | |
Re: I'm not sure I understand your problem (working with std::string is no less powerful than C-style strings), but if you're ultimately converting to an integer type length [I]should[/I] be a consideration due to overflow. | |
Re: [B]>Positive values seem to follow ASCII, but ASCII is only 128 characters. So where are the others from?[/B] It really depends on the character set your system is using, but probably Unicode or some form of extended ASCII. | |
Re: [edit] Doh, this is the C forum. Post replaced. [/edit] The same function you use for single lines, fgets. | |
Re: [B]>is temporary object created is returned to a2 object ?[/B] Conceptually, yes. In practice compilers can often optimize away return value temporaries. [B]>why it can't be returned by reference?[/B] Well, in this case it can't because then you would be returning a reference to a local object, which is immediately … | |
Re: Are you required to update the file with each edit? It's often more practical (barring very large files) to keep the file in memory and work with the copy in memory. Then when a convenient time comes to save the edits, you can overwrite the file. To read the file … | |
Re: [B]>How many years will it take one on avg to master C++ (doing self study) or atleast get a fair touch of this lang?[/B] Mastery is quite different from competence (which is how I interpret "a fair touch"). If you're an experienced programmer you can become competent with C++ in … | |
![]() | Re: >I installed TurboC++ version 3.0 in my computer Okay. >which runs a WindowsXP OS.... It might start without crashing, but a lot of old programs start on Windows XP and don't work correctly due to their age. >The same Turboc++ works well in other computers with the exact configuration as … |
Re: [B]>Who make better programmers? Men or Women?[/B] Based on my experience conducting interviews, I'd say men make better programmers on average. Of course, that's completely anecdotal with no scientific rigor, so it's worthless as an answer to your question. I'm not aware of any studies on the subject; you'll simply … | |
Re: [B]>NO, at least, it would be extremely surprising and weird. Just try and see. I >bet you that if you have a proper compiler, it will issue a compilation error.[/B] If your compiler complains about a pure virtual destructor, either the compiler is non-standard, or your code is wrong. [B]>Why? … | |
Re: You're not reassigning the reference, you're overwriting the value of ival, to which ref is a synonym: [code] #include <iostream> int main() { int ival = 12, ival2 = 14; int &ref = ival; ref = ival2; std::cout<< ref <<'\n'<< ival <<'\n'; } [/code] [B]>1 more thing- do references occupy … | |
Re: [B]>But I can't understand how p holds the value 30000 or how the result of the program is addition of 30000 and 20..[/B] Presumably this hideous trick is meant to add two numbers without using the + operator. a is converted to a pointer to char, thus making the address … | |
Re: >can you give me a code for queue program??? I can do one better. I'll give you code for a queue and a stack program: [code] #ifndef JDEQUE_H #define JDEQUE_H /* Increment or decrement an index with wraparound */ #define _wrap_decr(i,n) ( (i) = ( (i) == 0 ? n … | |
Re: [B]>I want its kids to be concrete classes But I don't want to implement the all methods of the class.[/B] Oddly enough we just had a discussion about this. You can make the "optional" member functions simply virtual instead of pure virtual (all with no-op bodies). Then include a pure … | |
Re: I'll get the bug out the way first: [B]>sample obj(); //explict call only here allow because of explicit keywoed[/B] This isn't a constructor call, it's a function declaration. Remove the parens and you'll construct a new object called obj. While it's still calling the constructor, one could argue that a … | |
Re: [B]>This causes an exception, please explain the error.[/B] Simple, an uninitialized pointer is not a pointer to infinite memory. It's an invalid pointer. | |
Re: [B]>Here's a solution that I think has the desired effect, >although perhaps not quite by the means you might expect.[/B] Clever. Though I'm curious how you came up with that solution. Was it intentionally designed from the start, or did you simply notice a pattern while working out a more … | |
Re: [B]>could anyone give a clear description of memory allocation process when virtualism works.[/B] Obviously this varies from compiler to compiler, but a typical implementation will generate vtables at build time. So when your program is loaded into memory, the vtables are already set up for the inheritance hierarchy. The constructor … | |
Re: [B]>but that's really programming in C, not C++.[/B] No, it's just a part of C++ that should be considered more advanced due to the lower level nature. The real question is why is a book teaching such things so soon? Most likely it's ignoring the more useful parts of C++ … | |
Re: [B]>If tp is going to be altered, like that then why even have getter/setters?[/B] Getters and setters are member functions, you can do more than just get/set a single data member. You can include logging, or debug output without any trouble, whereas if the data members are public/protected, life becomes … | |
Re: How do you get the hello world program wrong? Any decent C++ programmer should be able to type it out flawlessly while plastered from booze, spun around in a chair for ten minutes, and blindfolded. :D | |
Re: Presumably each line is processed individually, in which case you can simply read a line at a time and then parse it. As an example, this program would echo the file to stdout: [code] #include <fstream> #include <iostream> #include <sstream> #include <string> int main() { std::ifstream in("file"); if (in) { … | |
Re: >should work on unix as ANSI is listed. _vscprintf isn't a standard C function. It's a Microsoft extension that is unlikely to work on Unix. | |
Re: [B]>Can someone explain me what does this mean? >"40[^\"], %*c"[/B] Assuming it's actually "%40[^\"], %*c", it means read a string of up to 40 characters or until a double quote is found (%40[^\"]), then match a comma, any amount of whitespace, and ignore the next non-whitespace character (%*c). The %[ … | |
Re: [B]>Any one can help me?[/B] Not when your description of the problem consists solely of vague techno-babble. | |
Re: Perhaps it could be because temp is pointing to some random location? Pointers aren't magic, you're responsible for making sure they point somewhere sensible. Since this is C++, I'd also use a constructor to simplify code using termNode: [code] struct termNode { int coeff; int exp; termNode *link; termNode(int coeff, … | |
Re: srand seeds the random number generator. If you call srand too often, and the value you use as the seed (srand's argument) changes infrequently, you'll keep seeding the random number generator to the same thing and rand will produce the same sequence. [url=http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_rand.aspx]This[/url] will give you an idea of how … | |
Re: Wow, I was [i]just[/i] explaining interfaces to a coworker the other day. Freaky. >Does any one know a robust benefit of using interfaces? Consider the concept of data hiding. Let's say you want to provide a class to some client code, but don't want to give them full access. One … | |
Re: Piracy is wrong, period. You can rationalize it with different motives, but in the end you're still refusing to honor the creator's wishes even though they have every right to distribute their creation however they choose. The penalty should be identical to theft. You're punished in a way that's representative … | |
Re: >That seems a bit overkill It does at first glance. >why not just cast the character to an integer and add the number then recast back to character? Well, first because there's no need to cast, and second because letters in the basic character set are not required to be … | |
Re: [B]>score[i].thescore ->name = n;[/B] Close. [ICODE]thescore[/ICODE] is your dynamic array, not [ICODE]score[/ICODE]: [code] score->thescore[i].name = n; [/code] Apply that logic to your whole program. | |
Re: [B]>1) Explain why this is used - what are the pros/cons?[/B] That's quite a broad question. Can you be more specific about what you learned and what part of it is confusing? [URL="http://www.eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx"]This[/URL] is a tutorial that I wrote. It's more of an overview of pointers in general, but it … | |
Re: [B]>how can i use the switch statement to find a value in a range?[/B] Short answer: you don't. Long answer: You need a case for each value in the range, which obviously doesn't scale well at all. Use an if..else chain if you want ranges. | |
Re: [B]>All we know that PI = 22/7.[/B] Apparently not, because those of us who are correct know that PI < 22/7. Further, because PI is an irrational number there's no combination of x and y where x/y = PI. [B]>But how and why it is 22/7 rather other fractions? [/B] … | |
Re: [B]>I am curious how to became a white-hat hacker.[/B] Not many people in the know will trust that your intentions are benign. So my advice is to become a black hat first. Roll with other black hats and learn from them, but don't delve so deeply that you do any … | |
Re: [B]>It outputs 0 when I would expect 2.[/B] The problem is with your expectation. You're punning the bytes of a multi-byte object(float) to raw binary[1], then casting the first byte[2] of the result to another multi-byte type (int) and somehow expecting the value to match what was originally stored in … | |
Re: [B]>so how does it loop ?[/B] Not false is true, not true is false. That's how boolean logic works. Perhaps if you study equivalent constructs, things will become more clear. The following two snippets do exactly the same thing: [code] while (!correct) { ... } [/code] [code] while (correct == … | |
Re: [B]>Can anyone help me?[/B] Post your code, or a suitable facsimile of your code that exhibits the problem. [B]>Is it a problem with the compiler or my program. The latter is not possible >since I tried out a similar program from a book and got similar results.[/B] It's not possible … | |
Re: No, there's no difference, assuming we're talking about the result of the sizeof operator and any assumptions gleaned from it rather than technicalities such as the struct hack. | |
Re: >and error still occured pls help You didn't specify what the error was. >I am a girl doing my 1st simple program "Oh great, is Narue going to bash the title now?" Yes. :) First, it's not informative at all. Second, it has useless information. We don't care if it's … | |
Re: [B]>Help please?[/B] "Help" doesn't constitute doing your thinking for you. It doesn't constitute doing your typing for you either. Until you come up with something besides a program requirement, and thus prove that you're not looking for a handout, you're welcome to piss off. | |
Re: >how do i check the no of elements on the array ? Strings take an character value (the '\0' character) and use it as a sentinel. You can do the same thing with an integer array, but just like with strings, you can't use that sentinel as a legitimate value. … | |
Re: [QUOTE=firstPerson;]That will be $100 per homework please.[/QUOTE] That's cheap. I use my regular consultancy rates for lazy student homework: $250/hour with a minimum of 8 hours. | |
Re: >It violates about every rule in the book (homework, bumping, code tags) [B]Homework[/B]: It's a clause for the person asking questions, not the person answering them. There's no explicit rule saying that you can't give the complete answer to homework (though it is an [URL="http://www.daniweb.com/forums/thread78060.html"]unwritten rule[/URL] and you'll lose face … | |
Re: >can...u...convert..words..2..no..????? Yes, though the inverse is easier due to formatting constraints. It's not a trivial problem, but it's also not overly difficult. What have you tried? |
The End.