1,608 Posted Topics
Re: If you have a system with 1000 particles the information you will need to save/enter will be the same whether you have individual particles, arrays of attributes or a container of particles. Who said you won't have to worry about out of bounds checking when using vectors? To my knowledge … | |
Re: One method to right justify shorter string: Determine the lengths of A and B Determine which string is longer Determine the number of zeros to prepend to the shorter string Create a string of zeros to prepend to the shorter string Concatenate the string of zeros and the shorter string | |
Re: HotDogStand.DogCounter = 0; HotDogStand is a type, not an object, so use of the dot operator in this context is an error. On the other hand, each element of CartSales: CartSales[i] is an object of type HotDogStand, so using the dot operator on each of these objects to allow you … | |
Re: Please learn how to use code tags when posting code to this board. Change this:[code] // Copy to the content for(int i = 0; i < SIZE; i++) for(int j = SIZE; j < SIZE * 2; j++)[/code] to this: [code] for(int i = 0; i < SIZE; i++) //assign … | |
Re: Ideas: 1) consider moving the using statement outside of and before declaring main() 2) Throughout your code you use this syntax: if (actionX == y. || actionX == y) Why? All the actionXs are declared to be ints so the period after the integer, y, may not be doing what … | |
Re: >>What I'm wondering is is there a way to randomly display a string array and avoiding duplicates? If I have an array of x unique strings I could write code to display all x strings randomly, but display each string only one time, yes. If that's what you are asking. … | |
Re: >>is any other way with less steps If you didn't have the restrictions placed on the project, definitely. With current restrictions and without seeing your current code, who knows if it might be done with fewer lines/comparisons or not. | |
Re: Unless your goal is to be the equivalent of an olympic athlete, I agree with Ancient Dragon. But if you're willing to sacrifice other aspects of your life to the pursuit of a goal you hold passionately I guess that's up to you, as long as you are aware that's … | |
Re: [code]printing term of polynomial without coeff if coeff == 1 and without exponents if exp == 1 and without variable or exp if exp == 0: if(coeff != 1) cout << coeff if(exp > 1) cout << "x^" << exp; else if(exp == 1) cout << "x"; //else if(exp == … | |
Re: The alternative to prefixing "everything" with st:: is to place the line: using namespace std; after the list of includes (in this case between the first two lines of the program). Once you've read further in the book you should learn why this statement isn't necessarily the prefered option, though. … | |
Re: My toe hurts, can you tell me why? That question is admittedly a little worse than yours, but not by much. Tell us what sort of a problem are you having---Program crashing? Not compiling? Runs okay but gives wrong output? Error/warning messages? Some ideas, that may or may not have … | |
Re: 1) check the file for all string literals Can string literals include embedded quotations? If so, then the project becomes harder. 2) Also, I have to ensure it ignores comments that include quotations. Again, you can use a brute force method or use find() on an STL string to find … | |
Re: Files work best for saving data, not using data interactively, as the response time for retrieving data from file is slow compared with finding data from within RAM. For doing what you want with 15 words it is much easier to read all the words into a container, and an … | |
Re: 1) if the user doesnt put in a valid response then a message will cum up and they will go back 2 the beginning until they do it correctly. Add another section in the switch statement after the case 'D': that looks something like this: default: cout << "input error. … | |
Re: [code]{ //start body of loop .... case 'A': if money_left more than cost-of-A money-left -= cost-of-A increment number-of-items-bought-today money-spent += cost-of-A else sorry you do not have enough money to buy this break; .... } //end switch if money-left not enough to by cheapest item available sorry you do not … | |
Re: Declare an int variable for each item you can purchase and initialize them all to zero. Do this at the start of the program. Then increase each variable within the appropriate case statement as an item is purchased. | |
Re: There are two types of lines in your rectangle. The top and bottom line both look alike and all the lines in between have the same appearance. The top and bottom all use the same symbol. The interior lines all have the first and last char the same as the … | |
Re: replace this:[code] cin >> mug; cin >> teeshirt; cin >> pen; cin >> quit; mug = ('A' || 'a'); teeshirt = ('B' || 'b'); pen = ('C' || 'c'); { if ((mug == 'A') || (mug == 'a')) { mug = 2.50; } else if ((teeshirt == 'B') || (teeshirt … | |
Re: Use an outer while loop to control the number of line. Within the outer while loop use two loops in sequential manner. The first inner loop will control the number of spaces to print for the line you are on. The second inner loop will print the sequence of numbers … | |
Re: When thinking about a question posted about creating a LargeInteger class the other day I realized that to access the indexes of a string with the [] operator you need to use an int, which has an upper limit in size which is probably less than 1,000,000,000,000, unless the compiler … | |
Re: Based on representative file lines the following strategy using sequential calls to find() and substr() and using a stringstream to convert an STL string into a numerical data type might work. Below is narrative description of a possible protocol and a rough pseudocode of what it might look like: use … | |
Re: The standard deviaion is the square root of the sum of the variations from the average squared divided by the number of elements in the population. numbers is an array of type double N = number of elements ine numbers x = average = sum of all elements in numbers … | |
Re: There are any number of ways to do this. If I assume the file has a number of lines of text and each line has two fields, one being a word which is preceded by a space which is preceded by a number, then I would create a class called … | |
Re: Before jumping to the math function members have you run your code to see if you can declare a Matrix, delete a Matrix, copy a Matrix and assign one Matrix to another without the program crashing? In particular I have questions about the deletion operator, and the copy constructor. Do … | |
Re: 1) I'm having issues with reading data into a 2D array.... It's probably easiest to use a nested loop to read in values. Since it is given there will be 50 ints in the file you can use for loops: int temp;[code] outer loop to control row inner loop to … | |
Re: Welcome to the board! There is a number of problems with your code, but since I haven't memorized the meaning of error # 2447 I can't say which one it is. 1) The first thing I would do is remove the semicolon at the end of this line: int main(); … | |
Re: to look at an online version of the difference between strcpy() and strncpy() go to cppreference.com and look at Standard C string and Char section. Without further clarification I would expect your first and third versions to fail given that char * needs to have memory assigned to it before … | |
Re: You could do the arithmetic in "two" steps:[code] 1) Determine the sign of the result: A) Addition a) if operands have same sign, then result has the same sign as the operands b) if operands have different signs, then result has sign of the operand with the largest absolute value … | |
Re: line 43: you need some way to stop the loop. using a line like: while(!valid); should do it. line 84 should be: return true; else how are you going to indicate that all char in the input are valid char for a roman numeral? | |
Re: I think of an iteration as being a single time through something or a version of something that changes over time. So if I use a loop to increase the value of x by 1 ten times there are 10 iterations to the process. There are 20 some versions/iterations to … | |
Re: I noticed you have commented out all the calls to display(). I suspect that's because when you try to display the lists you don't get what you expect because the addToHead() function is wrong and all the lists you create in main() use addToHead(). You always assign the new node … | |
Re: jBat describes one way write data to file. You must decide what you want to write to file. The 0x notation won't appear as such in a text file using jBat's protocol. Instead what will appear is the char represented by the integer (0x...) in whatever character set (often ASCII … | |
Re: There are two logical endpoints to stop calculations. One is based on the width of the boxes. The other is on the variation in the area under the curve; that is, decrease the width of the boxes as much as you need to until the change in the area under … | |
Re: the header file known as string.h and the string header file in namespace std are not the same. Therefore when using the std:: prefix in declaring string objects in the Car.h file you don't have the correct header file included. | |
Re: [url]http://www.cppreference.com/wiki/string/start[/url] That's a reference for the member methods of the STL string class including find_first_of() and subst(). You would probably want to use those two methods in combination to separate out tokens based on the criteria you have. An alternate would be to change the STL string into a C … | |
Re: url = sUrl.c_str(); This won't work because you can't assign one Cstyle string to another. At the top of your code add the line #include <cstring> and then use this: strcpy(url, sUrl.c_str()); for the above line. There are other rules for using C style strings. If you are going to … | |
Re: IMO this is the result of the indescriminant use of typedefs. On line 266 TempStudent is declared to be of type StudentArray. Therefore, rather than the :: operator to access member variables of whatever a StudentArray object is, you will need to use one of the following: TempStudent.memberVariable, TempStudent->memberVariable or … | |
Re: How many digits are in each element of basis and how many do you see when printing them to screen in line 35? | |
Re: Is the input string a null terminated char array (C style string)? What type is the output to be? What type(s) do you want the token(s) to be? | |
Re: If the array of customers may hold less than the maximal number of possible customers then you should keep track of the actual number of customers anyway. Under that scenario you can evalute the actual number of customers. If it's zero, then display menu A and if it isn't, then … | |
Re: ??it lets me enter the numbers, but than exits the command prompt right after It may be doing everything you want but just not keeping the console screen open so you can see it because it's not been told to do that. Whern the program is done, the console closes … | |
Re: You don't want to reverse the string, you want to reverse the words in the string. First you need to break up (parse) the string into substrings (words). But how are you going to know how many words there are and how will you know which order they are in … | |
Re: Give neg and pos a meaningful value, probably zero, before trying to use them, just like you did for sum. Pass neg and pos to getNum() by reference. Call countNum() from within loop of getNum(), probably between line 31 and 32, otherwise you will only be able to process the … | |
Re: Post at least the list of header fies included in your program and the user created header files, particularly the CHESS.H and CHESS.CPP file. Looks like there are some dependency issues with lack of necessary header files. Also indicate what compiler and OS you are using. | |
Re: You can overload operators to do whatever you want them to, almost. For example, you could overload the % to increment an int by 33 if you wanted. That being said, most overload implementations stick to reasonably traditional actions. So overloading the + operator almost always means addition if it … | |
Re: I'd check for denominator equals zero and if not, then call the function passing a, b, result and remainder to the funciton with result and remainder being passed by reference. When the function is done, then print out the numerator, denominator, result and remainder.[code] void div(int temp, const int b, … | |
Re: 1) How about declaring an array of pointers to pointers to int? Declare memory dynamically for both the array and the pointers it holds and then delete one pointer at a time. 2) How about the reverse of "expanding" an array? Declare temp using enough dynamic memory to hold the … | |
Re: I sometimes have problems using the [] operator for STL strings in the fashion you are. I believe this has to do with the default size of an STL string and that using [] doesn't automatically increase size of an STL string when needed whereas other operators like + and … | |
Re: Line 213 returns an int but line 217 says return type is void. A protocol for calculating time interval between current time and other time might look something like:[code] //detrmine which time is ealier than the other if current time after other time later time = current time earlier time … |
The End.