6,741 Posted Topics
Re: main is a special function because it's the program's entry point. Thus, there's a certain measure of compiler magic involved. During compilation the compiler will determine which version of main to call based on your definition. | |
Re: [B]>I really need that code[/B] Then write it. That's what I do when I really need code for something. [B]>I have a text file >and I want to convert it vector or array[/B] I'm sure you've used cin's >> operator to read integers from standard input. What you did was … | |
Re: Your constructor and class fields are nested inside Main. It should look like this: [code] class Student { private int registrationNumber; private string name; private DateTime DateOfBirth; public Student() { Console.WriteLine("New Student created. Parameterless constructor called...."); } public static void Main(string[] args) { } } [/code] | |
Re: Call Hide rather than Close, you can restore the form with Show. | |
Re: If you give a wrong answer, someone will likely correct you, which leads to you learning more on top of the original question being answered. I don't see a downside to this process. ![]() | |
Re: What exactly were you expecting to happen? What you're attempting is rather nonsensical. | |
Re: [B]>Do me 1 favour...[/B] Not only will I do you a favor, it'll be the single best favor you'll ever receive. I'm going to let you bomb this assignment. Then you'll learn that nobody is going to bail you out, that you should only rely on yourself, and you should … | |
Re: [QUOTE=Don_k;1423916]I know that perhaps a header file is needed(containing filename, size of filename, start and end of file) for extracting these files back out into their original form, but how would I go about doing this.[/QUOTE] Here's a simple example where each file is preceded by a header with the … | |
Re: [B]>can u do a c++ program without main function.....?[/B] It's splitting hairs, but yes, you can if your compiler supports alternative entry points. For example, Microsoft's CL compiler supports WinMain as an entry point instead of main. | |
Re: Decompilers are genally crap due to the lossy nature of compilation. However, disassemblers are terribly useful provided you're reasonably proficient with assembly language. I like OllyDbg for Windows. | |
Re: % is the remainder operator. It performs the usual division operation, but evaluates to the remainder instead of the quotient. In your example, 4 can't be divided by 10, so the quotient is 0 and the remainder is 4. | |
Re: You're accessing the array out of bounds. In main, index exceeds 999, which is the largest available index in primes. Anything can happen, including wacky output and crashes. | |
Re: I think the appropriate question in this case is why do you want to invoke the destructor explicitly? It's called automatically at the right time except in some extreme and obscure situations (which you're not likely to encounter for a while). | |
Re: [B]>It works but I dont understand why it is not displaying me the items I have inserted after sorting it.[/B] Um, if the output isn't as expected then it clearly [i]doesn't[/i] work. Looking at your sorting algorithm, aside from it being obviously wrong to a trained eye, temp is an … | |
Re: [B]>um ok...um ok...[/B] You were expecting some sort of mystery of the universe? The difference is that signed types use half of the range for negative values. With unsigned types you have a wider positive range, and a guarantee of wrapping on overflow/underflow. | |
Re: [B]>Don't encourage people to use nonstandard headers.[/B] Indeed, especially when the nonstandard header is also completely unnecessary. | |
Re: <broken record> What have you tried so far? Do you have any code? If so, please post it. If not, go give the assignment an honest attempt before asking for help! </broken record> | |
Re: The invocation would look something like this: [code=text] $ g++ file1.cpp file2.cpp file3.cpp $ ./a.out [/code] The header files need not be compiled as the preprocessor textually inserts them into your .cpp files. The resulting executable file is named a.out by default, but you can alter that with the -o … | |
Re: [B]>why it's so?[/B] Enter is a character too, the newline ('\n'). On your system it has a value of 10, so 10 - 48 = -38. Note that your condition fails to catch the newline because you've already changed the value by that time. | |
Re: [B]>And the assignment called for floating point numbers, not doubles...[/B] Doubles [I]are[/I] floating-point numbers. [iCODE]float[/iCODE] is single precision and [ICODE]double[/ICODE] is double precision. Otherwise I agree with your post. :) | |
Re: [QUOTE=frogboy77;1423807]very limited knowledge of this but this using ctime appears to give a rough time the code took to run. [CODE]double time=clock(); //program cout<<clock()-time<<" ms"; or cout<<(clock()-time)/1000<<" seconds.";[/CODE][/QUOTE] This is more conventional: [code] #include <iostream> #include <ctime> int main() { std::clock_t start = std::clock(); // ... std::cout<< ((double)std::clock() - start) … | |
Re: Your two if statements are executed every time in sequence, so if you have an upper case letter, it'll be converted to lower case, then back to upper case. If you have a lower case letter, it'll jump over the first if statement and still be converted to upper case. … | |
Re: It depends on the type and scope of the variable. Can you be more specific? | |
Re: When writing a library you need to take care to only make the names that should be visible to client code extern; the rest should be static for file visibility. Names that are extern should be designed to avoid clashing with client code and other libraries as well. Finally, any … | |
Hey Dani, I know you [i]really[/i] want us to use the personalized home page and favorite forums, but is there any chance of a feature for collapsing categories on the main forum list? That's something I very much miss from the previous design. | |
Re: [B]>Is there any way I can prevent this copy?[/B] No, not really. In calling operator<<, you've bound the temporary object to a reference, which basically invalidates it for further copy elimination. [B]>had I known that it would make copies all the time I would not have done it...[/B] It's best … | |
Re: [B]>is there a difference??[/B] The latter will probably give you a warning about loss of precision, but since the value is representable by both float and double, there's no real problem. | |
Re: [B]>it 'll be good if i can find links for some good ebooks ........[/B] You'd be better off just picking [URL="http://en.wikipedia.org/wiki/List_of_data_structures"]from a list[/URL] and googling until enlightenment. I don't know of any ebooks (though my own website has thorough tutorials on a a few data structures), and dead tree books … | |
Re: Unless the method is static, you need an object to call it on. How you go about accessing the method (static, instance, inheritance, etc...) really depends on your design. How do these two classes relate and interact in your application? | |
Re: Your thinking is backward. Try left shifting instead of right shifting. | |
Re: You're missing a terminating semicolon on the Classic class. | |
Re: I have a better idea. How about you show us your attempts at writing functions and we can show you where you went wrong? Otherwise you're essentially asking for a full tutorial on how to write functions, which most of us aren't inclined to write. | |
Re: [B]>Don't use bit fields. They're implementation dependent, not portable.[/B] Bit fields are quite portable, provided you don't make unwarranted assumptions about the storage layout. | |
Re: Let's say you have an array [ICODE]{a, b, c, d, e}[/ICODE]. Now c is deleted resulting in [ICODE]{a, b, (empty), d, e}[/ICODE]. The avail_list logic would store index 2 such that adding a new item (f) would result in [ICODE]{a, b, f, d, e}[/ICODE] rather than [ICODE]{a, b, (empty), d, … | |
Re: Use xcopy or robocopy for a bit more control over the operation: [code] xcopy /E /O /V /Y "fedr023818" "Z:\TNT\prod\other projects\FEDERAL REGISTER\FIN MOD" [/code] | |
Re: [B]>cout<<"The array after revers is : " << revers (a) << "\n";[/B] What does revers return? | |
Re: [B]>The exact definition of NULL is compiler dependent, but normally defined as either (char *)0 or just 0.[/B] I haven't seen NULL defined as [ICODE](char*)0[/ICODE] and I don't suspect any compilers have done so after the generic pointer type was introduced to C. While char* and void* have the same … | |
Re: [B]>scanf("%s",&fnamen);[/B] fnamen is already a pointer in this context. Adding a redundant address-of operator changes the type, which can potentially break your program (though it's usually benign in this case). Also consider that %s without a field width is no better than gets (ie. there's no protection from buffer overflow), … | |
Re: [B]>fillnumb will be =2[/B] Why would it be? If fillnumb is 0, then that falls into your case 0, which sets fillnumb to 1. A break at the end of a case terminates the switch statement, so execution won't fall through to case 1. | |
Re: [QUOTE=kitsan;1421345]Can anyone tell me the Coding for: [ATTACH]18596[/ATTACH] Help me!!![/QUOTE] I'd be happy to give you complete code so you don't have to do [i]any[/i] work at all! [code] #include <stdio.h> #include <stdlib.h> #include <math.h> #define f(x) ((x)>0?((x)*((x)+1)/2):0) #define g(x) (((int)sqrt(8.0*(x)+1)-1)/2) int main(int c, char **v) { if (c>1) for … | |
Re: There should be a separate index counter for a and b, because you don't want to skip indices: [code] if (s % 2 == 0) c[s] = a[q++]; else c[s] = b[r++]; [/code] | |
Re: [quote] I've read around, some say [code=c++]vector.swap ( otherVector );[/code] is fastest? [/quote] Typically, but that's not a copy operation. [QUOTE]Let me know if there are fast ways to do this please![/QUOTE] If performance is an issue, it's often better to think squiggly. Instead of making a copy, can get … | |
Re: Use a loop: [code] if (argc > 1) { int i; for (i = 1; i < argc; i++) { /* Open and read argv[i] */ } } [/code] | |
Re: If the pointer is not okay, it should be NULL. Otherwise you have no choice but to always return a valid pointer and test the contents, which you've already stated isn't desirable: [code] #include <stdio.h> char *fun(void) { char *result = NULL; /* Allocate and populate result, or leave NULL … | |
Re: [url]http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_21.html[/url] | |
Re: >small(*array[], &sumc, &sumr, r, h, w); The empty subscript only works for declarations. Either remove [], or remove * and change [] to [0]. Also, &sumc and &sumr are pointers, not int as small expects. This will compile, but it may not do what you want because you clearly have … | |
Re: Bumping your thread is rude. Please use code tags. Specify WTF is wrong with the program if you want help. kthxbye. | |
Re: >You didn't think you could just download experience "matrix style" With all of these books claiming you can learn programming in 24 hours and 10 minutes, or that even dummies and idiots can program, it's reasonable to believe that programming isn't hard when you have no real experience doing it. | |
Re: char is a keyword, you can't use it for a variable name. And don't use magic numbers. If you [i]must[/i] rely on ASCII (std::tolower exists for a reason), at least use character literals: [code] if (c >= 'A' && c <= 'Z') c += 'a' - 'A'; [/code] | |
Re: [B]>I was using process.h , now i replaced it with malloc.h.[/B] So you replaced a header which didn't contain the function wanted with a header that might not even exist. Brilliant. And what about including stdlib.h as gerard suggested? That's the correct solution. [B]>Is it correct CIRCULAR implementation??[/B] Assuming you … |
The End.