2,712 Posted Topics
Re: Oh so you mean in 1 location, there can be up to 3 treasures. Can you show me how are are setting up your 2d array. The size and whatnot. | |
Re: I commented on your actual code. I comment it as I read it. [code] //Good, gaurds are good, but name them something useful like // MATRIX_H_ #ifndef GUARD_MM_info #define GUARD_MM_info #include "stdafx.h" #include <vector> #include <string> #include <iostream> #include <utility> #include <algorithm> class Matrix { public: //I like this typedef, … | |
Re: First take srand( time(0) ) out of the constructor. Put srand( time(0) ) at the beginning at main. Second do this : [code] strength = (rand() % 20) + 8; dexterity = (rand() % 20) + 8; [/code] So that way they both get different values range from 8 to … | |
Re: I will be glad to help, first to start out. Here are some guidlines. 1) Get a IDE, I suggest one of these, [URL="http://www.codeblocks.org/downloads"]codeblocks[/URL] or visual studio 2008. 2) Now you need to start making projects, so google online on how to make projects with either codeblocks or visual studion, … | |
Re: I can implement it for you for $100.00 US dollars. | |
Re: >>Or even better: I beg to differ. Not only is that hard to read, but also harder to understand, plus it leave the user to remember to delete the object returned. @OP: I advise you to use string, but if this is for learning purposes, then you can do something … | |
Re: >>what would best way to approach this in order to combine these 3 functions into 1? The best way to do this is to not do it. Functions are there to help create more readability for the coder and the reader. The more the better. By trying to combine functions … | |
Re: Your syntax is wrong. You need to use the [URL="http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/cplr016.htm"]scope resolution operator[/URL]. So your call would look like this [i]myEngine::GeneralCore::WindowManager:: DisplayWindow()[/i] | |
Re: The maximum value a int can hold in java is [i] [b] 2,147,483,647 [/b] [/i] while [i] [b] 13! = 6,227,020,800. [/i] [/b] So you see that an int cannot hold 13! or higher. Its only big enough to hold 12! or less. | |
Re: First this constructor : [code] Student::Student(){ int *gptr; gptr = new int grade[3]; } [/code] is incorrect, it has a memory leak. You already have declared a gptr in your .h file, so you can just delete [i] int *gptr [/i] thats inside the default constructor. Second I don't see … | |
Re: There are a couple of options. 1) Use std::vector< std::vector > 2) Use dynamic arrays 3) Create a static array, with big enough size, and get the limited user's input as size. And use that variable, as the max size. | |
Re: Example: [code] class list{ public: class Node{ }; }; list::Node n; //declare a Node object [/code] | |
Re: Why do you need centimeter and meter, you can just work with meter. Centi is just an extension of meter? And come to think of it, your just scaling the width and the height. It makes no sense to me, to put that in the constructor. It should go as … | |
Re: Just use strings. [code] std::string input; std::string pass = "file.txt"; cin >> input; if(input == pass){ /* success */ } else { /* fail */ } [/code] | |
Re: Have you converted the x and y variable into world coordinates? Does graphCalculation takes the mouse coordinate in world space? Or does it want to raw pixel points? Can you show how the graphCalculation function looks like? Can't really help without more info. | |
Re: a better solution would be to define an operator>>. For example : [code] std::istream& operator>>(istream& is, Client& c){ return is >> c.acccount >> firstName >> lastName >> balance; } //...in main somewhere Client c; while( file >> c) vectorVariable.push_back(c); [/code] | |
Re: wait are you supposed to sort the rows first, and if there is any collision, like 2 values are the same in the rows, then you use the columns to resolve the conflict if possible? | |
Re: >>how would one define RANDOM FILES [code] string randomFile = "randomFile.txt" [/code] >> well as suggest ways of creating [code] ofstream newFile(randomFile.c_str()); [/code] >>updating them in Visual C++ "Updating" is subjective, what kind of update? If you want better answer, We need better and more specific questions. | |
Re: >>fromBinaryToDecimal To convert from binary to decimal you use the expansion rule. For example : convert "1010" to its decimal value. To convert 1010 into a decimal value, we note the position of each bit. [code] [COLOR="Red"]3 2 1 0 [/COLOR]//position of each bit 1 0 1 0 //binary number … | |
Re: It seems like you just wan't to ask question and not do any reasearch, i.e be lazy. Did you think google did not have an answer to this question? Google has answers to all. Here is a [URL="http://lmgtfy.com/?q=c%2B%2B+class"] answer [/URL] to your question. | |
Re: I can have this done for you in a hour or so, but its gonna cost you $100.00 dollars, or $130.00 express. | |
Re: Well thats what a for loop is for. Or you can use strings [code] string sent = "ILoveYouMary"; string sub = sent.substr(5); //"YouMary" [/code] | |
Re: Instead of making things global, why not make your function take in a _aline as a parameter? For example [i] ReadConfig(const _aline* line){ /* work with line variable */ } [/i] And all you have to do is make sure that you can call ReadConfig from your file. | |
Re: What part of C++ troubles you, my young lad? | |
Re: >>What if I want the output to be ANY float rand() has a limit on the highest number it can return, specifically RAND_MAX. So if you want to output any float number you need to adjust accordingly( or use a better RNG). | |
Re: Put it into a vector, then randon shiffle it, and get the first element. Here is an example: [code] int doIt(){ declare std::vector<int> variable; while input.isgood, put input into variable. call std::random_shuffle with variable; print variable[0], a random number from the list of inputs given. } [/code] | |
Is it just me, or does it seems that people posting here are getting dumber and dumber? Dang if its this hard for you then, go work at McDonalds or something. | |
Re: Oh wow. This is so shocking. At least, now he's in a safe place with nothing but happiness. Dave, if your listening, say hi to Jesus for me. | |
Say you have a class Foo, and it contains some member variables. And in that class you have a const-correct function. Can you code some way in C++, that changes the private member variable, inside the const-correct function. For example : [code] class Foo{ int num; public: void doIt()const{ num … | |
Re: Make a simple timer class to simplify stuff. For example : [code] #include <iostream> #include <ctime> using namespace std; class ClockTimer{ public: typedef time_t TimeType; private: TimeType startTime; public: ClockTimer(): startTime(clock()){ } TimeType elapsed(){ return clock() - startTime; } TimeType elapsedInSec(){ return TimeType(elapsed()/float(CLOCKS_PER_SEC)); } void start(){ startTime = clock(); } … | |
Re: You need to pass it an iterator!!!!!!!! Even you said it. But when you use the operator[], on a vector you are de-referencing it! Which means you access the elements stored, in your case its a string. So basically, now you are left with trying to turn a string into … | |
Re: Think about it first. If you have a string like so : [i]string sentence = "This is a sentence that needs to be splitted";[/i] how would you go ahead and get word by word? How would you start? Use this as an exercise. | |
Re: I wrote this DateClass some time ago, see if you find a use for it. Study carefully and you might find what you wanted. [code] #pragma once #ifndef DATE_TIME_H_ #define DATE_TIME_H_ #include <ctime> #include <string> #include "CommonFunction.h" using std::string; typedef unsigned long ulong; struct DateInfo{ ulong seconds;//current seconds ulong minutes;//current … | |
Re: Here are some, [URL="http://docs.sun.com/source/806-3568/ncg_goldberg.html"]What Every Computer Scientist Should Know About Floating-Point Arithmetic[/URL]. [URL="http://programmingexamples.net/index.php?title=Main_Page"]Programming Examples[/URL] [URL="http://ootips.org/yonat/4dev/smart-pointers.html"]Smart Pointers[/URL] | |
Re: The right way depends on the situation. But I would suggest to do something like this: [code] #include <vector> struct Book{ string _name; string _author; float _price; //...more info Book(const string& name,const string& author, float price) : _name(name), _author(author), _price(price){} }; int main(){ std::vector<Book> listOfBooks; listOfBooks.push_back( Book("America","Obama Hussian", 59.95); //add … | |
Re: >>[B]*array[4]; // pointer to 5th content of array.[/B] The above is correct only if array is declared as [i] DataType*** array [/i], because you deference it twice. If you declare array as [i] DataType array[] [/i] then [i]*array[4][/i] is invalid syntax, because you are using the dereferencing operator on a … | |
Re: For #2, iterators are just classes. They have certain operation defined for them. For example they define the deference operator, which is why you can deference them. Similarly, the library does not define the operator << for the iterators, thus it is a compiler error. For #3, "selection < gameLibrary.end())" … | |
Re: You should be fine, but you can always separate your logic : [code] if(condition1 && condition2){ /*logic here */ } if(condition1){ if(condition2){ /* logic here */ } } [/code] But,you don't even need isOccupied variable, if you default initialize player to null, in the class, then you can just check … | |
Re: [QUOTE=Rickay;1279718]Thank you, I actually figured that out about a minute after posting that hehe... but another question along those same lines if thats okay. How can I use an if statement to decide whether the input is a character or an integer? [CODE]if(x == char) //code here... if(x == int) … | |
Re: A int is not going to hold a number that big. Use [i] __int64 [/i] instead. [code] __int64 n = atoi("11111111111111"); [/code] | |
From project euler : [code] By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. [COLOR="Red"]3[/COLOR] [COLOR="red"]7[/COLOR] 4 2 [COLOR="red"]4[/COLOR] 6 8 5 [COLOR="red"]9[/COLOR] 3 That is, 3 + 7 + 4 + … ![]() | |
Look [URL="http://www.spoj.pl/problems/ADDREV/"]here[/URL] for a complete description of the problem. Your code should follow the coding standards, good names, spacing, easy on the eyes...etc. Make sure you handle all test case and boundaries. Good Luck, and happy coding. Although this is a C++ forum, it would be nice to see some … ![]() | |
Re: Can you show more code. It looks fine to me. | |
Re: Yes, I charge by the hour. The rate depends on the project. Can you supply more info. | |
Re: I think you are looking for random number generator. Here is an example : [code] #include <iostream> #include <ctime> int main(){ srand(time(0)); //seed random number generator for(int i = 0; i < 5; i++){ for(int j = 0; j < 5; ++j){ int randomNumber = rand(); //use rand() function to … | |
Re: Here is what I got : [code] #include <iostream> using namespace std; template<typename T> void printN(T arg, int n){ while(n--)cout << arg; } int main(){ const int ROW = 9; for(int r = 0; r != ROW; ++r){ printN(ROW, r); printN('*',ROW - r); cout << endl; } return 0; } … | |
Re: [B]>>fstream FILE[/B] Change the name from FILE to something else like file, because you have a name clash with the standard FILE defined in cstdlib header file. | |
Re: >>Strings used to be an array of char in C-style coding. Now they're objects in C++. Forget about what it used to be is C. std::string is a class. An instance of a class is called an object, so [i] std::string name [/i], here name is an object, because it … | |
Re: The best thing to use is std::map here. That will give you very good performance. Here is an example : [code] #include <iostream> #include <map> #include <string> using namespace std; typedef pair<string,int> NamePair; int main(){ std::map<string,int> listOfNames; listOfNames.insert( NamePair("jeff",0) ); listOfNames.insert( NamePair("Don",1) ); listOfNames.insert( NamePair("Calvin",2) ); //or read from a … | |
Re: >>string word2("Over"); >>string word3(3, '!'); The string class, has the proper constructor that allows those syntax. So it calls the string class constructor. Other that that, i'm not so sure about your question, maybe its because i'm tired. |
The End.