- Upvotes Received
- 3
- Posts with Upvotes
- 3
- Upvoting Members
- 2
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
Programmer a long time ago, getting back into it now.
- PC Specs
- Platform: Mac mini running OS X, using Qt as my IDE and C++ as my primary programming language.
39 Posted Topics
Hi, all - I'm relatively new to iterators, and to template functions, so I suppose it was inevitable that the first time I tried to combine them, I'd run into a problem. Here's the function: [CODE]template <class T> int getVectort(ifstream & s, long nbrCells, typename vector<T>::iterator iter) { int rc … | |
Re: Where is grade() defined? It's referenced in grade.h, but I don't see a definition. Same goes for some of your other functions. | |
Re: Please put your code in code tags in the future. The variable message is building just fine. The problem is, you're only writing out the current decrypted letter: [CODE] cout <<"Current message: " << decryptedLetter(num)<< endl; [/CODE] Change your code to first append the new letter, and then print the … | |
Re: Operator overloadings are often tricky. You'd do an addition operator like this: [CODE]Poly Poly::operator+(const Poly &rhs) { Poly temp; temp.size = size + rhs.size; return temp; } [/CODE] Note that this isn't going to solve all your problems in this program. | |
Re: Is there a question in here? | |
Re: The "&&" operator has higher precedence than the "||" operator. Your statement in line 3 is evaluating [CODE]m==12 && d<1[/CODE] first, and then running the "||" evaluations. Can you see how this isn't what you wanted? | |
Re: You've got your assignments backwards. The receiving variable should be on the left, and the calculation should be on the right. So: [CODE]31-day=inbetween[/CODE] should be: [CODE]inbetween = 31 - day;[/CODE] (Note that the use of spaces in your code makes reading it more understandable.) | |
Re: It looks to me as though you're currently counting swaps, not comparisons. To count comparisons, you need to move your line 15 outside the if statement. Also, note that you're not initializing comparisons, so if your function is passed a non-zero argument, your count will be off by that amount. | |
Re: What have you done so far? Post your code, and put it within code tags, please. | |
Re: The problem is that end() isn't what you think it is; I think it's a sentinel node, but in any event, it's not a valid data element. You can replace it with: [CODE] sort(a1.begin(), a1.begin() + size - 1); [/CODE] I'm looking into a better way to do it, without … | |
Re: Compiles (and runs) using gcc, too. Here's my entire program, built from your snippet: [CODE]#include "vector" #include "iostream" using namespace std; int main () { vector<int> iv; iv.push_back(4); vector<int>::iterator it = iv.begin(); cout << *it; cout << *(iv.begin()); //debug assertion here return 0; } [/CODE] This doesn't compile on your … | |
Re: your line: [CODE]if (answer != 'n' || answer != 'N' || answer != 'y' || answer != 'Y') [/CODE] Will never return false. The "||" operator is an OR, not an AND. The variable answer can't be all four of the values you test, so at least three of the … | |
Re: You'll need a second array to hold whether the corresponding elements have been found or not. If you're super-tight on memory (unlikely) you can use bit arrays, but a simple bool array will work just fine. | |
Re: A couple things come to mind: 1. you don't have to use the third parameter; it might be better to leave it out. [URL="http://www.cplusplus.com/reference/string/string/find/"]http://www.cplusplus.com/reference/string/string/find/[/URL] 2. I can't remember all the characters that require escaping in a string sequence...have you tried searching for something simpler, like alpha text without any other … | |
Re: My first thought is, why would you want to use arrays instead of strings? You have a perfectly good implementation using strings...why argue with prosperity? If you do want to use arrays, you'll have to buffer the input string (the "sentence") and rebuild it into another array as you replace … | |
Re: 1. get rid of the curly braces on lines 38 and 39. 2. your 2nd and 3rd calls to getline() won't work, because you're trying to pass a double in the second parameter, and getline() expects a streamsize (int) variable here. But I don't think you want a getline() here … | |
Re: What happens when you explicitly declare a destructor? | |
Re: Your constructor paramater is missing a type. I noticed that you chose the same name for your parameter as you chose for your array. You're aware that just by giving them the same name, you're not actually passing the array into the constructor, right? | |
Re: A static method can only access static members of the class. This feature doesn't prove useful very often, in my experience. The "const" at the end of a function bans the function from modifying any members of the object. | |
Re: I believe you're missing a semi-colon at the end of line 17. And, you're attempting to reuse a variable name in line 34 that you've already used in line 19. Fixing these should at least get you to compile. | |
Re: It's going to be system/compiler dependent. Is your matrix going to be sparsely populated? You might consider a different data structure in that case. | |
Re: How much have you completed so far? Post what you have, please. | |
Re: I'm taking a look at this program, and the instructions. I'm not sure what "in = temp" is supposed to mean, but I think it's putting you into an infinite loop. (This doesn't appear to be your only bug, though.) Also, as you appear to have discovered, there's no clear() … | |
Re: Not sure what you mean by "show" a constant. If you're trying to declare a constant, do so in the definition of your class. [CODE]class Savings { private const double INTEREST_RATE = 0.03; . . . }; [/CODE] If I understand what you're trying to do here. | |
Re: I'm curious...why did you create a separate class for the account number? It seems to me that you could have put your static variable in the Account class. Then, you constructor could retrieve the account number, copy it to the member accountNumber, and increment it. This would obviate your issue … | |
Re: From [URL="http://www.cprogramming.com/tutorial/operator_overloading.html"]http://www.cprogramming.com/tutorial/operator_overloading.html[/URL]: [QUOTE]... the overloaded operator is a member of the class ...[/QUOTE] Try declaring it in the public section of your class definition. | |
Re: Let's have a quick terminology check here to make sure we're on the same page: an [I]object[/I] is a collection of data and methods to access that data. a [I]class[/I] is a definition of an object. a [I]member[/I] is a data element within an object. (I just whipped these definitions … | |
Re: A good start would be to put each of those code fragments into separate routines, and post the code here. Please put the code in tags for easier reading, too. Thanks. | |
![]() | |
| |
Re: Where is cin declared and initialized? I see no mention of a filename, or an attempt to open a file; how is your program going to access the file? Also, I see no need for the randomizing of c. Finally, why are you casting the characters you read into integers? … | |
Re: This is actually a pretty clever problem. Can you be sure that your input file is exactly 22x80? Were you given any other rules about the contents of the input file? | |
Re: main() can't return a void; it must be declared int. | |
Re: This tutorial may help you get your file access working: [URL="http://www.cplusplus.com/reference/iostream/fstream/open/"]http://www.cplusplus.com/reference/iostream/fstream/open/[/URL] Also, I believe you have your valid test reversed in line 27. Once you get these addressed, we can go from there. | |
Re: There are plenty of C++ tutorials on the Internet. The challenge is, if you think like most people do, you won't internalize a concept until you see a need for it. In C++, this is tricky, especially if you're an experienced C programmer. You have to conceptualize a real need … | |
Re: If I understand your question, you want to establish a starting value as well as an ending value for your prime number search? If so, that's quite simple; instead of having a single num, have two ints: start_nbr and end_nbr. Prompt the user for them separately, and pass them both … | |
Re: I'm not sure I understand your question. Are you asking the probability of certain patterns of characters occurring? Or, are you asking how to compare the selected characters? | |
Re: GCC has a similar tag: [QUOTE] -fexpensive-optimizations Perform a number of minor optimizations that are relatively expensive. [/QUOTE] I'd venture that "expensive" here means time-consuming to the compiler. Your code might not even contain the kind of stuff that such optimizations target, though. | |
Re: I'm not at all sure I fully understand your program, but...I wonder if line 43: [CODE] for (int i=0; i<cCol; ++i)[/CODE] should be: [CODE] for (int i=0; i< BOARD_SIZE; ++i)[/CODE] It's not clear to me that you're exhausting all possibilities with your current loop limit. |
The End.