1,362 Posted Topics
Re: First I would ask, "WHY?" Why take the slowest sort and slow it down further with the overhead of more function calls and additional memory usage? And, you will have a sort that may overflow the stack on sorting a large array. That said, a quick bit of googling finds … | |
Re: I'm not fully sure what you're looking for. If you browse in Windows Explorer to the folder where the program you want to run is located, shift+right-click and choose Open Command Window Here. You then are in a command window at that folder. If you want to be able to … | |
Re: So just what is that you're trying to do with this statement [icode]string letter= str.length(i, 1);[/icode]? Once you fix that, then there's issue that your function is not being used in main( ). (yeah, what Auto said!) | |
[URL="http://www.metal-club.org/ElectricLesson.html"]What in the world is electricity and where does it go after it leaves the motor in your lathe or mill? [/URL] | |
Re: Doing a good job is like peeing your pants in a dark suit. It gives you a warm feeling, but nobody notices. | |
Re: [QUOTE=jonsca;1160338] ch1 is a char so it holds 1 character. When you are typing in the character to go into this variable, you hit enter. Enter is a character which remains in the input stream and is processed by the [iCODE] cin >>int1;[/iCODE] call which interprets it as "someone has … | |
Re: Well, is there another computer on your network? Do you set fixed IP addresses, or let DHCP on a router handle them? More info needed to give any definitive help. | |
Re: There are a few approaches one can take. Get input. Check the state of the input stream, if it's good, you got an integer. If it's bad, you didn't, so you need to clear the error state and flush out all that remains on the input stream and try again. … | |
Re: How about you tell us what you think the answers are, and why the other choices are not correct, and we'll help you to understand any that you got wrong. | |
Re: [QUOTE=apegram;1156383]The comma seperates the negative! That's my story and I'm sticking to it.[/QUOTE] As well you should. AD - this is from Tongue and Quill, on commas:[quote] b. After introductory words such as yes, no, or oh. Yes, I’ll do it. Oh, I see your point[/quote] In a related vein, … | |
Re: I'd been thinking of asking the question about the HW ad myself, just never got around to it. Really bugs me as I use them, have two sites hosted there. And after a brief respite, IT'S BAAAAACK!! | |
Re: Yes, you can write a C++ program to do all that. Oh, I mean YOU can write it, we won't. Please read the sticky threads explaining how to get help here. | |
Re: You could store the data as a separate file, then the code to read and store the data to your array of structs is quite small and simple. Your last example is almost correct in line 1 for initializing the array, but you must indicate that it's an array [code] … | |
Re: It really helps if you tell us what error message you're getting. | |
Re: You need to move the [icode]using namespace std;[/icode] line to be above the function prototype. | |
Re: If your primeNum is a factor of the array size, you'll keep displaying the same values again and again as you go around the circle, skipping over most of the data. | |
Re: Works for me. Doublecheck the spelling of your data file name, does it agree with what's in the code? Is the file in fact where your program is expecting it to be? What environment are you using, how are you executing the program? | |
Re: [code] while(newfile[when]) when++; //gets "newfiles" length [/code] Does not do what you think you want it to. It stops at the first char with value 0, which might be a value in the date that occurs before the end the input file, but is not guaranteed to mark the end … | |
| |
Re: How would assign a value to an element of the array? Pretty much the same you assign a value to a plain int. Your loop is fine, if you know exactly how many values are in the data file, and that number is the size of the array. Usually a … | |
Re: don't put the [] on the parameter in the function header, just the ** [code] //not double** transf[][] ) //just double** transf ) [/code] What you're describing is a two-D array of 2-D arrays! | |
Re: For starters, what is this suppoed to be doing in function menu() [icode] return choice = main();[/icode]?? Just return the value choice. It would help if you gave a better description of the error that occurs, but I'm betting you get a debugging message about your array [icode]fgrade[][/icode]. Your function: … | |
Re: [QUOTE=axed;1145560]Hi, I want to know when and where is memory allocated for static variables. If: 1) static variable is in a function 2) static variable is a member of a class 3) a global static variable inside a file of code. Much appreciated. Google hasn't been much of a friend … | |
Re: The program is halting at this line: [code] void Insert( List_t &List, Addr_t &Start, Addr_t Pred, Addr_t &Avail,cAccount NewAccount) { Addr_t Curr; Curr=Avail; Avail=Avail+1; List[Curr].Account=NewAccount; ///breaks here [/code] And is doing so on the very first record (John Walker) You also have many warnings that you should attend to, such … | |
Re: Now I might be wrong about this, but I think your char* in main is pointing to where the literal string is in the code. It is not allocating space on the stack for a variable. Your function is then attempting to change the code, which it's not allowed to. … | |
Re: You're trying to assign NULL to a Train object, or to compare NULL to a Train object. You haven't overloaded the = and == operators, and it wouldn't make sense to assign or compare NULL in any case. ar is the pointer - that can be assigned or compared to … | |
Re: What do I like most in Win7? That it's not as annoying as Vista. I'm still annoyed that Create a Restore Point and doing a System Restore are separate apps. | |
Re: The poll is actually to restrictive for me - different machines get different treatment. Office PC is left locked when I'm not around. Main home machine is on 24/7. Laptops I hibernate when not in use. A few other desktops around the house get hibernated till needed. What is this … | |
Re: One reason to compare pointers is to compare two pointers for equality (or inequality) to determine if they are pointing to the same thing, or not. Or if a pointer is pointing to anything at all (ie. ptr != NULL ). Otherwise, using > or < comparison, it's kind of … | |
Re: [icode]cout << setw( 20) << "Find Allen, Jim: ";[/icode] use whatever number of spaces will contain your longest string. Remember that setw is not a sticky setting. | |
Re: It has no indentation? It's using old, outdated include files? It has meaningless variable names? Oh, and the % symbol is used incorrectly. You really should explain your problem. What should it do, what it's actually doing, where you think the problem might be. If your compiler generated any error … | |
Re: You could use any of the regular sort functions. Your comparison must be correctly done, as in [code] if( strcmp( my_class[i].lastname, my_class[i+1].lastname) > 0 ) [/code] which is the comparison for bad ol' bubble sort. I changed the array name as "class" is a reserved word. And you have an … | |
Re: You could allocate an array of 1 to 100, then shuffle it. Or, as you generate a new number, scan the current array content looking for duplicate, reject the number if found. But that becomes a time consuming operation, the more full the array gets. I'd go with the first … | |
Re: Yes, you could use sort( ), provided you provide a comparison function. | |
Re: I think this function[code] void Point::shift(double dx, double dy) [/code] shoudl add dx to the x member and add dy to the y member. As to errors, please post the exact error message (or pertinent parts thereof) and where in your code you think the problem lies. When posting code, … | |
Re: divide, then use modulus. You can create a loop, where the value you divide by is decreasing power of 10 | |
Re: First of all, to enter and process the user's conversion choice, [icode]sym[/icode] must be of type char. Then, in your switch, you don't need the if statements - the switch does that. [code] switch ( sym ) { case 'c': case 'C': //do the Celsius conversion break; case 'f': case … | |
Re: Compiled in VC++ 2008. Runs fine from the IDE and directly from the command window, or double clicking program file. Want to give more details on what you did/tried and the system description? | |
Re: [QUOTE=firstPerson;1132075]Your sort array needs another for loop.[/QUOTE] No it doesn't. The do...while is the outer loop, continues until a pass of the inner for loop goes without any swap occurring. However, it is less efficient than it could be, as it keeps comparing at the far end of the array, … | |
Re: cin statements put input into the variables you declared. The actual values, Bronco, 2005, 12345, etc will be entered during runtime in response to the program's prompts. | |
Re: Big, and I mean BIG, problem is first of all that you are using type float - which is not very precise in dealing with large numbers. And your numbers get really, really large. What happens in this: [icode] fac( 6 * k ) [/icode]. At the limit of your … | |
Re: Your counting of letter occurrence looks to be correct, but could be more efficient. Back to that in a bit. This:[code] if(numberOfTimes[i] > numberOfTimes[i-1]) { max=i; } [/code] should be in a separate loop, after all the letter counting is done. Once you have the counts of letters, then scan … ![]() | |
Re: As with any non-trivial problem, get out pencil and paper and start breaking the problem into smaller sub sections. Keep refining till you are at least at the level of describing each function you need - what goes in, what it does, what comes out. This one has a few … | |
Re: I think you're on the right track [code] for(i=0;i < numStudents ;i++) { tmp=array[i]; for(int j=0;j<numStudents;j++) { if(array[j]==tmp && (j>i)) { cout << array[j] << endl; } } } [/code] You examine each element of the array, and compare it to all others, looking for a match. Your j>i test … | |
Re: That sort of statement will only work at array declaration. [code] int data[][3] = { {1,2,3}, {4,5,6} }; [/code] In your case, where the array is declared in the header, it must be given a size for both dimensions. Then, in the constructor, you must initialize it within loop(s). [code] … | |
Re: [QUOTE=vegaseat;1119398]Wealth created by speculation can evaporate quickly. The US government owns a huge amount of land and resources that it can use as a collateral.[/QUOTE] But the greenies have it all tied up with restrictions so nothing useful can be done with it. What's it really worth? | |
Re: If you're writing a C++ statement like that, the answer should be 1. 1/1 = 1 1/2 = 0 1/3 = 0 ..... Please show the actual code, and we can give an actual help. | |
Re: This bit bothers me [code] if (num > 10) {quit = true;} cout << factorial(num); [/code] Is it your intent not to find factorial of 10 or greater? And to use the 10 or greater input as a quit signal? The way you have it, your code will set up … | |
Re: [icode]if(name==s[0-4])[/icode] says to compare name to s[-4], which is way out of the array's bounds. You will have to construct a loop and compare name to each string in array s, one at a time. | |
Re: OK, back up the train a bit. [icode]int num_players(0);[/icode] is not the way to initialize a simple data type. Try: [code] int num_players = 0; [/code] The array of player structs needs be only a 1D array, so your [icode]**playersp[/icode] is excess. The input function prototype ought to be more … |
The End.