- Strength to Increase Rep
- +7
- Strength to Decrease Rep
- -1
- Upvotes Received
- 51
- Posts with Upvotes
- 49
- Upvoting Members
- 26
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
133 Posted Topics
["Objects that are instances of an inner class exist within an instance of the outer class"](http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html) Even though I attempt to create an independent instantiation of the inner class, the outer class is always there because of the statement above. ##Is that ture? If true, then that would also mean … | |
Re: ##You can't return a pointer from off the stack. Add the error handling #include <cstdio> #include <iostream> using namespace std; struct student { int SUB[3]; }; struct AVGPCT { float avg; float pct; }; AVGPCT* CALC(student *A) { int x,y; //--------------------------------------- // Have to allocate the memory here AVGPCT *D … | |
Re: Yes, need more context. Post more. And tell us what it is doing that makes you say that it doesn't work. | |
Re: Read this http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html and look at the section **Rounding Error**. ##Play around with this #include <iostream> #include <iomanip> #include <cmath> // Might need this later #include <cfloat> using namespace std; int main(){ // a / b = c = c // (1/9) / (1/3) = 3/9 = 1/3 float a(1.0f/9.0f),b(1.0f/3.0f),c(1.0f/3.0f); … | |
Re: You didn't allocate memory for the cell inside the INST. [code] for ( j = 0; j < i; j++ ) { top_inst_list[j] = (INST *)malloc(sizeof(INST)); top_inst_list[j]->name = (char *)malloc (sizeof(char) * 10); // You need to allocate memory for the CELL before you start to access // top_inst_list[j]->cell->name top_inst_list[j]->cell … | |
Re: ##Would this work http://www.cplusplus.com/reference/std/locale/collate/hash/ | |
Re: ##See comments in code #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/types.h> #include <ctype.h> //---------------------------------------------------------- // Added for fstat #include <sys/stat.h> int main(int argc, char * argv[]){ //---------------------------------------------------------------------------- // Added for fstat struct stat sb; int fd, pagesize,i; char *data, x; if (argc != 2){ //-------------------------------------------------------------------------- // Here … | |
Re: ##If using GCC version < 4.7.0 (me 4.6.3) need to uncomment out this as Mikael Persson indicates // For GCC version < 4.7.0, use this replacement for the template alias: // template <typename T> // struct locked_ptr { // typedef const detail::locked_ptr_impl<T>& type; // }; ##And replace all locked_ptr<const std::string> … | |
Re: If you are inserting at the front each time, DataAt(i) will always return the first element you added. Ex: InsertAtFront(22): 22 DataAt(0) = 22 InsertAtFront(33): 33, 22 DataAt(1) = 22 InsertAtFront(44): 44, 33, 22 DataAt(2) = 22 etc ... | |
Re: > /* Memory allocation */ > array = (int**)malloc(sizeof(int) * ROWS); ##Should be /* Memory allocation */ array = (int**)malloc(sizeof(int*) * ROWS); sizeof(int) and sizeof(int *) would be different on 64-bit machine. | |
Re: ##@dyl_ham, your last try was really close. Just move some things around. #include <iostream> #include <fstream> #include <cstdio> #include <cerrno> using namespace std; ifstream * openInputFile() { string fileName; cout << "Please enter a valid file name: "; cin >> fileName; //--------------------------------------------------- // You have the file name, just use … | |
Re: ##Try if(childpid > 0){ //parent close(pipe2[1]); close(pipe1[0]); client(pipe2[0], pipe1[1]); //--------------------------------------------------- // I moved these, you have to close the pipes // so the server can exit and then the wait // will catch the exit of the server. close(pipe2[0]); close(pipe1[1]); wait(&status); exit(0); } ##Now `while(read(readfd, am, sizeof am) > 0)` … | |
Re: ##This works for me and I'm using the same g++ (gcc version 4.1.2 20080704).## #include <iostream> using namespace std; typedef int DOMNode; class MyDOMNode { public: MyDOMNode (DOMNode* node): mDomNode (node) { cout << "Constructor: " << node << endl; } bool operator== (const MyDOMNode& rhs) { if (mDomNode == … | |
Re: ##See if this helps, look at comments.## #include <iostream> #include <string.h> #include <sstream> using namespace std; struct Item { string itemDescription; int quantity; float wholesaleCost, retailCost; string dateAdded; }; int main(){ Item temp; //file.read((char*)&temp.itemDescription, readsize); //####################################### // Comment this out for this to work read(1,(char*)&temp.itemDescription,4); //##################################################### // // temp.itemDescription // … | |
Re: ##See if this helps, look at the comments.## #include <string.h> #include <stdio.h> //####################################### // This must be what your structure // looks like struct { char *nome; char *identificadorNum; char *quantStock; char *limMin; char *consumoMed; } ingredientes[4]; //####################################### // This is what it should look like struct { char nome[10]; … | |
Re: Just ran you code and it worked for me: #include <iostream> #include <string> #include <cstdio> #include <curl/curl.h> int main(void) { CURL *curl; curl = curl_easy_init(); if(!curl) { std::cout << "Unable to initialize cURL interface" << std::endl; return -1; } std::string curl_url = "https://www.cia.gov/"; curl_easy_setopt(curl, CURLOPT_URL, curl_url.c_str()); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); curl_easy_setopt(curl, … | |
![]() | Re: I don't think you want to have it scoped to the Circle class. If it was then you wouldn't have to be a friend. |
Re: When you get to it, void B::add(int id, string name, int age){ A *a; a=new A; a->setid(id); a->setname(name); a->setage(age); list.push_back(*a); } is leaking memory. You define list as `vector<A> list;` and in the add function allocate memory for an A class but when you add it to the list it … | |
Re: Using a recursive function as well. I just have one more bug (I think). I thought that function was getting to complex but maybe not. Got to solve it, it's consuming me now. | |
Re: Change line 223 from `dobule weightInKg = convertLbToKg(weight);` to `weightInKg = convertLbToKg(weight);` You defined weightInKg at line 201 and then again at line 223 but then you used it in 275. But were you set it at line 223 is a different scope then the one defined at 201. | |
Re: What do the values in the matrix represent? And why is T1 -> p1 T2 -> p2 T3 -> p3 T4 -> p1 the best? Trying to understand your problem a little more. | |
Re: > I tried to do linear probing in the above ... Looking at the link you gave, it looks like they want you to use link-lists for the collisions because in the section were it talks about >b. when requested, analyze the efficiency of the hashingalgorithm for this set of … | |
Re: Line 152 you are using 1for the first index, it should be i. cout << " " << feedback[i][3]; | |
Re: Should `generate_combination()` be an operation of the class bruteFrce? Like `void bruteFrce::generate_combination(int)` or should it really be outside the scope of the class bruteFrce? | |
Re: Use erase: http://www.cplusplus.com/reference/string/string/erase/ `string& erase ( size_t pos = 0, size_t n = npos );` "pos: Position within the string of the first character to be erased." "n: Amount of characters to be removed." void setSecretCode (char code[4]) { string colors = "RGBYO"; int pos; srand(time(NULL)); pos = rand() % … | |
##I was working on something and saw this oddity, thought I would share it. $ ./a.out in.val = 86.3115158 -> Its a valid floating point number out1.val = nan -> Swapped it and now its a NaN! That's OK swap it back. out2.val = 86.4365158 -> What, its not the … | |
Re: Its wraping around. $ ./a.out i(0) f1(9) f2(-8) <------ Should have stopped here i(1) f1(12) f2(-6) i(2) f1(18) f2(-4) i(3) f1(24) f2(-3) i(4) f1(36) f2(-2) i(5) f1(72) f2(-1) i(6) f1(-72) f2(1) i(7) f1(-36) f2(2) i(8) f1(-24) f2(3) i(9) f1(-18) f2(4) i(10) f1(-12) f2(6) i(11) f1(-9) f2(8) <------ When all of … | |
Re: You forgot to put the RefEnv:: infront of the two functions get_var and get_func. std::map<std::string, VarIdent>::iterator RefEnv::get_var(std::string s){ std::map<std::string, FuncIdent>::iterator RefEnv::get_func(std::string s){ And you have the wrong type for the second map template para. bool RefEnv::insert_func(Type t, std::string key, std::string n){ //Precondition: // A RefEnv object exists // //Postcondition: // … | |
Re: ##Try, but only tested it a little #include <vector> #include <iostream> using namespace std; int main(){ vector<int> m1,m2,m3; m1.push_back(0); m1.push_back(1); m1.push_back(1); m1.push_back(0); m1.push_back(0); m1.push_back(1); m1.push_back(1); m1.push_back(1); m1.push_back(1); m1.push_back(0); m1.push_back(1); m1.push_back(1); m1.push_back(0); m1.push_back(0); m1.push_back(0); m1.push_back(1); m2.push_back(0); m2.push_back(1); m2.push_back(0); m2.push_back(1); //------------------------------------------ // Just thinking // 1 2 3 4 5 6 // … | |
Re: Not at home to check it out but I pretty sure that your problem is, you are returning a pointer to something on the stack. ScoreEntry** retEntry = &newEntry; return retEntry; newEntry is a local variable and when you leave the Load function its address is no longer valid. Why … | |
Re: Yeah phorce, it seems like I only get emails once in the morning. I checked send email on threads I post on but not getting updates when there is activity on thread. | |
Re: Not infront of my computer to test, but I think you need to [icode]chomp($choice)[/icode] to get rid of the '\n'. The '\n' is on the end of $choice which is why it is failing. [url]http://perldoc.perl.org/functions/chomp.html[/url] | |
Re: ##See if this helps #!/bin/bash if [ -d $1 ] then cd $1 for file in $(ls *.jpg) do newfile=${file%.jpg}"_DEFAULT"${file:(-4)} echo "New file name: $newfile" done else echo "Directory $1 doesn't exist" fi ## Testing ## $ ls ./temp P100.jpg P172.jpg P342.jpg P400.jpg $ ./myScript temp/ New file name: P100_DEFAULT.jpg … | |
Re: If you put #!/bin/bash (wherever bash is for you) as the first line in the script, do you still get the error? | |
Re: Just curious, why are you integrating over the CDF and not the PDF? And wouldn't the value of x->infinity = 1 - chicdf(x) (chicdf not being the integral but the value of chicdf at x)? Just thinking, I could be totally wrong. | |
Re: Here is some code to mess with. The first code chunk is the scheduler-ish program. It forks a child program that receives an amount of time to sleep from a pipe and outputs time slept to another pipe to the parent. If the current working directory is not in your … | |
Re: In function `void openFile(Person list[], int& size)` you don't increment the value of size, so it loaded but you never changed the value of size so it looks as if zero were loaded. You could use STL sort. http://www.cplusplus.com/reference/algorithm/sort And a compare function like: bool compPerson(Person p1, Person p2){ if( … | |
Re: Not really sure what you want this program to do. I had to change the sem_init to sem_open because I have a Mac (should change the functionality). I didn't check anything else like memory leaks, so see if this helps. Jobs are added to the queue and each thread processes … | |
Re: I didn't look all of it but on line 38 is one of your issues. // The check on i is not correct, it will never // enter the loop for(int i=10;i<=0; i--) // It should be i greater than or equal for(int i=10;i>=0; i--) | |
Re: Try something like: #include <string.h> #include <stdio.h> void funct1(char line2[]) { char *tem_tptr; tem_tptr = strtok(line2, " \t\n"); //here i should have value add, or sub if(tem_tptr != NULL) { printf("\tInside funct1: %s\n",tem_tptr); } } int main() { char line2[20]; char tem_line2[20]; char *tptr; while(fgets(line2,20,stdin)) //read one line and store … | |
Re: http://en.wikipedia.org/wiki/Standard_deviation The standard dev is the square root of 1/N*sum (x-mean)^2. float stDevSum(0); for(int testNum = 0; testNum < 15; testNum++) { stDevSum += powf((numbers[testNum]-mean),2.0f); } stDev = sqrt(stDevSum/15); You might also see it done as sqrt(E[X^2]-E[X]^2) but if the standard dev is really small you might get NAN (Not … | |
Re: That will always happen. '.' is the current directory and '..' is the parent directory. while((direntry=readdir(dir))!=NULL) { // If the first character is a dot, then skip it if ( direntry->d_name[0] == '.' ) continue; printf("%d %s\n",i,direntry->d_name); i++; } closedir(dir); | |
Re: [code=perl] #!/usr/bin/perl $i = "|,0.005,0.004,0.004,0.005,0.006,0.005,0.006,0.005|,0.005,0.006,0.004,0.005,0.005,0.004,0.004,0.006|,0.004,0.004,0.004,0.004,0.004,0.005,0.004,0.004|,0.005,0.003,0.004,0.004,0.005,0.005,0.004,0.003|,0.005,0.003,0.004,0.004,0.005,0.004,0.005,0.004|,0.004,0.004,0.004,0.004,0.004,0.003,0.005,0.004|,0.005,0.004,0.005,0.005,0.005,0.005,0.005,0.004|,0.005,0.005,0.005,0.005,0.005,0.005,0.004,0.004"; # I have to get rid of the first '|,' otherwise the first # element in the array will be empty. If you don't mind # then you can delete this line and just use the split $i =~ s/^\|,//; @values = split(/\|?,/,$i); foreach $elm … | |
Re: In the client code: On line 23 use the length instead of strlen. If you read 4096 bytes then there is not '\0' for strlen to stop at. That is why the first print out of the number of bytes received (4102) is over 4096. On line 10, 11, 19 … | |
![]() | Re: You should do it in pieces. 1.Start with reading and parsing the XML file first. This may be the function that takes you the longest. Create a program the takes in the file name, opens the file and parses out each (x, y) and prints them to the screen. Once … |
Re: This works in my head, can't check it unless I code it up or some simple binary tree. At the end the value return by HuffmanCode will have the encoded value **not code (third arg)**. int main() { // etc... someChar = 'n'; wrkingTmp = ""; // <--- Will not … | |
Re: Reference: http://en.wikipedia.org/wiki/Single-precision_floating-point_format #include <iostream> // Needed for the hex, showbase, setfill and setw #include <iomanip> using namespace std; int main(){ // Set the floating point number float floatVal(-1); // Want the integer form of what the float looks like, not the integer // part of the float. unsigned int intValOfFloat(*reinterpret_cast<unsigned … | |
Re: I'll start you off. I changed the qsort compare function for IDs and the call parameters to [qsort](http://www.nsc.ru/cgi-bin/www/unix_help/unix-man?qsort+3). >The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the … | |
Re: Check out this vs. what you have. $ ./a.out Please enter a size for the square: 5 Please enter first symbol: + Please enter a second symbol: * * + * + * + * + * + * + * + * + * + * + * + … | |
Re: I think you are going to have to make a map of string to enum. std::map<std::string, NyNumbers> theMap; theMap["First"] = First; // etc... std::map<std::string, NyNumbers>::iterator pos; if ( (pos = theMap.find(argv[1])) != theMap.end()){ // Found!! cout << Matrix[pos->second]; // etc... } |
The End.