2,712 Posted Topics
Re: You could use a gui library, possibly QT or wxWidgets or create your own | |
Re: >>Even on an embedded system, that is hardly a memory hog. How about calculating 100! or 1000!, putting aside the limitation of data-type of course. Anyways, usually tail recursion can be removed by compiler's optimization. OP have you learned about functions? Try to modularize your code by using functions. [code] … | |
Re: What is the problem? If you can't use std::vector, then why not use std::list? Why are you using memcpy? Just use operator= for more clarity. | |
Re: Dont read it line by line. Instead, read it word by word. The check if each word is a valid real number. Example: [code] int main(){ ifstream fileIn("input.txt"); string word; unsigned int count = 0; while( fileIn >> word ) { if( isRealNumber( word ) ){ //you need to implement … | |
Re: I kind of like the idea of unary plus being an absolute value sign. Right now, the unary plus is nothing more than extra information to the user. Maybe to hint to the user that it should always be a plus or something. It has no effect. | |
Re: Use std::strings [code] int main(){ string label,topcode,toperand; ifstream fileIn("input.txt"); while( fileIn >> label >> topcode >> toperand){ cout << "Label = " << label << endl; cout << "TopCode = " << topcode << endl; cout << "Toperand = " << toperand << endl; } } [/code] | |
Re: You should use the getline function, which reads the first line from input. Then you can use the first character to determine the proper equation to use. Here is an example. [code] string line; //while there is a line to get while( getline( fileIn, line) ){ switch( line[0] ){ //check … | |
Re: Your logic seems false. Line 3: You create a node t Line 16: You search for the int value then then updated t's frequency? But t is a new node not necessarily inside the binary tree! What you want is a helper function that returns the Node who has the … | |
Re: Line 14-18 set all pointers to null. Line 21 check if driver is null comment out line 23 and see if it runs fine. | |
Re: so.....whats the question 0_o? ![]() | |
Re: Seriously how hard is it to perform a [URL="http://www.google.com/webhp?sourceid=chrome-instant&ix=e1&ie=UTF-8&ion=1&nord=1#hl=en&nord=1&site=webhp&sa=X&ei=HeboTruBAsjd0QHeyeTlCQ&ved=0CBgQvwUoAQ&q=C%2B%2B+matrix+library&spell=1&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=a6957c99ad62c3c8&ion=1&biw=1276&bih=683"]google search[/URL]? Just pick one of the top ones. Sorry for sounding rude, but sometimes independency is what should be utilized to increase productivity | |
![]() | Re: If your on linux you can use the '<' operator. As in [icode] ./app < fileName [/icode] it gets the input from the file instead of direct terminal. ![]() |
| |
Re: Your code is hard to read but your problem is in line 15, your using the array and it hasn't event been initialized it. Usually when you use an array, you you use hardcoded index when you want to access all values. What you are looking for is something like … | |
Re: You can think of static variable as global variables but with scope | |
Re: You adding it twice here : [code] for (int day = 0; day < 7; day += 1) for (int temps = 0; temps < 2; temps += 1) tot += tempav[day][0]; { cout << " Total Col 1 " << tot << endl; } [/code] just do this: [code] … | |
Re: Another option is to supply your comparison method to std::sort: [code] int getDigitFromLine(const std::string& line){ const string digits = "0123456789"; size_t beg = line.find_first_of(digits); size_t end = line.find_first_of(digits); string digitString = line.substr(beg, end-beg + 1); return atoi( digitString.c_str() ); } bool mycomp(const std::string& lhs, const std::string& rhs){ int lhsNumber = … | |
Re: [icode]std::cin.getline(const_cast<char *>(name.data()), MAX_NAME_SIZE);[/icode] is undefined behavior because you are not allowed to modified the pointer-to-const-char returned by data. You could easily just use the c-style approach and convert that into a string. Or you can do something like so. [code] string str(' ',MAX_SIZE); cin.getline( &(str[0]) , str.size() ); [/code] | |
Re: How about you make a helper function to reduce work. [code] class Logger{ private: ostream *stream; public: Logger(ostream& strm) { stream = &strm; } void log(const std::string& msg){ _log(msg); } private: void _log(const std::string& msg){ (*stream) << msg << endl; } }; [/code] And so now you just call [icode] … | |
Re: Couple of options. 1) Read it into a string and work from there 2) Split the digits and work from there - to split the digits you can use the divide and modulus operator And I am guessing your avoiding arrays because either your assignment says you cannot use them … | |
Re: When you delete a node from a graph, to update your adjacency matrix you can either remove the column and row associated for that row. For example [code] Let node = 1 2 3 And its initial adjacency matrix be: 1 2 3 1 0 0 0 2 0 0 … | |
I'm graduating this december and I got a job offer!!! Will be working for FactSet. I can't believe it. This is so crazy. Thanks everyone for helping me when in need. I'm just so happy :) regards firstPerson | |
Re: >>[B]Rewrite the Student_info structure to calculate the grades immediately and store only the final grade.[/B] Seems like you want to do this in the constructor. Here is an example. [code] #include <iostream> struct Sum{ int total; Sum() : total(0){} Sum(int max): total( _calculate(max) ) { /*sum calculated already */} int … | |
Re: Test this : [code] #include <iostream> using namespace std; int main(int argc, char * argv[]){ for(int i = 0; i < argc; ++i){ cout << "Argument[" << i < "] = " << argv[i] << endl;; } } [/code] You can call it like [icode] ./ExecutableName arg1 arg2 arg3 [/icode] | |
Re: > `using namespace std;` your probably confused about what the above does. Look up 'C++ namespace'. In short, it makes public data that is in std namespace in your current scope. So instead of doing `std::cout << "hello"` you can simply do `cout << "hello";`. Notice I didn't have to … | |
Re: It looks like depending on what the string contains you want to do certain action. You should look into the command pattern. Anyways here is one way. [code] #include <iostream> #include <string> #include <vector> using namespace std; struct Command{ virtual void execute(const std::string& commandString) = 0; ~Command() {} }; struct … | |
Re: >>[B] if((s3=="Y" || "y"))[/B]] You want[icode] if(s3 == "Y" || s3 == "y")[/icode] or [icode] if(s3.find("yY") != string::npos) [/icode] or [icode] if(tolower(s3[0]) == 'y') [/icode] | |
Re: Yup tolower return the 'lower' version of the argument passed if valid. IT does not change the argument to its lower-cased version | |
Re: [QUOTE=jeevsmyd;1703420]Suppose I have a simple program to find the largest of two numbers of different datatypes and return the largest.I'm implementing it as a template to support generic datatypes [code] template<class T,class U> T max(T t,U u) return (t>u?t:u); int main() { int x=70; float y=100.5; max(x,y); return 0 } … | |
Re: Whenever you have a "big" assignment like that, its really good to break it down. Here is the first thing your should do : <quote> Create an [B]inheritance [/B]hierarchy containing [B]base class Account[/B] and [B]derived classes SavingsAccount and CheckingAccount[/B] [B]that inherit from class Account[/B]</quote? Draw this out on paper. Let … | |
Re: >>[icode] omp_get_max_threads ( ) [/icode] Spacing issue I think. Try [icode] omp_get_max_threads( )[/icode] | |
| |
Re: Um... you have to check it for all character [code] //check if str contains only digits bool isDigits(const std::string& str){ bool isValid = true; for(int i = 0; i < str.size(); ++i){ if(!isdigit(str[i])){ isValid = false; break; } } return isValid; } [/code] Note, this code might be ambiguous in … | |
Re: Just some few comments/questions first. 1) you might want to think twice on that hungarian notation. 2) Does the order of the elements in the string matter? For example does the last element has to be the last ? So does the element position matters relative to its neighbors? | |
Re: Your user interaction logic would look something like this : [code] string userInput; const std::string DONE = "done"; do{ cout << "Enter a command to call[ add, print, delete, done ] "; cin >> userInput; if( userInput == "add"){ /* ask user what to add then add it to the … | |
Re: >>Even though both variables have the value 30 in it, the if-condition gets satisfied and exception is thrown The int gets promoted and you are now doing a floating comparison. When doing floating comparison, as of right now you can do a simple range comparison : [code] //checks if lhs … | |
Re: So you need to perform a check. Something like so : [code] while(fileIn){ const char peekChar = fileIn.peek(); switch(peekChar){ 'A': createObjectA(fileIn); break; 'B': createObjectB(fileIn); break; default: /* error, object not supported */ break; } } [/code] [icode]cin.peek()[/icode] just peeks at the next character but doesn't 'read' it. So you can … | |
Re: Have you learned about for-loops? If so then using for loops is the correct way to solve this problem. | |
Re: Modern games are usually made with OpenGL, DIrectX, XNA or something else than win32. My advice to you is to not worry about win32 and pick up either opengl or directx | |
Re: Thats one approach. 1) You calculate the frequency of each letter in the ciphered text. 2) You have a frequency map for the english text 3) Get the highest frequency character in the ciphered text, and replace it with the highest frequency character in the map form step 2. 4) … | |
Re: Are you trying to delete a vector of pointers? [code] std::vector<x*>::iterator begin = x.begin(); while(!x.empty()){ x* tmp = x.back(); x.pop_back(); delete tmp; } x.clear(); [/code] | |
Re: Or maybe its conceptually better to have one boolean : [code] bool done = false; bool validMove = true; bool shouldContinue = true; do{ //... shouldContinue = done && validMove; //should continue only if all test are passed }while(shouldContinue); [/code] | |
Re: In line 16 and 19, you are using State2 and State3, respectively, without defining State2 and State3 previously. At that line, the compiler doesn't know that State2 and State3 is. So it spits out an error. | |
Re: You got the first step correct -- to create a enum list. Now your next task is to create a function that given a Enum Planet, it returns the string version of its name. here is a start. [code] #include <iostream> #include <string> using namespace std; enum Planet {MERCURY, VENUS, … | |
This code below add two positive numbers in any base from binary to base 36 with any length allowed by memory. The snippet comes with examples. There might be some bugs, because I haven't tested extensively, so forgive me if you find bugs. Hope people find it useful somehow. Thanks … | |
Re: Welcome to the world of pointers; a place where evil hides behind tricky beings. | |
Re: >>[B]((i-2)/i);[/B] your doing integer division. You want [icode] sum += (float)(i - 2) / i; [/icode] | |
Re: [B]>> Should I include the whole path name or just the image name? [/B] If the file is in the same directory as your source file, then you can just use the filename, else you can either use relative path or full path. However it needs to be a valid … | |
Re: You need to put line 69-70 in line 72. [code] bool isPrime(int num){ for(int i = 2; i < num; ++i){ if(num % i == 0) return false; } return true; } [/code] |
The End.