2,712 Posted Topics
Re: You need to define what exactly you mean by limit. For example what should happen in the sixth character? Should the program just go with the first five character or should the program output an error message if more that 5 character is entered or should the program enable the … | |
Re: The first thing I see is this : [code] int main() { //called functions void userData(string studentName, int numOfClasses, char letterGrade); double calData(int totalPoints, int numOfClasses); void displayData(string studentName,char letterGrade, double gpa); getch(); return 0; } [/code] which is wrong and should be this : [code] int main() { //called … | |
Re: Or you can get the input as a string and just access the first digit from there | |
Re: >>[B]Note: Im planning on using this with a Message box[/B] If so then you will need to convert the variable to a string if its not already. A handy tool is to use something like the following : [code] template<typename ReturnType, typename InputType> ReturnType convertTo(const InputType& input){ std::stringstream stream; //#include … | |
Re: [icode]struct car cobalt [/icode]. car is not a pointer. I believe you want something like so, [icode] struct car cobalt[23] [/icode]. In that case you could use the same notation as for regular arrays. For class object there is a special pointer operator[icode]cobalt->gas[/icode]. Notice the "->" operator. For class objects … | |
Re: Just note( I may be wrong but its worth thinking about ): They will teach you theoretically that linked list are fast for insertion in the front, middle, and end of the list. Fast in terms of theoretical comparison of big-omega. While theoretically this is true, in practice, you will … | |
Re: A suggestion is to make a get() function that checks for errors, for example : [code] template<typename InputType> InputType getType(){ InputType var = InputType(); while( ! (cin >> var) ){ cout << "\nInput failed...try again : "; //print error message if failed cin.clear(); //clear the error bits while(cin.get() != '\n') … | |
Re: It does that because the number extracted is in base 10. | |
Re: Dude just use [icode]if( x % 100 == 0){ x= 1; } else ++x;[/icode] | |
Re: [QUOTE=alex55;1460923]1 is consistent throughout the entire program in all the arrays would that still affect it?[/QUOTE] If you ever do [I]monthAverage[0], monthSum[0], or monthInput[0] [/I]it will be garbage! But your problem is with your for loop condition. In all of your for loop you use [I]i <= someVariable[/I]. The problematic … | |
Re: Use action listener for each unique button category. For example, just a simple idea is to make a action listener for the numbers and have a actin listener for the functions. Here is a non-compiled on the spot simple example : [code] class Calculator extends JPanel{ private ArrayList<JButton> numbers; private … | |
Re: I don't know any sites but [URL="http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=function+pointer+C%2B%2B"]google[/URL] does, and it spat out [URL="http://www.newty.de/fpt/index.html"]this[/URL] site first. Try it. | |
Re: Are you really trying to use meta-programming to create an array of site t? | |
Re: To polish it, you can combine the words[] and numbers[] into one std::pair<string,int>; And your search in GetNumber could be just, [icode]numbers[ words.find_first_of(number) ][/icode], but be careful about error checking. And make the parameters const-reference. This code [code] std::string tempString; size_t size = sentence.size(); for (size_t i = 0; i … | |
Re: Depending on the exact content, the node class might have to be-friend the list class in the second case, while in the first one it does not. | |
Re: Two options: 1) You can output 2 decimal places 2) You can change the actual precision of variable to 2 decimal places For option number 1, here is an example : [icode]float f = 1.23456f; cout.precision(3); cout << f;[/icode] and for option number 2, here is an example : [code] … | |
Re: You have to find the start and end position of the quoted text. In C++, using std::string you can use the following call to find the first quote position [icode]stringVariable.find_first_of("\"")//find the first '"' [/icode]. So you can use "\"" to represent a quote character. | |
Re: use can use [i] string.erase [/i] with [i] isspace [/i] | |
Re: Just an example : [code] #include <iostream> #include <vector> using namespace std; struct Person{ int age_; float gpa_; Person(int age = 0, float gpa = 0.0f) : age_(age), gpa_(gpa) {} }; ostream& operator << (ostream& stream, const Person& p){ return stream << "[" << p.age_ << "," << p.gpa_ << … | |
Re: [URL="http://oopweb.com/Assembly/Documents/SPIM/Volume/Floating%20Point%20Instructions.htm"]http://oopweb.com/Assembly/Documents/SPIM/Volume/Floating%20Point%20Instructions.htm[/URL] It basically converts a single precision into double precision and puts it in an appropriate register. | |
Re: Save all names into an array, and then use a while loop to display the array. | |
Re: Yes, use delete when new is used to allocate that memory, and forgot about malloc and free if you are in C++ world. Check here for more info. [URL="http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.3"]http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.3[/URL] | |
Re: You can't shuffle map. A Quote from C++ Reference [QUOTE]Internally, map containers keep their elements ordered by their keys from lower to higher , therefore begin returns the element with the lowest key value in the map[/QUOTE] so you just made a poor choice in data structure. I suggest you … | |
Re: Well what do you intend to use the heightmap for? One use for them is to create a terrain based on the heightmap. For example, you would use the heightmap values to map the height of the plane at a given point. | |
Re: To get what you want, you need to read it as a string, and then parse the string. Some example : [code] string str; cin >> str; //for example assume user enters 11:22:33 string::size_type hourEndPosition = str.find_first_of(":"); int hours = atoi( str.substr(0,hourEndPosition) ); string::size_type minuteEndPosition = str.find_first_of(hourEndPosition+1,minuteEndPosition); int minutes = … | |
Re: Just a wild guess at what you want but a negative number can be represented in a string simply by the negation operator like so : [icode] string negativeFive = "-5" [/icode]. Then if you want to convert it back, then you can check if [icode]negativeFive[0] == '-'[/icode] and if … | |
Re: Umm what exactly do you have in mind? Your questions isn't to clear for me. | |
Re: I think you can have an algorithm that does this in constant time. I'm not sure why you have so much code[ didn't bother to look ]. Try to formulate a formula for a given range. | |
Re: [QUOTE=Fbody;1454559]??? I'm glad you know what that means. It just looks like spam to me... I'm tempted to report it for not being written in English.[/QUOTE] [ICODE]这么明显的错误你都发现不了?你到底是不是C++编程人员[/ICODE] is in Chinese and maps to [ICODE]Such an obvious mistake you can not find it? You in the end is not C + … | |
Re: >>[B]error C2057: expected constant expression[/B] corresponds withs this[icode]double term[sizeofpolynom];[/icode]. The reason being is [i]that sizeofpolynom[/i] isn't known at compile time. Because the user can pass it anything. So to solver this there is a couple of things you can do, but the easiest way that I suggest is to use … | |
Re: @Fbody: I think that statement you posted is intentional. I have a feeling that it uses return values to signify success or not. So the if statement checks if the return value is a success or a fail. A fail probably returns 0. | |
Re: Just create a std::map with all of the reserved words, and check for them using that. And for your post script, unique just means there is only one of. | |
Re: You are using depreciated header files, take out the [b].h[/b]. And [b] int main [/b] is in these days. And you need to either use fully qualified name or use the using declaration. [code] #include<string> #include<iostream> int main(){ using namespace std; string str = "My name is shridhar"; cout<<"What is … | |
Re: I think something like this should work : [code] #include <fstream> #include <iostream> #include <string> #include "CommonFunctions.h" using namespace std; struct BitmapInfo{ unsigned char id[2]; unsigned char size[4]; unsigned char unUsed[4]; unsigned char pixelOffset[4]; unsigned char bytesInDIBHeader[4]; unsigned char width[4]; unsigned char height[4]; BitmapInfo() : id(), size(),unUsed(),pixelOffset(),bytesInDIBHeader(),width(),height() {} }; int … | |
Re: You want something like this : [code] int getIntGrade(char letter){ if(letter == 'A' || letter == 'a') return 95; if(letter == 'B' || letter == 'b') return 85; //and so on } [/code] And if you want to go the other way it would look something like this. [code] char … | |
Re: Forgot to include the [I]string[/I] library. | |
Re: Programming is logical. So you need to train your self how to think logically. Some people compare programming with math because they both require perfect logic. So my suggestion is to change your mind of thought. Train yourself to think more logically. One way to do this, is to do … | |
Re: Just looking at your main, specifically this part : [code] mySolver.setMathematicalMethod( pointerToMathematicalMethod ); mySolver.solve(); [/code] intuitively, I would expect [i] mySolver.solve()[/i] just delegate the job to the mathMaticalMethod. So what I am trying to say is that your computeValue(...) function in your mySolver doesn't make sense to me. It should … | |
Re: [QUOTE]Is set theory like arrays in C# and C++ for example?[/QUOTE] No no where close. Set theory is a branch of mathematics. Check [URL="http://en.wikipedia.org/wiki/Set_theory"]here[/URL] for more info. | |
Re: Print out your "input" and see if its correctly formatted. Make sure you account for the spaces. Have you learned about classes and structures? >>[QUOTE] I don't want to cheat. This is my major and I have a passion for it, but I can not find this answer in my … | |
Re: There is some problems with your code, right now I'm too lazy to point them out and try to explain it all. Instead I will give you a push in the right direction to achieve what you want to do. First you want to make use of std::string and std::vector. … | |
Re: First of, can you use [i]std::string[/i]? | |
Re: Are you interpreting the data in [i]std::vector<char>[/i] as big-endian or little-endian? To reverse the process you an just shift right and use the bitwise and operator. So just to get this straight, you have a std::vector<char> full of whole unsigned digits correct? And if the user wants to read say … | |
Re: Check out [URL="http://en.wikipedia.org/wiki/BMP_file_format"]wiki_bitmap[/URL]. It has good explanation of how bitmaps are formatted. From there you can determine how to read the width/height, and the starting offset of where the actual pixels starts from. | |
Re: As said earlier, you aren't using the template correctly. In your "SetName", if a template instantiation is made of type double, then you will have a compiler error, because you can't assign a double to a string. | |
Re: Are you using solely C++. What platform? Does it have to be a portable solution? Can you use anything else? | |
Re: Truthfully, that gives absolutely no advantage, bloats code, makes it hard to read, and is probably slower( although not noticeably ). And as your friend suggest, and your ego denied, its just bad coding. Drop this like a bad habit. |
The End.