1,608 Posted Topics
Re: Do a routine swap manually or use the swap() method from STL algorithm header file. The routine swap involves identifying the two items you want to swap, declaring a third item of desired type and doing this: temp = B; B = A; A = temp; Be sure your struct … | |
Re: Here's some answers, each with a grain of truth, but none of which I suspect your instructor is expecting. To find the real answers I recommend you search through your notes, your book, or, if you must, search the web. Q.no.1: What is the difference between zero and null values? … | |
Re: If the last row has zero spaces to the left of the *s then somehow you have to get K equal to zero. row number zero has 1 * row number one has 3 *s row number two has 5 *s row number x has (2 times the row number) … | |
Re: Do you have a problem with the math involved or the C++ involved? The easiest way to do the math you need using C++ is to use the modulo operator. Assuming m and n are both postive integers, if the result of m % n is zero then, n is … | |
Re: Here's one approach: add an attribute called degree to linkedList class. It will be equal to the number of terms in the linked list. All terms will be listed in linkedList, even if coefficient (aka value) is zero. add a friend function to linkedList class to overload the + operator … | |
Re: Why would Node have an insert method? The insert method declared doesn't insert anything anywhere. It just declares a new Node, which seems dubious. Move the insert function to Set itself. Basically you can make the Set class a modified List class (or a wrapper around a List class), but … | |
Re: In math: M(i,j) = ( k = 1 to n ) Σ { A (i,k) x B (k,j) } In C++: There are 8 variables to deal with: M, A, and B are matrixes (multidimensional arrays in C++ speak) rows is the number of rows in M and the number … ![]() | |
Re: Conditionals and loops will probably be important to your program, as they are in just about any program. Remember that if the response is more than one character long that isn't a digit, then you have to use a string variable (there are several versions of string variables you could … | |
Re: You are welcome to do what you want with your compiler and you machine. You should be aware however that there is a jargon associated programming in C++ just like there is in most other areas of life. One of the traditional assumptions (jargon) when talking about lists in C++ … | |
Re: Do you have a class to represent a card? Does the class have the ability to distinguish when one card is bigger/lower than another? What are the rules of the game? Is it more like "War" or more like "Rock, Paper, Scissors"? | |
Re: play around with the value of n and see what happens. In particular, try changing n from 1 to 2 to 3 etc. The function as written isn't specific for rounding to 2 decimal places. Also, look into the stream manipulators, and here I'm thinking of the fixed and setprecision … | |
Re: Nice link! Any other recommendations per chance? | |
Re: Be sure the sum variable is initialized to zero before you try adding to it. Otherwise looks pretty good. I'd probably do something like this[code] double stdDev; double sumOfSquaresOfDifferences = 0; for (int i = 0; i < size; i++) { sumOfSquaresOfDifferences += pow(average[i]-a,2); } stdDev = sqrt(sumOfSquaresOfDifferences/(size-1));[/code] to increase … | |
Re: >>how can i add main for this First, develop a protocol to display a Vector2D object. You could write a class method or you could overload the << operator for the Vector2D class. In my example below I assume an overloaded << operator has been developed. Second, you might consider … | |
Re: Not sure what this is supposed to mean: >>I have to modify my sort function so that when a character is passed through it which is coded in main not given by a user it arranges it by that. If you are supposed to let user decide what gets sorted … | |
Re: [code] void CharNode::headInsert(CharNode* &head, char *d) { head = new CharNode(d, head); }[/code] What the above says is create a new list every time you insert a new item. T'm almost positive that isn't what you want. I strongly recommend you have two classes, not one. One to define a … | |
Re: I find your problem description difficult to read/decifer. I would start by putting the following lines: cout << "num is " << num << endl; cin.get(); between these two lines: inFile >> num; intList.InsertItem(num); to be sure you are reading in what you think you are. I suspect the reason … | |
Re: Try sending form() to getData() and pass row by copy rather than by reference. Within getData() assign the actual seat number by converting input row number and column char to appropriate index numbers for the array. No need to cast anything that I can think of. It will complicate the … | |
Re: Since you are storing pointer to type objects why not try using polymorhism by writing a base method called displayPay() declared with the keyword virtual that would be overloaded with in each of the inherited classes. Then you can loop through the vector of pointer to StaffMembers calling the displayPay() … | |
Re: First define how you want the file to be structured. Given the variable length of several of the member variables (strings) within struct objects I would probably go with writing each variable to file separately rather than trying to use the write() stream member function. Given the possibility of space … | |
Re: Why not start with a list of Clusters. Say each Cluster starts as a list of points having size of one. If you wanted you could start with the first Cluster. Find the closest Cluster to it. Merge the two. Repeat until you have come to the end of the … | |
Re: Write it out by hand. It might start like this: [code]enter two numbers. calculate the product of the two numbers. determine which number is larger, call it A, and call the other number B. use an accumulator, initialzed to zero as long as A is above zero if A is … | |
Re: A is a square matrix. In C++ that means A is a multidimensional array of doubles like this: double A[x][y]; where x and y are constants and known at compile time. Alternatively, since x and y probably won't be known at compile time, then you can use dynamic memory to … | |
Re: C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winioctl.h(641) sounds like you have a name clash with a variable type declared in winioctl.h included when you included the windows.h file. You could check by commenting out the windows.h include and recompiling. | |
Re: l is a terrible name for a variable because it is very difficult to tell if it is an el or a one. Ditto for 1. Use something more desciptive, maybe something like numDigits. Don't use variable names that are the same as a function name, like find. Again too … | |
Re: you only need to swap the first half with the second. The terminating value for the loop shouldn't be zero. It should be half of count, or something like that. I'd do it by counting j up rather than counting i down, but you should get the drift. And you … | |
Re: error C2065: 'friction' : undeclared identifier means there is not free standing variable called friction. Yet, on line 23 you write code suggested that's what you want. That compiler is saying you can't do that. friction is a member variable of the Block class, but to do anything with it … | |
Re: You can edit file contents without reading the whole file directly into a program, under some circumstances. To my knowledge there are several situations where this is possible. Under one scenario you read in just the data that needs to be edited, make the changes and write it back. You … | |
Re: Here's one possible scenario. All players need to play a card, have a hand, keep a score, whatever, whether it is a computer or an enduser. Maybe you overload that you overload that so the computer outputs snide remarks like "Ha Ha, I won that one", or "Drat" or whatever. … | |
Re: take out the delay()s. They add nothing to the code and are distracting.[code] scanf("%d",&find); while(loc < 5) { if(nos[loc] == find) { printf("\n The location is: %d", loc + 1); } ++loc; }[/code] For maximum learning benefit explain each change from my code to yours. For better code writing, write … | |
Re: Sounds like you have a broad idea presented and you need to develop a project within those guidelines. I wish my boss did that more often! One possibility is to set up computer programming business. Then charge outrageous sums for your services. Say $5 per line for finished code. $3 … | |
Re: Let's see. I want 5 items of type a at 315.74 dollars each. How much is that going to cost? And if I want x number of products y that cost z dollars each how do I keep doing the same type of calculation over and over again as long … | |
Re: This should get you pretty close. Each term has the form (-1^n)*((x^n)/n!) where 0! is defined as 1 and x^0 is also defined as 1. E(x) is the sum of the number of terms you want to use. You calculate the sum using a running total within a loop adding … | |
Re: >>i have to create a w64 structure and the array will be of that type. >>a two dimensional array where the first dimension is the 2^14 ( that is 16k) and the other is 8 So do you want something like this?[code] struct w64 {}; w64 buffer[16000][8]; [/code] | |
Re: The whole list is probably irrelevant. Just post a copy of the first 1 or 2 errors you get. The stl_ files referenced by the error messages are probably included in the vector header file. As a wild guess, you might try putting lines 1, 2 and 3 in the … | |
Re: The first two lines of the triangle must be given. However, after that you can calculate each value on your own as needed. One way is to recognize that if you number the lines of the triangle 1 to x then the maximum number of values per line is also … | |
Re: Welcome to the board/community! When posting code please use code tags as discussed in the watermark in the Message box, or in the announcement section at the top of the board. This will preserve the indentation you use (hopefully) when writing code. Without the indentation many of the more experienced … | |
Re: digit isn't given a value if select == 1. change the variable used by the switch statement to character instead of digit. Place break statements after the output statement in each case. Otherwise all digit values after the entered value of character will be displayed. | |
Re: Make next a pointer to type. Then move line 8 to line 16 and see how it works. | |
Re: Her role as moderator is less important than her role as contributor, though both are highly respected. | |
Re: Is there a reason why you have placed the definition of insertOrd() before the class declaration? Within insertOrd() you need an opening curly brace between these two lines. [code] while(current!=NULL && !found) if(current->info>=newitem)[/code] and you need a closing brace for the while loop as well. Keeping your indentation consistent and … | |
Re: change this: system("pause"); return(0); } } to this:[code] system("pause"); } return 0; }[/code] Note how consistent indentation helps solve the problem! | |
Re: [code]else { if (seats[position]==0) cout<<"You have booked "<<position<<".Thank you\n"; seats[position]=1; //to change the array from 0 to 1 }[/code] In addition, pay a little more attention to proper indentation. That will allow you to spot errors easier. I suspect you want a set of curly braces around both of the … | |
Re: >>Use two strings provided in main and then the function is called to add the rwo strings. That's what strcat() does when using C style strings. Do you mean you need to write your own version of strcat() for educational purposes, that is, you are not allowed to used strcat()? | |
Re: I guess there are two schools of thought regarding how to view the content of a queue. One school says you can only look at the top of the queue so you have to pop everything off the queue one element at a time to find out what's in there. … | |
Re: William Hensworth's code declares memory for the new string and copies the char from the original string into the new string, but it doesn't copy the char from other into the new string. You will need to add another loop to do that, but it's only a slightly different version … | |
Re: Do you intend to allow negative numbers? If not then somehow you have to identify which input is larger, x or y. (Padding the smaller one with zeros if the they don't have the same number of digits is useful, just like with intadd().) The larger ultimately determines the value … | |
Re: To successfully read a file you need to know exactly how it is organized. If the file is organized with the Album Title on the first line and song titles one per line thereafter like this: Green Chili's Greatest Hits How Hot Dreamy 7 Days and 7 Nights the using … | |
Re: conio.h isn't bundled with many compilers/IDEs. You can do what you want to do without it by thinking of the page as a grid of cells. The grid can be viewed as lines of cells, like a chess board. Each cell may hold 1 character. Some char may be visible … |
The End.