537 Posted Topics
![]() | Re: the previous post makes me want to jab an ice pick into my eye sockets. ![]() |
As a proud memeber of the 10% unemployed and the 45% under-employed, I often find that I have a lot of time on me' hands. Now my dear ol' mom likes to play this game, and she's often at home alone.. so with nothing else to offer this holliday season, … | |
Re: I see that you have went out of your way to captivate us with your innovative post and well written description of your problem. However, despite your exhaustive efforts to ask a smart question, I am still curious.. how much of your homework assignment have you completed thus far? Please, … | |
Re: [quote]Write a program that asks the user to enter and item's [B]wholesale cost[/B] and its [B]markup percentage[/B]. It should then display the item's retail price. [/quote] Based on the above requiremet, it would make sense to me to have a funtion that takes two arguments: a wholesale cost and a … | |
Re: I just checked [URL="http://www.cplusplus.com/reference/stl/vector/"]the documentation for the vector class[/URL] and it appears that <vector> does not offer an overloaded += operator. It seems that only the = assignment and [ ] subscript operators are offered. It looks as though you are trying to push char type variables into your vector. … | |
Re: Consider usage of the [URL="http://www.cplusplus.com/reference/iostream/istream/tellg/"]tellg() [/URL]and [URL="http://www.cplusplus.com/reference/iostream/istream/seekg/"]seekg() [/URL]functions. | |
Re: I'll make you a deal... you translate and repost your request for help into pig latin.. and I'll throw some quality c++ code your way. | |
Re: This is really a self explanitory type of assignment. Straight-forward, no exotic techniques required. I will assume since requirement #3 mandates the use of PEMDOS precidence, requirements #1 & #2 do not; therefore, we can get away with working "left-to-right" for requirements #1 & #2. [U]Requirement #1[/U]: We have to … | |
Re: Although I am by no means an algorithms expert, I'll throw in my 2 cents anyway.. maybe I'll get lucky. In my opinion, I believe there may be a scope issue of the variables declared in line #5. The vectors are pass by value into perhaps a huge stack of … | |
Re: Whenever you want white-space delimited data extraction from file, simply use ifstream's >> insertion operator... perfect for what you are trying to do: [CODE] while(infile >> temp) { myvec.push_back(temp); infile >> temp; myvec2.push_back(temp); infile >> temp; myvec3.push_back(temp); }[/CODE] | |
Re: Just looking briefly over your code... there is one consideration that deserves special attention whenever you have a deque() type function; you should make special accomidations to ensure you will never dereferrence a NULL pointer, which I think may be the case here. | |
Re: [U]problem[/U]: you will always get zero because of line #6; you are exiting your function based soley on string sizes... [U]answer[/U]: one little tip on recursion that i found out on my own... Generally, for recursive functions, the return value of your function should also be a function parameter. any … | |
Re: suggestion: [code] //function prototype string unique_chars(string line, int index = 0);[/code] [code] //function definition string unique_chars(string line, int index) { int pos = 0; string temp; //recusive exit case if(index == line.size()) { return line; } pos = line.find(line[index], index+1) //if no other matching characters in string, move on to … | |
Re: Here is how you can compare an element, against every other element.. while we are at it, we'll erase any matching words in order to get a good word count: [code] string temp; //This array will contain single occurances of words from wordsM[ ] string unique_words[length]; //This array will serve … | |
Re: the URL for your huffman algorithm is not working. | |
Re: you could use a technique called 'pointer arithmetic' to access ye' array: [CODE] #include<cstring> //dynamic array char* array = new char[11]; //breaking into the ol' C library to handle the array cstring strcpy(array, "I Love C++"); //display the array using pointer arithmetic method: while(array != NULL) { cout << *array; … | |
Re: Hello Ms. Christina, Let me first say that I have never done any work with .pgm files. I've just looked at some .pgm examples though, and it doesn't look too terribly difficult. However, I think we might have to put our brains together to come up with the result that … | |
Re: You declared a single pointer, to a single SavingsAccount object. I believe what ye' wanted to do is to create a pointer to an array of SavingsAccount pointers; each element containing the address to a new SavingsAccount object: [CODE] //Pointer-to-pointer (or an array of pointers) SavingsAccount** accounts = new SavingsAccount*[100]; … | |
Re: 1) create an array of struct objects that will hold ID and GPA information: [CODE] struct Student { int id; double gpa; }data[50];[/CODE] 2) Now you can fill up your array of structs: [CODE] int size=0; while(infile >> data[size].id) { infile >> data[size].gpa; size++; }[/CODE] 3) Now ye' can sort: … | |
Re: there seems to be one major problem with your code.... [B]*** IT'S IN C ***[/B] (try posting your problem on the C forum, not c++) | |
Re: I'd probably do somethin' like this here: [CODE] #include<iomanip> int spaces = 0; for(int i=30; i>0; i--) { cout << setw(spaces); for(int j=0; j<i; j++) { cout << '*' << endl; { spaces++; } spaces -= 2; for(int i=2; i<30; i++) { cout << setw(spaces); for(int j=0; j<i; j++) { … | |
Re: I would suspect the letterDisplay cstring doesn't have anything in it. I think I can fix your problem without even having to double check your 'int to char' offset. Try this: [CODE] for(int i=0; i<26; i++) { letterDisplay[i] = 'A' + i; } letterDisplay[26] = '\0'; [/CODE] | |
Re: I believe you might have a problem with line #2. I just looked over the [URL="http://www.cplusplus.com/reference/stl/vector/vector/"]vector class constructors[/URL].. the only constructor with a single parameter takes a "reference to a vector" argument. In your code, you are attempting to pass an integer, which will probably throw a "could not convert … | |
Re: Serious error on line #70. You are attempting to perform an assignment operation instead of a boolean comparison. Since you are using cstrings, I would recommend use of the [URL="http://www.cplusplus.com/reference/clibrary/cstring/strcmp/"]strcmp() [/URL]function from <cstring> [CODE] #include<cstring> for (int x = 0; x < size; x++) { if (strcmp(names[x], "Jim") == 0) … | |
Re: My suggestions: You stated that you need to distribute hands to each player. I would recommend removing cards from deck() and pushing them into arrays assigned to each player; each array containing 5 Card objects. In order to determine what hand someone has, I would recommend making a function for … | |
Re: You got a few things to take care of which may or may not directly be related to your problem: 1. Please in the future, when you post on the forum, wrap your code with code tags. 2. void main() is bad, for many reasons. instead, use int main() which … | |
Re: This is actually a clear-cut easy to follow assignment. Your instructor did all the thinking for you. There is nothing left up to your imagination; all you have to do is follow directions. [CODE] class Queue { public: Queue(); Queue(int& q); void add(int); void take(); private: int array[100]; }; [/code] … | |
Re: The easiest way to read diagonally through your array would be to take the procedural approach and just write out each element of the 2d array that makes up the diagonal you want to add. But it seems like you are looking for a better method that would involve less … | |
Re: The errors are self explanitory. Your sortArray() and binarySearch() functions are prototyped to take an array of cstrings, and you are trying to pass in a string object. couple of things to try: 1) see if you can pass in your string whilst calling the c_str() member [CODE] sortArray(name.c_str(), name.size()); … | |
Re: There might be a better way to do this, but this is just my idea: 1. determine sign of the result 2. make all cstring'd numbers positive 3. big number always goes on top 4. smaller number always goes on bottom 5. perform right-to-left subtraction just like you learned in … | |
Re: click [URL="http://www.daniweb.com/forums/thread330100.html"]here[/URL] for a good example on recursion. | |
Re: try this: [CODE] for(int i=0, size=sV.size(); i<size; i++) { for(int j=0; j<size; j++) { if(sV[i].compare(sV[j]) == 0) { sV.erase(sV[j]); } } }[/CODE] | |
Re: 1. How is the data arranged in your file? Please provide an example if that's not too much to ask. 2. A vector object can handle a file of infinite size and should be the container of choice for this project. Tell your instructor that a vector is an array. … | |
Re: I just solved this problem like a couple weeks ago. [URL="http://www.daniweb.com/forums/thread327649.html"]Check out this thread[/URL]. I'm sure it will answer pretty much all your questions. Give this a shot on your own and see how you do. Then, if you have anymore questions let us know. | |
Re: [CODE] #include <iostream> #include <iomanip> #include <string> // User-defined headers #include "MediaCollection.h" using namespace std; // Global function definitions void DisplayMenu(); int main() { // Create my media collection MediaCollection MediaCollection; // Declare and initialize the variable used for the menu int menuChoice = 0; do{ cout << endl << … | |
Re: couple of ways you could do this, I will show you using a vector object, which will allow you to read in a file of any size. A vector has many of the same behaviors as an array so it's easy to use. [URL="http://www.cplusplus.com/reference/stl/vector/"]Here is a list of all the … | |
Re: [code]str1 = "$#!%"; str1 += ' '; str1 += " the "; str1 += ' '; str1 += " police.";[/code] | |
Re: Here is a muy bueno tutorial on all the cool features of the dos console, to include changing colors: [url]http://www.adrianxw.dk/index.html[/url] | |
Re: you could probably handle your modulus operation like this: [CODE] #include<cmath> class Number { public: Number(){x = 0.0;} Number(double a){x = a;} Number operator= (Number rhs); Number operator% (Number rhs); private: double x; }; friend ostream &operator<<(ostream &stream, Number n){stream << n.x; return stream;} Number Number::operator=(Number rhs) { x = … | |
Re: in your function, try the following at #17: [CODE] string temp1, temp2; while(getline(fin, temp1)) { //Handle even number of lines if(getline(fin, temp2)) { fout << temp2 << endl; fout << temp1 << endl; } //Handle odd number of lines else { fout << temp1; { }[/code] | |
Re: Just out of curiosity, how are you learning to code in c++ (ex: what method are you using, book, online tutorial, school professor...) | |
Re: 1. if argc != 3, throw error message. exit program. 2. create an ifstream object that will handle all file reading operations. 3. create on ofstream object that will handle all file writing operations. 4. open the file using your ifstream object, using argv[0] as the file to open. 5. … | |
Re: This is a double post. You just posted the same question about an hour ago. You have identified that you have 2 different possibilities for file input: 1) Date, char, 4 digits, int. 2) Date, char, 4 digits, string, double, double. I would recommend reading in your file line at … | |
Re: There are generally 2 different strategies for reading a file; read the file line-by-line (which preserves the white spaces) using getline() and then parse the line into the stuff you need, or read the file word at a time using the >> extraction operator, which is white space delimited. | |
Re: Your request is very vague. I actually still have no clue what you are asking for. If I had to guess, you require a bar graph that will display in percent a user entry vs. proper zip-code format. For example, if a user enters 48$43-0020, 8 out of 9 characters … | |
Re: [CODE] //Begin loop: 0 to 40 (years) //Year_Total = Year_total + Monthly_payment * 12 //If the Loop_Counter / 2 has no remainder, then it has to be a "2nd Year" //Monthly_payment = Monthly_payment * 1.10 //End Loop[/CODE] | |
Re: You will never.. ever.. ever.. see an assignment operation take place in boolean if/else logic. The only things you will ever use for comparison are the following: <, >, >=, <=, ==, !, !=, && and ||. These are all you are allowed to use.. ever. No exceptions. Anything else … | |
Re: I think in lines #81 and #82 you have to use the -> dereferrence operator as opposed to the dot operator. |
The End.