2,712 Posted Topics
Re: [CODE] //O(n) for (int j = 4; j < n; ++j) { cin >> val; } //O(n) for (int i = 0; i < j; ++i) { b = b * val; } //misformatted? for (int k = 0; k < n; ++k) c = b + c;} } [/CODE] | |
Re: >>I'm aware of the std::map container, and I had considered it. The problem is the strict weak ordering that it requires is not appropriate for the problem domain as the ordering is based on the first member of the pairs and I need the values sorted based on the second … | |
Re: Ok, does the tower of happiness has all the happiness that I need ? Does it include megan fox in there? How about the best food in the world? How about a infinite power machine? So seriously, whats your problem? | |
Re: For Binary search trees or any data structures that are [i]recursive[/i] in nature, you will want to implement a recursive algorithm to solve most of its problems.Its not only easier to write, but its easier to understand as well. So with that said, consider this recursive algorithm that finds the … | |
Re: How about just reading it as a string? Then you have an array of numeric character. | |
Re: Bad choice of data structures. Go with std::map | |
Re: Java is a good source of code that is event driven. For example, when you click a button and event is created, and parties are notified of such events. | |
Re: >>Which array-based operations are O(1)? >>inserting item or deleting item in unsorted array not quite, what happens if we insert in the middle of the array. How about accessing the data? >>Which linked-list operations are O(1)? >>inserting and deleteing item in unsorted lsit true. >>Which array-based operations are O(n)? >>traversing … | |
Re: Note: [icode]bool sayi[10] = {false}; [/icode] will initialize the whole array to false. So there is no need for sifirla function. Its hard for me to understand your code. I suggest you do something like the following : [code] int randRange(int min, int max){ return rand() % (max-min) + min; … | |
Re: try [icode] cout << setprecision(10); [/icode] where you need to include [i]iomanip as a header[/i] | |
Re: You are not able to create a large array because there isn't enough memory in stack memory. So you have to allocate it and use heap memory like so : [code] int size = 10e10; int array = new int[size]; //..utilize array delete [] array; //release memory for later use … | |
Re: >>[B] if((node -> data %2) != 0)[/B] bad coding. Make a [icode] bool isOdd(int n){ return n % 2 == 1; }[/icode] function and use it like so [icode]if( isOdd(node->data) ){ ...} [/icode] | |
Re: >>[B]all the vector class is, is a linked list[/B] Are you implying that a std::vector class is implemented using a linked list data structure? Example : [code] template<typename T> class SpecialList : std::list<T>{ public: //add functionalities here }; [/code] Or use composition : [code] class SpecialList{ private: std::list<int> listOfInts; public: … | |
Re: Something else to consider : [code] template<typename T, int ROW, int COLUMN> class Array2D{ private: T _array[ROW][COLUMN]; public: Array2D(){/*initialize _array*/} //Array2D methods/operations }; int main(){ Array2D<int,5,5> array; } [/code] | |
Re: Your saying this doesn't work : [code] struct GrowableArray{ unsigned size; double *array; } void initialize(GrowableArray& g){ g.size = 0; g.array = 0; } [/code] What errors do you get? Post some actual code. | |
Re: The pointers makes me weary. I don't see a reason why you need to use pointers. Remove all instance of them, and use proper data structures like std::vector or std::list. What type of runtime exception do you get? Stack overflow? Invalid index ? writing into memory exception? Also, do not … | |
Re: $100 dollars per homework, plus extra depending on the assignment. Or else you need to do this on your own, with some of us giving you hints. | |
Re: Here is the prototype : [code] friend istream& operator >>(istream& stream, Data_Time& date){ /* code to read here */ /* return ... */ }; [/code] Make that your member function. | |
Re: Are you guys sure about that runtime? The first loop runs n times. And for each n, it runs 2^n. Thus the total runtime is O(n*2^n) | |
Just for Fun, and for reference to the web searchers, lets start a series of problems in computer science thats ranges in difficulty from [1,10], where 1 is easy, and 10 is harder. Maybe I and others will learn something useful from this. The following exercise is meant as an … | |
Re: What do you mean? As a background? Or just save the file in desktop? | |
Re: Ok now you need to use a for loop. Have you used it before? Give it a try. Inside the for loop, you ask the user for a number and insert it into the array. | |
Re: Does the getTail() return the last element or one passed the last element? Is it valid to do this [icode]cout << (a.getTail())->Coeff << endl;[/icode] Also what is the exact error message? | |
Re: I didn't test the below code, but there is no need for the vector in your code. Just go directly to string. [code] //supports only positive numbers string convertToBase(long num, int radix){ assert( radix > 0 && radix < 36); //base range[1,36) assert( num > 0); string ans = ""; … | |
Re: Some styles that I use : [code] class Class{ //Classes start with capital letter m_var; }; [/code] [code] bool func(){ //notice the '{' being in the same line as the function } [/code] [code] int *p = 0; [/code] [code] string firstNameList; //naming convention [/code] I use the "//" inline … | |
Re: easy way out : [code]void doIt(int start, int end){ if(start < end){ printBinaryRepresentation(start); } else doIt(start+1,end); } [/code] | |
Re: Easy enough. What you need to do is the following : [code] 1) Populate the list with words from the file. 2) Start from the beginning, check if the first word is correct, i.e first letter is capitalized, and spelled correctly. 3) Check if the second word is spelled correclty, … | |
Re: Its not possible to do what you are doing. The best you can get is : [code] template<typename T> class CategoricalStats { ... } template<typename T> struct QualitativeStats{ typedef CategoricalStats<T> Type; } //... QualitativeStats<float>::Type qstats; [/code] You have that ugly extra level of indirection, but it gets the job done. … | |
Re: I can do this in a couple of minutes for a low rate of $20.00 US dollars. | |
Re: [B]>>Look up C++ for dummies[/B] HAHAHAHAHA... We can't inherit constructors, so there is no need for them to be virtual. | |
Re: use this simple function, : int getInt(const char *msg){ cout << msg ; int n = 0; while(!(cin >> n)){ cout << "Input failed...try again\n"; cin.clear(); while(cin.get() != '\n'); } return n; } Basically, the `while(!(cin>>n))` checks the cin gets what we are expecting it to get. We are expecting … | |
Re: So if I get this straight, you have a file with "pre-order" data. And your goal is to print out the data in a post order manner correct? If so then, what you could do is, take the pre-order data, store it in an array, call it PREARRAY. Then construct … | |
Re: All of this could have been avoid by [B]not using raw pointers[/B]. If you can, avoid pointers all together. If not, then use smart pointers. | |
Re: [QUOTE=gwahl;1350134]is it possible to make an array of variables?[/QUOTE] Its not only possible, its also possible to make an [i]arrays of arrays of arrays of pointers to an arrays of arrays that takes values.[/i] | |
Re: >>[B]int newSize=size*=2;[/B] OUCH! That equivalent to : [icode]size = size * 2; int newSize = size[/icode] Which means that the variable size is twice its value. You wanted [icode]int newSize = size * 2[/icode]. Thus leaving the variable size unchanged. Make sure you call [I]delete [] expandArr[/I] at the end … | |
Re: Also, there are some problems with your letterGrade function. It should look something like this : [code] char letterGrade(int score){ char grade = 0; if(score >= 90) grade = 'A'; else if(score >= 80) grade = 'B'; else if(score >= 70) grade = 'C'; else grade = 'F'; return grade; … | |
Re: Don't declare it globally. Your teacher will take points off. Instead do this: [code] void listmodified(Car car[], int size){ /* some code here */ } int main(){ warehouse car[2]; /* some code here */ listmodified(car); } [/code] so that way you are using the same car thats in main inside … | |
Re: Do this [code] queue<state> stateQueue; state s; //initialize s stateQueue.push( s ); //...blah blah a blah [/code] | |
Re: Most people use C++ as base. Meaning that, they use some type of library that can handle the graphics, and use C++ to code the logic. Every time you make a project, you are making software. For example, when you make a program that checks if the string is a … | |
Re: @OP here is some syntax help: [code] #include<iostream> using namespace std; #include <fstream> //returns the mean of the array double meanArray(double N1[], int size); int main() { const int MAX_DATA = 1000; double fileData[MAX_DATA ] = {0}; //initialize the array to contain 0 ifstream fileInput("data.txt"); //open the file /* read … | |
Re: The problem you suggested should be fixed by modern compilers. Which one are you using? | |
Re: [QUOTE=Rizwan606;1347522]Im not talking about the even numbers stored in array,,But im saying that the numbers which are stored on even index of array could be displayed?[/QUOTE] Think before you speak. Thats exactly whats he talking about. Fir you need to know how to generate even numbers such as {0,2,4...}. Then … | |
Re: 1010 in decimal = 1 * 2^3 + 0 * 2^2 + 1* 2^1 + 0*2^0 = 8 + 0 + 2 + 0 = 10 Thus 1010 in decimal is 10. | |
Re: The first one basically reads as follows : "Create a string object called S where S refers to the statically defined string object "abc". The second one reads as follows : "Create a string object called S, where S points to a new dynamically allocated string object with the value … | |
Re: Pattern # 3 : [code] $$$$$ // Print('$', 5) && Print('5', 0) $$$$5 // Print('$', 4) && Print('5', 1) $$$55 // Print('$', 3) && Print('5', 2) $$555 // Print('$', 2) && Print('5', 3) $5555 // Print('$', 1) && Print('5', 4) [/code] | |
Re: Or another possibility to this stupid problem : [code] struct WidthProperty{ unsigned width; }; struct HeightProperty{ unsigned height; }; class Rectangle{ WidthProperty w; HeightProperty h; public: unsigned area(){ return w.width * w.height; } }; [/code] | |
Re: >>[B]although library implementations of std::sort usually have optimizations so it doesn't degenerate to O(n^2)).[/B] Does that mean the stl guarantee that they use quicksort for std::sort? | |
Re: You are trying to specialize a template function that does not exist! | |
Re: Sure, we would be more than glad to help you. But first there are a few things you should know : 1) We tend to help people that are "stuck on a problem" or give them a little push and whatnot. We are not here to do your homework for … |
The End.