2,712 Posted Topics
Re: You can either use standard containers or use dynamic arrays. I will show you how to use both : using std::vectors [code] #include<iostream> #include<vectors> using namespace std; int main() { vector<int> Array; cout<<"Enter the array size : "; int Size = 0; cin >> Size; Array.resize(Size); //now populate for(int i … | |
Re: 1) Too much comment. 2) That is not how to call a function : [code] bubbleSort(int * Array, int SIZE); [/code] it should be [code]bubbleSort(Array,Size); [/code] 3) you bubble sort is wrong, j should start out as i+1 until the SIZE. 4) You aren't populating your array with random numbers, … | |
Re: >>1) the style in which the user inputs their numbers for each 3x3 matrix should be - enter all 9 #s and then press enter... as opposed to enter a # press enter (9x) Ok, whats the problem with this? >>2) the only place i know where to put the … | |
Re: Recursion is a bad idea here. But if this is what you want : [code] String str = "vertical"; printVertical(str); [/code] and if the output should be : [code] v e r t i c a l [/code] Then your code shouldn't be hard. do something like this : [code] … | |
Re: [QUOTE=chaines51;1044571]To start off with, based on your example, I'm not sure you've got the general idea of inheritance. In general, you want to inherit from another class if the class you're building has all the attributes of the class you're inheriting from, plus some unique to this child class. If … | |
Re: google cctype header. Its really useful. | |
Re: floats are made for spaced optimization, it does not necessarily have to be faster than double, especially in a 64bit CPU. | |
Re: You have a vector of int pointers that do not point to any memory. Try allocation memory first. | |
Re: How about you warp your code into code tags, correctly. Then comment on each line of code, so we can see what you are thinking. | |
Re: It would be better if you just let the overloaded operator work like this [code] MyClass A; //initialize A cout<< A[0].someGetFunc(); [/code] Do you know how to accomplish this? | |
Re: First initialize your variables. Average = totalSum/totalElement. Thus totalSum should be computed first and then divide it by the array size. | |
Re: Don't forget code tags. It makes it easier for us to help you. | |
Re: Input = cin x is a float y is a int r is a int for i to y means : [code] for(int i = 1; i < y; i++) { //code goes here } [/code] The "code goes here" part is result = result * i; | |
Re: Use an external library to handle musics and sound. I would suggest openAL (Google it). | |
Re: is it possible to use just a vector instead of vectors of vectors? | |
Re: Can you be more clearer? Do you mean how random number works ? | |
Re: Why do you have 3 loops for a 1d vector? If you want to emulate it as a 2d then all you need is 2 for loops. [code] int A[4] = {1,2,3,4}; int B[4] = {1,2,3,4}; int R[4] = {0}; for(int i = 0; i < 4; i++) { for(int … | |
Re: You cannot use std::sort with list (if that is what you intended to do) list has its own sort. Here is an example : [URL="http://www.cplusplus.com/reference/stl/list/sort/"]http://www.cplusplus.com/reference/stl/list/sort/[/URL] | |
Re: >>a problem arises whereby, when I access the vector from a different class, for some reason it "loses" it's contents and is empty? << From what content? How about you make a adapter class, that wraps vector, and make that adapter class singleton. | |
Re: Tell me if you see a problem here : [code] [COLOR="Red"]char an;[/COLOR] cout << "Please enter the operation you want" << endl; cout << "Press 1 for addition" << endl << "Press 2 for subtraction" << endl << "Press 3 for division" << endl << "Press 4 for multiplication" << … | |
Re: [URL="http://www.google.com/imgres?imgurl=http://www.cs.utk.edu/~pham/ascii_table.jpg&imgrefurl=http://www.cs.utk.edu/~pham/ascii.html&h=475&w=715&sz=142&tbnid=fHeK-W8VD8qXUM:&tbnh=93&tbnw=140&prev=/images%3Fq%3Dascii%2Btable&usg=__lHecv_bS2HSgp9GzbeNcEr00luM=&ei=MWD2StSzHsjT8QaPqsXzCQ&sa=X&oi=image_result&resnum=4&ct=image&ved=0CBEQ9QEwAw"]Ascii Table[/URL] They represent the value of a character. For example : All character from 'a' to 'z is represented by the decimal value 97 to 122. So a function that would check if a character is a lower case character might look something like this : [code] bool isLowerCase(char … | |
Re: Here is a hint : [code] ********** 10 stars ********* 9 stars ******** 8 stars ******* 7 stars ****** 6 stars ***** 5 stars **** 4 stars *** 3 stars ** 2 stars * 1 stars ** 2 stars *** 3 stars **** ***** ****** ******* ******** ********* ********** 10 … | |
Re: Well the top and the bottom are the same so you can just duplicate the top at the end, and the middle two are the same. I see no reason to use for loops for this. | |
Re: >> Add a static method Account consolidate(Account acct1, Account acct2) to your Account class that creates a new account whose balance is the sum of the balances in acct1 and acct2 and closes acct1 and acct2. The new account should be returned. << Break this down : >>Add a static … | |
Re: You could use [URL="http://www.opengl.org/documentation/specs/glut/spec3/node76.html"]glutBitmapCharacter[/URL] Combined with function you can make this : [code] void renderBitmapString( float x, float y, float z, void *font, char *string) { char *c; glRasterPos3f(x, y,z); for (c=string; *c != '\0'; c++) { glutBitmapCharacter(font, *c); } } [/code] That is provided by lighthouse, [URL="http://www.lighthouse3d.com/opengl/glut/index.php?bmpfont"]Their link[/URL] Now … | |
Re: You need to use the mod operator. example : [code] 2 % 2 = 0 4 % 2 = 0 12 % 2 = 0 114 % 2 = 0 [/code] as you can see even numbers mod 2 will equal 0. So use this as your test case in … | |
Re: call your calc_average inside openFile function. | |
Re: [QUOTE=Ezzaral;1039359]++ Me too. Not only is it unnecessary, the code just reads a whole lot cleaner without them.[code]if (isComplete) {...[/code][/QUOTE] Yea, sometimes, but IMO not all the times. It depends on the variable name. When giving a variable name, if giving it isBlah doesn't necessarily make sense, for example, suppose … | |
Re: I am a little doubtful about your code. Why does CarNode inherit from Car and it also composes it ? Note that in c++ objects is by default passed by value and Not passed by reference. You may wan't to read about pointers and reference in c++. | |
Re: Your copy ctor is hiding the member variable. And even worse you have a memory leak. | |
Re: Then you should take the input as a string. Then if the size of the string is greater than 1 then display an error message, else compare it with a or b. Doing this way you would have to use if/else. This isn't that bad if you don't have many … | |
Re: >> I'm trying to eliminate the highest and lowest number out of 5 inputs then get the average of the remaining 3 inputs... In some instances, it gives me incorrect average.. << First find the highest/lowest integer. When getting input, make a variable that checks for high and low numbers. … | |
Re: Let me try to explain further of the algorithm below : [code] An outline of the above algorithm would look something like: // positive integer I is given P = 1 //determines when a even factor of I is found while (I > 1) //I is you input number { … | |
Re: Like super-sonic said, you need to pass your variables. This code : [code] double distance() { double center1, center2, point1, point2; double distance1, distance2, distance3; if (point1 >= center1 && point2 >= center2 ) distance1 = (point1 - center1); distance2 = (point2 - center2); distance3 = pow((distance1 + distance2), (1/2)); … | |
Re: >> result = ((x % 10) + ((x / 10) % 10) + ((x / 100) % 10) + ((x / 1000) % 10) + ((x / 10000) % 10)); You know your formula won't handle number above 99999, try doing this with for loops or recursions. | |
Re: Maybe this will help : [code] int x = 0; cin >> x; //get input, expecting an numeric value if(! cin ) //check if input wasn't a numeric value { cin.clear(); //clear the stream while(cin.get() != '\n') //discard all bad inputs up until the line end ; cout<<"Bad\n"; //tell user … | |
Re: 1) Create a array, which represents a table. 2) use a for loop; [code] for(int i = 1; i != 5; i++) myArrayTable[i] = 6*i; //say, myArrayTable is already declared. [/code] | |
Re: First use code tags when posting code so we can read it better(its the button on the tool list that says "(code)" ). here is your code with code tags #include <iostream> using namespace std; int main(void) { int myweight; int myheight; int mynum; mynum = 703; int mybmi; int … | |
Re: Use the suggestion above, although you might want to google sorting for knowledge experience. You can do this if you want to use std::sort; [code] # int main() { int x[5]; prompt(x); printreverse(x); std::sort(x,x+5); system("pause"); return 0; } [/code] | |
![]() | Re: First tell me how id has something to do with A[0].a I mean you have [code] if (id == 1) { A[0].a = 2; ... } else if(id == 2) { A[0].a = 1; ... } [/code] How does id correlates to A[0].a? What would A[0].a be if id is … |
Re: >> the problem is i dont know how to use the ifstream to read and use the code Morse that must be kept in .text file Then google it or something? Here is one from [URL="http://www.daniweb.com/forums/thread6542.html"]here[/URL] | |
Re: You mean the input is something like this ? [code] <enter fraction > 123/452 [/code] And its read as a string. If so then separate the string into 2 components the left side before the '/' character and the right side, after the '/' character. Then use the [URL="http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/"]atoi[/URL]function . | |
Re: try : [code] return ( a == 1 ? true : false ); [/code] | |
Re: Don't use goto. Period. How about you show some code and explain what you are trying to do | |
Re: Hint, a odd number plus a odd number equals a even number. | |
Re: >>If I have the class name in a string varibale, how can I instantiate an object of that class? Your question is not very clear, but my guess would be that you meant something like : [code] class Foo { public Foo() { } }; int main() { string className … |
The End.