1,358 Posted Topics
Re: That is an unusual notation, but it could work. That aside, this program won't run properly. Your b array is only 2 elements long. [B]Q.[/B] What happens if your user wants to generate a sequence that is greater than 2 numbers long? [B]A.[/B] Your program crashes. | |
Re: The extraction operator breaks the input stream at a whitespace (a 'space' or a newline, among others). Take advantage of that and try using multiple input statements:[CODE]while (ifstream >> rowNumVar) { ifstream >> wordVar >> floatValVar; }[/CODE] | |
Re: I'm not really sure what you're asking, but I think you're asking about the efficiency of passing conventions. In your example, if you were originally passing an 8-byte long and you change it to a 4-byte pointer it wouldn't make an 8-byte difference. It would only make a 4-byte difference, … | |
Re: A word of advice, don't mark your thread with "URGENT" that actually makes it more likely to be ignored. It may be "URGENT!!!" for you, but it isn't for us. I'm not sure what you did, but I can't read your comment(s) well enough to help much. Did you try … | |
Re: Um... How do you expect to add a number to the file if you never read a number? I don't see anything related to the "Enter Age: " prompt... Once you add the proper input statements, the rest is basically the same as for the name. | |
Re: I would suggest you speak with your instructor and ask them this question. It seems to me that the purpose of this assignment is to demonstrate dangling pointers and the problems they cause because you did a shallow copy when a deep copy was required. I suspect the instructor wants … | |
I'm doing some self-study concerning statistics right now and while doing so I want to get some practice with templated classes. As a result, I'm working on a collection of templated classes designed for statistical analysis. What I would like to know is how I would handle creating typedefs for … | |
Re: [QUOTE=Nandomo;1350308]I don't comprehend getche.[/QUOTE] The function getche() is a non-standard input function defined in the non-standard header "conio.h". Don't use it. Instead, use something standard like [URL="http://www.cplusplus.com/reference/iostream/istream/get/"]istream::get()[/URL] or similar. EDIT: Or do as first person suggested. Approach your problem directly instead of dancing around it. | |
Re: On Line 100 you declare nd as a pointer to a Listnode, which is fine. Then you do nothing else with it until Line 107 where you try to dereference it to store information to the object it points to, which is definitely NOT fine. The problem is you haven't … | |
Re: [QUOTE][CODE]for (i=0; i<tempstr.length() ; i++){ if (tempstr[i] == ' ' && tempstr[i+1] == ' ') {[/CODE][/QUOTE] [B]Never[/B] use i+1 as an array index unless you account for it in your loop control. When your for loop gets to the last element of the array, you go past its boundaries with … | |
Re: I think you'll have to share a little more of your code so that we can see exactly what's going on. What do you initialize 'p' to? Are you initializing it to NULL or an actual object/value? The assignment operator should only call a constructor if you use a pass … | |
Re: [URL="http://www.gidnetwork.com/b-38.html"]Your formatting isn't very good,[/URL] it makes it very difficult to follow what you are trying to do. What exactly is this program supposed to do? Why do you have assignments formatted like this?[CODE]found = 2 * a > b;[/CODE]What are you hoping this will accomplish? | |
Re: It's evaluated that way because of the mathematical order of operations. Look again.[CODE] //with this macro #define SQUARED(x) (x*x) //this line: int i = SQUARED(3 + 2) //literally becomes this int i = [COLOR="Green"][B]( 3 + 2 * 3 + 2)[/B][/COLOR]; //order of operations says multiplication occurs before addition int … | |
Re: There are a couple different ways to do it. Both will require loops. What are the even numbers? 0,2,4,6,8, etc... Can you think of a way to generate a similar series to use as a sequence of array indexes? | |
Re: [URL="http://www.daniweb.com/forums/faq.php?faq=daniweb_policies"]You obviously didn't read the rules when you signed up.[/URL] [list=1][*]Don't hijack threads (especially 6-year old ones). [*][URL="http://www.daniweb.com/forums/announcement8-2.html"]You need to do your own homework.[/URL] [/list] You'll need nested loops to do this, but I'm not going to demonstrate until you try yourself. | |
Re: Your Case 1 is not a "Perfectly valid Derived" it is a Base object that has been forced into a pointer to a Derived object. You can't call testD from a Base because a base has no [B]testD[/B] method, virtual or otherwise, it has a [B]test[/B] method. In fact, none … | |
Re: A solution to what exactly? Give us something to work with... Oh, and check [URL="http://www.daniweb.com/forums/announcement8-2.html"]here[/URL] as well. | |
Re: You need to start by initializing your "dist" array properly. Currently, it is not an array, and it is not initialized. It is a pointer to a single int. If you try to use it as an array, you will cause a segmentation fault at run time. To accomplish this, … | |
Re: You'll have to elaborate a little. "It's not working" gives us nothing to go on. Are you getting a compiler error, invalid output, etc...? What is the definition of "AddString()"? | |
Re: By chance is this assignment related to inheritance? If so, it is possible to define 2 classes that work together to produce a shape such as a rectangle then determine the area. | |
Re: You would have to read the file word-by-word and compare the read-in word with the user input to see if it matches. Alternatively, you could read the file (again, word-by-word) into a vector of strings, then use [URL="http://www.cplusplus.com/reference/algorithm/find/"]the find() function from the <algorithm> header[/URL]. | |
Re: [QUOTE=chepaii;1347112]Hi! can you make and run a program that will display the numbers and so on depending on the number of lines the user will enter. example if the value of N is 4 the output will be like this: N=4 4321 321 21 1 thanks ! :))[/QUOTE] :yawn: Wow, … | |
Re: I don't know if there are sites dedicated to any other specific types of algorithms, you will have to do some googling for that. That being saie, [URL="http://www.sorting-algorithms.com/"]sorting-algorithms.com[/URL] is one that I use for obvious reasons. | |
Re: [QUOTE=hq1;1344523]okay so im just guna work on the above assignment at school, but i have this other assignment that i did below, it reads from keyboard but i also need it to read from file, how do i do that? [code] The following program reads a number from the keyboard … | |
Re: I don't see where you are inserting a '\0' (NULL char) to terminate the C-string. The '@' must be an extraneous character stored in a byte adjacent to the memory that holds the C-String. | |
Re: [QUOTE=caged_fire;1341996]Linker errors can be quite hard to track down so without any code to examine the job is made ever so slightly more difficult ;) Post up some of the code that you think could be associated to or causing your problems. Side note: Your punctuation and grammar is quite … | |
Re: I'm not sure why you posted this 3 times, but it's really not an advisable habit to get in to... In ini_count(), you appear to read to the end of the file. Because of that, and since I don't see any sort of reset, I'm guessing your eofbit flag is … | |
Re: I can think of a couple ways, but the best one depends on your answers to these questions: [list=1][*]Is there a particular reason it needs to be 1 and -1? [*]Can it be 1 and 0? [*]Is 0 considered "off" for the purposes of this exercise? [*]If 3 is yes, … | |
Re: Okay. That's nice. Is there a question in there somewhere? | |
Re: Q1: Hmmm.... Something like this has alot of overlapping constructors and function calls, it's an exercise in using resources efficiency. I'm actually working through a similar situation on a project I'm working on right now. This is how I'm approaching it: To prevent multiple re-allocations of the vector as it … | |
Re: Your phrasing is a little awkward, so I might be missing something. But, if I'm understanding your question correctly, you should be able to simply break it into 2 input statements. [CODE]inFile >> face >> suit;[/CODE] Then, you can manipulate or store face and suit as you see fit. | |
Re: C++ automatically "promotes" values to the appropriate data types for certain operations. An int can be promoted to any of float, double, or long double. As a result, any of those versions of the function is an appropriate function call. To get around it, simply cast the first argument to … | |
Re: [QUOTE=Akill10;1337799]Why do you want to return 0? What is it you are trying to make your program do?[/QUOTE] Returning an int from main() is what is required by the standard. The normal return from main() to indicate no errors occured is zero (0). Thus, the absolute minimum standards-compliant program is:[CODE]int … | |
Re: [QUOTE=frogboy77;1341888]been at this 2 months taking one step at a time using whats there first before thinking about importing more not avoiding it just learning thanks for the help i'll figure it out. remember when rebuking someone "one must learn to walk before one can run." if i was unwilling … | |
Re: Once you have entered "number", you should not change it again. You then need to use a different variable, usually called 'i' (but it can be called anything you like), to control your loop. [CODE]cout << "How many numbers: ": cin >> number; for (int i = 0; i < … | |
Re: :icon_eek: >>Huh??? Glad I'm not the only one that didn't get it.... :confused: | |
Re: Pointers and references are similar and are both used under similar circumstances. Really, a reference is just a pointer without all the extra syntax, but they are not freely interchangable. Which syntax you use for function calls depends on how the function being called is defined. Both are frequently used … | |
Re: [QUOTE=Chris Bruner;1219162]I've got a library which you can obtain at [url]http://code.google.com/p/crylib/[/url] using subversion. It's basically my playground for learning and exploring some concepts. It was written using cbuilder, and gcc so it should be compatible with your system. The wiki gives a bit of an intro to some of the … | |
Re: I've noticed a similar behavior with the "Threads I've Posted in" button. It seems there is a lag in it. How long it takes to add threads seems fairly random, sometimes as much as an hour. Once added, the new posts behavior is fine. Perhaps it's some sort of cached … | |
Re: You'll have to post your code that handles the output. I don't see any "missing" tags, but I do see some missing newlines. | |
Re: How do you want it to look? If you only want "The CTEC students taking COSC 208 are: " to appear once, take it out of your loop. It's a pretty simple fix. | |
Re: With a loop:[CODE] for (int i = 0; i < vector.size(); ++i) { /* add them up */ }[/CODE] | |
Re: [B]>>Can anyone post the code to these? [/B][URL="http://www.daniweb.com/forums/announcement8-2.html"]Nope.[/URL] | |
Re: [URL="http://www.daniweb.com/forums/announcement8-2.html"]And what exactly have you done?[/URL] | |
Re: [URL="http://www.daniweb.com/forums/announcement8-3.html"][B][COLOR="red"][noparse]I'm sorry, I can't read your code very well.[/noparse][/COLOR][/B][/URL] Are they full state names or abbreviations? Either way, I doubt you need strings that are 50 chars long. Unless there is one I'm missing, you should only need about 20 chars. | |
Re: Boy, I would have done this with an enum, but it sounds like you can't. Can you use a switch? [CODE]switch (asciiGrade) { case 65: qpts = 4; break; case 66: qpts = 3; break; /* etc... */ }[/CODE] It works just like an if ... else, but it's not … | |
Re: The extraction operator breaks the input when it detects a whitespace character. At the end of each input line there is a newline, which is a whitespace character. The newline character is not extracted and is left in the input stream as a "dangling" character. This occurs most often after … | |
Re: >>THAT ****ING CONST Is there to assure you that the file name will not be changed on you while it's creating the file and is entirely appropriate. You should not try to circumvent it. Please post the code of your "save as" function so we can see what you are … | |
Re: You corrupted your input stream, you need to reset it and remove the offending char(s). You will need to use [URL="http://www.cplusplus.com/reference/iostream/ios/good/"]ios::good()[/URL] or [URL="http://www.cplusplus.com/reference/iostream/ios/fail/"]ios::fail()[/URL] to detect the stream corruption. You will then have to use [URL="http://www.cplusplus.com/reference/iostream/ios/clear/"]ios::clear()[/URL] to reset the stream. Then you will need to use [URL="http://www.cplusplus.com/reference/iostream/istream/ignore/"]istream::ignore()[/URL] to "throw away" the … | |
Re: You'll have to store the return value. Right now, the return values are all being discarded. To store the return, declare a variable of the same type as the return, then use the assignment operator with a function call on the right of the assignment.[CODE] #include <iostream> using std::cout; using … |
The End.