1,358 Posted Topics
Re: Inline functions can be finicky. As I understand it, because they don't have execution jumps they don't generally work unless they are part of the compilation unit* you are attempting to use them in. This lack of jumps makes the linker unable to find them if they're not already in … | |
Re: [QUOTE=dospy;1654718]that's not the name of the structure, it's an instance of and unnamed structure basically when you declare a structure without naming it, you are not allowed to create any instances of it, thus the only way to create and instance is by putting names(separated by commas) after the struct … | |
Re: :confused: I know gerard "mis-spoke", but is this supposed to be an extension to your question or am I missing something here? Did gerard answer your question sufficiently? | |
Re: [QUOTE=dospy;1654700]i figured it out thx to you Narue, i appreciate your effort, now, one more last thing, is there any other way to specify the command line arguments than by running the program through the cmd followed by "$ ....."?[/QUOTE] As mentioned, you should be able to do it through … | |
Re: In your code, you have an attempt at a default constructor:[CODE]fraction() // default constructor { numerator = 0; denominator =1; }[/CODE] Unfortunately, because your capitalization isn't correct, your compiler won't recognize it as your default constructor. Remember, C++ is [B]case-sensitive[/B]. This means that "fraction" is not the same name as … | |
Re: [QUOTE=Epicurus;1654496]Aren't you forgetting something? The arrows maybe?[/QUOTE] Aasking for rep is generally frowned upon and not a good idea (it's kind of rude actually). A post like this can net you some serious neg rep., especially if a mod or a partner gets hold of you. @OP: Assume you have … | |
Re: [QUOTE=joon920721;1654563]I want to make a program that asks to enter number. The program will keep asking for entering number until the user enters -99. And when the program finishes, it will give the number of counts, max, 2nd max, min, and 2nd min. The program I made works for all … | |
Re: If this is only a temp to store the line from the file, use a std::string object. This way you should be able to avoid an extra vector* and do something like this:[CODE]std::string inputLine; getline(inFile, inputLine);[/CODE] Then analyze/tokenize inputLine and push the substrings into your final vector. *A std::string is … | |
Re: Your Algorithm object in your Graph class needs to be a pointer, not an actual Algorithm object. For polymorphism to work properly, you need to use pointers. I also notice that your non-default Graph constructor is designed to pass your Algorithm object by value; this is not only slow, because … | |
Re: Do you have any experience with C++ at all? Your post seems to imply that you don't... Consider this a friendly warning: Don't jump directly into OO if you don't have any experience with C++, the OO parts of the syntax are much more complicated. Make sure you have a … | |
Re: I don't see any return statement but you've specified the function to have a string return. Have you tried re-specifying the function as a [B]void[/B] function so that you don't need the return statement? | |
Re: [QUOTE][CODE]struct RandomChooser{ RandomChooser(){ srand( 0 ); } RandomChooser( const RandomChooser& RC ){} template< typename T > inline T Choose( const T& item_1, const T& item_2 ) { return (rand() % 2) ? item_1 : item_2; } };[/CODE]The situation is slightly complicated because you only want one call to srand once, … | |
Re: [QUOTE=ambigouscase;1650902]I don't know how to create a program with that problem :([/QUOTE] That's a textbook lazy response right there. If you already knew how to create that program, it wouldn't have been assigned. Figure it out, we all had to at some point. First, get out a pen and pencil. … | |
Re: This smacks of a design issue and begs a few questions: If you're not going to use it,why do you have the derived version of the function at all? What is so different about the "m2" version that you feel you need to call the "m1" version instead. Are the … | |
Re: What do you think you have wrong? Your compiler is telling you the whole story. Did you even look at your code before you tried to compile it? What I can see right off the bat: [list=1][*]There are no headers #included. You can't access any library functions without including the … | |
Re: Wow, I would tend to agree. Something this short on information and detail should never even have been acknowledged as a viable application. Samsung should sue/file/... for revocation of Apple's certificate on grounds of excessive generality. >>Did anyone notice that the design "patent" that apple uses against Samsung has no … | |
Re: You can string multiple outputs (including stream manipulators such as setw()) together:[CODE]cout << "Loan Amount: " << setw(12) << "$ " << setw(8) << L << endl ;[/CODE] | |
Re: [QUOTE][CODE]/************************************************************************** * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and * * Pearson Education, Inc. All Rights Reserved. * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing … | |
Re: I think you need to provide a little more information about your intentions. Are you trying to plot just the integer part of a floating-point value (i.e. if you have 3.14, you want just the 3) or do you want to convert a value such as 3.1415 to 31,415? | |
Re: [QUOTE=Anirudh Rb;1650272]How do I check whether the data members of two objects belonging to the same class are equal? Will the following code do or is it done in some other manner?? [CODE=C++] class Sample { int a; public: S(int x) { a = x; } int getA() { return … | |
Re: What seems to be the issue? Your output isn't formatted at all, but other than that, I can't discern what your issue may be. | |
Re: First, your "success" variable/parameter/argument: Either remove it from your program completely, because it really serves no purpose, (especially since you are passing it to your function [B]by value[/B] instead of [B]by reference[/B]) or make it more useful by actually checking it's value and reacting accordingly. Second: you can not use … | |
Re: May I suggest viewing [URL="http://www.daniweb.com/software-development/cpp/threads/280189"]this thread[/URL]? It seems to be a discussion that is relevant to your situation. What it boils down to is creating an inheritance hierarchy that makes sense for shape analyses. | |
Re: Use the appropriate version of getline() to read the file line-by-line, reading each line into either a std::string object or a char array. Then, after you've read a line, use a loop to review each char in the read line. If the char is a digit either store it some … | |
Re: Honestly, I think you're going about it the wrong way. If you adjust your thinking, I think you'll solve your dilemma. I suggest that you check to see if the counter is greater than 0, but [B]not equal to[/B] 5. That way, depending on the value produced, after each iteration … | |
Re: The problem is that the char 'M' is not the same as the char 'm'. You have attempted to "normalize" the user's input, which is correct, but you don't have it in the correct spot. Move Line 9 to Line 13 so that the "normalization" occurs [B]after the user's input[/B]. … | |
Re: What are you lost about? Are you having compilation issues or getting unexpected results? One thing that I'm noticing is that you don't have a default constructor for your "testClass" class. You are going to need one to be able to create "obj3". Also, I see that your arguments for … | |
Re: It's certainly possible to put data into multi-dimensional arrays, but there is not enough information here to get a good grasp of the problem you're trying to solve. Where is the data coming from and how do you intend to use it? | |
Re: How do you intend to use this? Why wouldn't a simple std::vector<std::string> be sufficient? | |
Re: Generally video tutorials are pretty crappy. [URL="http://www.cplusplus.com/doc/tutorial/"]Here is one that should give you a decent starting point.[/URL] There are other, more-detailed, ones available; this should get you started though. | |
Re: That's because "stdafx.h" is a VS-specific thing. If you open the actual file, you should see the #include statements for the standard C++ headers that you need. | |
Re: I'm not real sure what I would do, I know it would be likely to involve family. I'm not too worried though; for blessed are those that endure to the end. | |
Re: The file you are missing ("MSVCR80D.dll") is the Visual C++ [B]2008[/B] RunTime. The file that you have ("MSVCR100D.dll") is the Visual C++ [B]2010[/B] RunTime. Search Microsoft's site for "Visual C++ 2008 Redistributable". Download the correct version (x86 vs. x64) and install it. There are some service packs/updates available for it. … | |
Re: If your instructor/prof told you this was C++, they lied. This is C (with some errors). C code will work/compile on a C++ compiler because of how the languages are related to each other, but it's not technically C++ because of how it's written (the headers used, and no namespaces). … | |
Re: [URL="http://www.cplusplus.com/doc/tutorial/"]Otherwise, you could learn to write C++.[/URL] It's really not that difficult to learn, if you're patient. | |
Re: [QUOTE=coolbeanbob;1634007]Hello, I am trying to figure out how to get the rand() function to include 0. [CODE]int value = rand() % range + 1;[/CODE] No matter what I set range to be, the lower bound is always 1.[/QUOTE] You have the right basic idea, but you've not delineated your code … | |
Re: [QUOTE=pecet;1113312]You cant use [ICODE]int[/ICODE] for such big numbers as 100!, since [ICODE]int[/ICODE] usually can handle 32bit value. solution is google: "c++ big integer"[/QUOTE] 1.) I suggest you take a closer look at your datatype limits. A 32-bit signed integer can hold values ranging from about -2.1 billion to +2.1 billion. … | |
Re: Do you want an integer that is 20-[B]Bytes[/B] or 20-[B]Bits[/B]? The int32 and int16 types are 32- and 16-[B]Bits[/B] respectively. | |
Re: I'm having trouble following your code for some reason; I think it may be due to the lack of comments. I noticed that your variable names aren't that great. I suspect that name/member/scope hiding is part of your problem. When you name a member function's local variables the same as … | |
Re: [QUOTE=FriXionX;1630130]Yeah just as you posted, just before I looked, I remembered about the default.. i'm such an idiot, lol.. And really? It worked before. I had that if() before, but am deciding to practice switch statements because apparently they're more widely used for larger stuff. ah well, thanks.[/QUOTE] Writing the … | |
Re: Q. Your char array is 4-chars long. What are the elements it produces/contains? A. It produces/contains elements keydata[0] through keydata[3]. Q. Have another look at Line 18. What element are you attempting to access? A. You are attempting to access element 4, which does not exist because it is the … | |
Re: [CODE]printf("%d", b[i]);[/CODE] C++ is a super-set of C. Which makes the code valid C++ as well. If you want to use a strictly C++ construct, you'll have to use the <iostream> header instead of the <stdio.h> header (<cstdio> in c++) and use the [B]cout[/B] object:[CODE]std::cout << b[i] << std::endl;[/CODE] | |
Re: You'll have to elaborate on the equations/functions you were given in your assignment before we'll have any clue about how to help you. Even then, you'll have to do some of the work yourself. We're not going to just hand you a ready-made solution to turn in to your prof. … | |
Re: The size of an array (in bytes) is determined by the size of a single item in the array and the number of slots the array has. If you have an array of int that has 4 elements, the size of the array is [TEX](sizeof(int) * 4) = (4 * … | |
Re: [B]>>Would this effectively make 8 booleans using just 1 byte?[/B] In theory, yes. But the behavior of bit fields is implementation specific. The best way to tell for sure is to display the result of a call to sizeof(BooleanStruct). [B]>>Is there a way to use some looping in order to … | |
Re: For starters, when dealing with money, a transaction is almost never an even-dollar amount (or whatever unit of currency you use). You should deal exclusively in floating-point data types (i.e. "float" or "double") and avoid integer data types. Second, your equation for calculating a withdrawal (Line 25) actually gives the … | |
Re: Let me start by saying that this project seems awfully simple for a final C++ project. There are no data structures, objects, or pointers. I also don't see any includes or namespaces. Remember, main() is a function. [URL="http://www.cplusplus.com/doc/tutorial/functions/"]Do you place a semi-colon after the head of a function?[/URL] No. This:[CODE]int … | |
Re: In overly simplified terms, a Reference is a simplified form of a pointer. They work similarly, but they don't have all the extra syntax, and aren't quite as powerful. | |
Re: @OP: Can you provide more information about the context and/or use case of your program? It seems odd to me that you would have to do what you are proposing for what sounds like an extremely simple program... | |
Re: [QUOTE=manugm_1987;1627317]How can you convert string to an string array?? Use pointers and increment the pointer to concatenate ur strings string *str1,*str2; for(;; ) if(str1++!=".") str2++=str2++ + str1++; Hope this is works[/QUOTE] There is WAAAY too much undefined behavior here. Not to mention you're de-referencing uninitialized pointers. Odds are, it won't … |
The End.