565 Posted Topics
Re: Here's a little example: public class A { public static void main(String a[]){ print("Hello World."); } public static void print(String str){ System.out.println(str); } } You'll have to include your main function, and your own function into a class. In Java everything has to be an Object/class, not like in C++ … | |
Re: Here's what my compiler says: > Implicit super constructor Student() is undefined. Must explicitly invoke another constructor In your class Student you have just one construcor, and it's a custom constructor with two arguments. In order to call that super constructor, it seems that you need to have explicitly in … | |
Re: Well guys, it's been four months sine the initial OP post. I don't know if he's looking into this program anymore. **KaeLL** I know that you're new on our website, but a read through our rules wouldn't have hurt you. Perhaps getting rid of unnecessary variables and declarations would clear … | |
Re: Perhaps this function will suite you better in checking if a string is a palindrome. bool pal(string str){ Stack<char> s, s2; //we'll use 2 stacks for (size_t i=0;i<str.size();i++) s.push(str[i]); //put all the characters into the stack for (int i=0;i<(int)str.size()/2;i++) s2.push(s.pop()); //pop as many elements as string's length/2 and push them … | |
Re: Try browsing using Atomic Browser, or Dolphin on iPad. I currently use them on my iPhone, and the editing ribbon appears. ![]() | |
Re: Well, you can have multiple single classes, and than to have an instance of some classes in another classes. Here's a quick example: #include <iostream> using namespace std; class A{ public: A(){} char* addA(){return "addA\n";} }; class B{ public: A a; //public instance of class A in class B; B(){} … | |
Re: You could check their time library: [Click Here](http://docs.python.org/2/library/time.html) | |
Re: use the pre-built methods: int a=5; String b = Integer.toString(a); //b="5" String b=5; int a=Integer.parseInt(b); //a=5 | |
Re: You know, Google provides good results... [Click Here](http://code.activestate.com/recipes/365640-thread-safe-multiqueue/) | |
Re: print "The data file specifies a "+ z+ "-server simulation." I'm not sure if it'll work, I currently don't have an active python ide/compiler. | |
Re: Here's a quick example of how you can integrate command line arguments into your program: #include <iostream> #include <cstdlib> int main(int argc, char* argv[]){ if (argc>1){ int a=std::atoi(argv[1]), b=std::atoi(argv[2]); std::cout<<"a: "<<a<<", b: "<<b<<" "<<std::endl; //could be std::printf("a: %d b: %d", a, b); if it's //required as a C program. } … | |
Re: for( char c : str ) result += m[c] ; It's a Java-like implementation of itration over a string, when char c will be at each iteration a character from the string. Here's what my compiler says: > range-based-for loops are not allowed in C++98 mode Also, perhaps this answer … | |
Re: Have you checked this thread? [http://www.daniweb.com/software-development/cpp/threads/182711/towers-of-hanoi-recursive](http://www.daniweb.com/software-development/cpp/threads/182711/towers-of-hanoi-recursive) Also this might be what you are looking for: [Click Here](http://lmgtfy.com/?q=tower+of+hanoi+recursive+solution+c%2B%2B) | |
Re: Line 28 long double Distance[NUM_Object][Object]; You got an error because Object as a variable is defined like this: double Object[NUM_Object][5]; You can't define it like that, because you're defining the size of that array, and thus you can't pass as number another array. | |
Re: Ok, so you need, if, for example, 5 is inputed, to show you 7, and if 7 is inputed to shouw you 11, and so on and so forth. Well, we'll need a proof that you tried to solve your problem, so that we know where you're stuck. Post what … | |
Re: Line 35: char name[16]; Line 37: string name; You can't have two declaration of variables with the same name. This can be don when declaring functions, but with different arrities, but here, you either put char name[16] and string name1, or leave just 1 variable (I would suggest to leave … | |
| |
Re: Is there suppose to be a problem? Because, from what I see, everything works swell. Here's my output: ----You have selected option A---- Please enter the first name. John Please enter the last name. Doe Please enter the street address. Liberty Please enter the city, state and zip code. New … | |
![]() | Re: You could do it like this, passing not a copy of the vector, but it's adress, and work directly on the vector, from your function. Here's a quick example. void WordFunctions(string *pstr, vector<string*> &words){ words.push_back(pstr); } int main(){ vector<string*> a; for(int i=0;i<10;i++){ string* f=new string(1, (char)80+i); WordFunctions(f, a); } for … |
Re: cout<< "\nEnter Position:"; cin>>x; cout<< "\nEnter value to be inserted:"; cin>>y; cout<< "\nNew elements:"; cout<<arr[numb]; wouldn't that be cout<< "\nEnter Position:"; cin>>x; cout<< "\nEnter value to be inserted:"; cin>>y; if (x<numb){ arr[x]=y; } else cout<<"Invalid position."; cout<< "\nNew elements: "<<arr[x]<<endl; | |
Re: Have a look at the string class: [Click Here](http://www.cplusplus.com/reference/string/string/) Also, have a look at the algorithm class: [Click Here](http://www.cplusplus.com/reference/algorithm/) Use functions as replace/find. Also, here are two examples of funtions: removes the 1st occurence from the string: void rem(string &initialString, string whatToRemove){ size_t pos=initialString.find(whatToRemove); if (pos!=string::npos) initialString.erase(initialString.begin()+pos, initialString.begin()+pos+whatToRemove.length()); } replaces … | |
Re: I like your ideea. Here's what I have cooked up in 5 minutes: #include <iostream> #include <string> #include <vector> using namespace std; vector<string> explode(string inputstring, string delimiter){ vector<string> explodes; inputstring.append(delimiter); while(inputstring.find(delimiter)!=string::npos){ explodes.push_back(inputstring.substr(0, inputstring.find(delimiter))); inputstring.erase(inputstring.begin(), inputstring.begin()+inputstring.find(delimiter)+delimiter.size()); } return explodes; } int main(){ string a="a23<del>b345<del>b657<del>c65", delimiter="<del>"; vector<string> explodes=explode(a, delimiter); for (int i=0;i<(int)explodes.size();i++){ … | |
![]() | Re: Well the reason you can't print a full sentence is because you write only 30 characters max: cout.write(msg,30); Have a look at the cout.write function: [Click Here](http://www.cplusplus.com/reference/iostream/ostream/write/) Instead you should write the entire msg: cout<<msg<<endl; Here, I put an example: this will read an entire file, and will display the … |
Re: Daniweb member rules state this: **Do provide evidence of having done some work yourself if posting questions from school or work assignments** Show us your current code, than ask the question. | |
Re: Seems fine: this is my output. Please enter the number of students in the database: 2 Enter name, student ID, and major... (follow each input with the 'enter' key until new prompt is seen): 1 2 3 Enter name, student ID, and major... (follow each input with the 'enter' key … | |
Re: Check this link: [Click Here](http://www.cplusplus.com/forum/windows/2024/) Also, there are numerous examples in the MSDN forums and on the site... | |
Re: Here's a little example: #include <string> #include <iostream> int main(){ std::string answer; std::cout<<"1 or 2"; std::cin>>answer; // here you take the input, single word, till you hit enter, or ' ' is met. if (answer=="1" or answer=="1.") std::cout<<"one\n"; else if (answer=="2" or answer=="2.") std::cout<<"two\n"; else std::cout<<"Invalid choice.\n"; return 0; } … | |
Re: `strlen` function from the `#inclue <string.h>` header, from the C library indeed calculates the size of the strig, having as a final delimiter the `'\0'` character, but strings in C++ are objects, which are not handled having as the last character the `'\0'` character. If you do want to use … | |
Re: Daniweb member rules state this: **Do provide evidence of having done some work yourself if posting questions from school or work assignments**. Show us your code, than we'll help you. | |
Re: I'm not going to give you speciffic code, but some useful links: [ifstream](http://www.cplusplus.com/reference/iostream/ifstream/) for opening files for reading. [ofstream](http://www.cplusplus.com/reference/iostream/ofstream/) for opening files for writing. [stringstream](http://www.cplusplus.com/reference/iostream/stringstream/) for tokenizing parts of the input stream. [getline](http://www.cplusplus.com/reference/string/getline/) for getting an entire line from a file, or from any other input stream. | |
Re: A way to throw and catch a logic_error exception: int main(){ try{ throw logic_error("err"); } catch(logic_error& e){ cout<<e.what()<<endl; } return 0; } Also, have a look at the logic_error class from c++: [Click Here](http://www.cplusplus.com/reference/std/stdexcept/logic_error/). | |
Re: Have a look at this: [Click Here](http://www.daniweb.com/software-development/cpp/threads/439460/replaceedit-a-specific-text-in-line-of-text-file#post1888886) | |
Re: Funny how a quick search on google shows a lot of answers: [Click Here](http://lmgtfy.com/?q=error+LNK1123%3A+failure+during+conversion+to+COFF%3A+file+invalid+or+corrupt) Also, you could see here some good answers to your problem: [Click Here](http://stackoverflow.com/questions/10888391/link-fatal-error-lnk1123-failure-during-conversion-to-coff-file-invalid-or-c) | |
Re: Also, you could do it by using a stringstream: int i=1001010100; std::stringstream token; token<<i; token.str(token.str().substr(0, token.str().size()-4)); token>>i; this will convert your int to a stringstream object, than, it will remove the last 4 digits and it will convert it back to int. | |
Re: As **ravenous** pointed out, this assignment is about operator overloading. You'll need a TrashCan class where you specifically overload the operators, here you'll need to overload operator `+`, `-`, `>>` and `<<`, plus the boolean operators. So, first of all you'll need a class: class TrashCan{ //class stuff }; and … | |
Re: You put it as a function inside that Entry class. class Entry{ //clas stuff; FileSize(std::string Path) { std::ifstream Stream(Path.c_str()); if (Stream.is_open()) { int Start = Stream.tellg(); Stream.seekg(0, std::ios::end); int End = Stream.tellg(); Stream.close(); return (End - Begin); } return -1; } }; and inside the while you call the function: … | |
Re: Here's a nice way of doing that: #include <iostream> using namespace std; #define SIZE 10 int main(){ double arr[SIZE], count=0; for (int i=0;i<SIZE;cout<<"Nr["<<i<<"]: ", cin>>arr[i++], count++) if (arr[i-1]<0) break; for (int i=0;i<(int)count;i++) cout<<"Nr["<<i<<"]: "<<arr[i]<<"\n"; return 0; } | |
Re: > Am I doing the calculation correctly? What lines of code should I change? Line 3 and 4: int sum; int variance; change them to double. | |
Re: Daniweb member rules state this, among other things: **Do provide evidence of having done some work yourself if posting questions from school or work assignments**. We won't just hand you the answer. | |
Re: bool leapYear(int year); { if (year % 4 ==0) return true; else return false; } get this function out of your main function, also indent your code... Another thing: your program has logic errors inside of it... #include <iostream> //Header Files #include <fstream> #include <string> #include <iomanip> using namespace std; … | |
Re: > int IsPrime(unsigned long m) `'m'` is the parameter of the function isPrime, basically it's the number you want to check if it's prime. | |
Re: > pkg.c:246: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'initted' line 246 from pkg.c, it seems that the expression is not valid, check again that code. Also, when dealing with large errors, look at the first errors, because some of the other errors are derived from the 1st … | |
Re: > but i got the error 998 memory access violation Than you're using some pointer which points to a restricted memory area. Also, post the entire error, and do a debug of your program. See which pointer gets crazy... | |
Re: Here's the buble-sort algorithm explained: [Click Here](http://mathbits.com/mathbits/compsci/arrays/bubble.htm) Try to think now how to apply this algorithm to work for strings and other items. Also, have a look at the STL sort algorithm: [Click Here](http://www.cplusplus.com/reference/algorithm/sort/) | |
Re: try this: <?php echo exec("ping www.google.com"); ?> | |
Re: Wouldn't that be easier to have a Book class, which will hold information about a certain book, and then a repository, in which you'll add/update/store/delete/search for books? class Book{ string name, category; double price; public: Book(){ name=category=""; price=0; } Book(string name, string category, double price){ this->name=name; this->category=category; this->price=price; } void … | |
Re: Have you checked this thread? [Click Here](http://www.daniweb.com/software-development/java/threads/430542/java-projects-for-learners). | |
Re: Create a class named Bin_add (means stack class) that should contain following inline functions: • Add( ) To add two binary numbers bit by bit and display the sum. Should be a function from your class, that should be implemented in the class, and not aside, in some clauses in … | |
Re: > please help me how can i design such logic. Well, we're kinda confused about your explanation too. So, if you'll try to explain better what you're trying to accomplish inside that 2 for loops, we'll might help you, starting with these: > int number=no. to skip; and > but … |
The End.