1,608 Posted Topics
Re: First of all decide whether you are going to use C or C++. The ifstream object and std::string object suggest you are using C++. However, the prinf() for such a simple object suggests you are using C. It's important because the word class is a keyword in C++ and shouldn't … | |
Re: Well, here's one possible starting point, but you really need to determine how you are going to approach this on your own. [code] class pharmacy string name string address string phone number string email address list<Product> inventory list<Invoice> sales class Product string name double cost class Invoice Date date list<Product> … | |
Re: First thing I'd try is eliminating line 15 as the int named myfile declared there may conflict with line 60 where you declare an ofstream by the name of myfile as well. If that doesn't work, and it may well not, then I'd try reposting, enclosing all your code, including … | |
Re: 1) Determine length of the keyword 2) Create an array of the English alphabet 2) Find the index of the element in the English alphabet equal to the the offset char. 3) Remove the letters in the keyword from the English alphabet array creating an array holding the depleted English … | |
Re: My, my, impatient little poster aren't we. If you are going to allow removal of a random node from within a list there are several protocols I've seen. In the first scenario you need to know the node to remove, and, if the node to remove isn't the first node … | |
Re: What a wonderful demonstration of the tremendous flexibility of the language. I'm equally impressed by the command of language necessary to create the demonstration. Thanks. | |
Re: How about if you sort the neighbors by distance. Then search the array from closest to furthest looking for closest unique distance determined something like this: WARNING: Following snippett not rigorously tested[code] type neighbors[capacity] int size = number of neighbors for(i = 0; i < size - 1; ++i) { … | |
Re: Create an internal representation of the maze using a multidimensional array of char. Then you can check the value of each element of the array as if were a visible cell in the maze. If the value of the element is the equivalent of a wall, then you can't go … | |
Re: Let's analyze this line: if (str[i] != '(' || str[i] != ')') Start with this: str[i] != '(' It will be true unless str[i] == '('. A similar statement can be made about this: str[i] != ')' But if stri[i] == '(' then it can't be ')' and visa versa. … | |
Re: Yes, you should be able to do that. You might want to look up use of switch statements and use a menu to select the task. Here's a rough sketch of the process, but looking it up in a book to learn the details is strongly recommended. [code] cout << … | |
Re: [code] int y, d, m; char c; while(flag[2]) { cout << "\nEnter your departure date (MM/DD/YYYY) : "; cin >> m >> c >> d >> c >> y; Date d1(d, m, y); if(d1.year() == 1999) cout << "ERROR: \"" << m << c << d << c << y … | |
Re: Define column lengths, determine the length of each word (think string), pad the word with spaces to reach appropriate column width and then display padded strings OR use output modifiers/manipulators like setw() or setwidth() or printf() format modifiers, etc. | |
Re: sPtr is the a pointer to the first char of the array of char being passed to the function. and *sPtr is the same as sPtr[0]. You could write it this way I suppose. for(sPtr = &sPtr[o];*sPtr!='\0';sPtr++) but that seems a little clunky, even if it is more explicit. BTW … | |
Re: First, the code you posted uses pure C syntax so it may be better posted on the C board. However, the logic will be the same whether it's C or C++, only the syntax will differ. Since the area of a circle is the product of pi times the square … | |
Re: I'd start with the basic model of s.o.s and add the following checks: n must be less than str.size() i must be less than str.size() - n To make the function more secure I'd consider changing the function prototype and definition to accept only strings as input so if user … | |
Re: Thanks for using code tags! If you are going to continue with your coding career you will need to learn how to handle error messages from your compiler. Usually tackle the first one or two and recompile. Often a number of the remainder will go away, though sometimes new ones … | |
Re: Heres the same basic information using a slightly different explanation: Given: string a = "hello"; a is not an address. The STL string object may have within it a char * (to be used as a C style string) as a member variable, in addition to other member variables such … | |
Re: First, use code tags when posting code to the boards on this site. Second, main() should have return type int, not void. Third, you should be using the iostream header and a using statement like : using namespace std;, assuming your compiler is compliant with that syntax. Fourth, You have … | |
Re: Each istream method/operator has it's quirks. getline() discards the delimiting char once found, unlike >> or gets(). Therefore, the call getline() within the conditional places Hello in one and discards the delimiting comma. The first call to >> places 1000 in Number but stops at the second comma since commas … | |
Re: It sounds like you only need one of the two sets of functions listed below: float centToFahr(int); void fahrToCent(int, float &); void centToFahr(int, float &); float fahrToCent(int); The int value is the number to be converted from one scale to the other. The float is the number after the conversion. … | |
Re: When I've encountered this error before it was generally when I was removing debugging code and erased one too many curly braces. To track it down I'd start commenting out whole chunks of the program until I got it to compile and then start adding small sections back one at … | |
Re: [code] srand( time(NULL) ); int r, rsize; for (int i = 0; i < rsize; i++) { r = rand() % max + min; const int w = r; } { const int p = rsize; double a [p]; for (int j=0; j<p; j++) { a[j]; a[j] = r } … | |
Re: >>Can anybody will help me to introduce the species member in the program? I would like to add species as member in public domain I'd do it like this: [code] class TREE { friend ostream &operator<<(ostream &, const TREE &); public: int Tno; int x; int y; int z; float … | |
Re: strcpy() needs two C style strings, not an STL string and a C style string. The parameters are strcpy(to, from); where to is the string to receive and from is the string to donate. There is a variation called strncpy() which takes a third parameter indicating max number of char … | |
Re: First thing I'd try is to make intent of this statement perferctly clear by adding additional (): if (matrix[i][3]==0 && matrix[i][4] ==1 || matrix[i][3]==1 && matrix[i][4] ==0) like this:[code] if ((matrix[i][3]==0 && matrix[i][4] ==1) || (matrix[i][3]==1 && matrix[i][4] ==0))[/code] If that didn't work I'd try to localize the problem by … | |
Re: Hopefully you've absorbed some of the information you've been given and used to write your code so far and can now start putting it into practice. For example what's going to stop this loop from reading to the end of the file? [code] while (infile.good()) cout << (char) infile.get(); [/code] … | |
Re: Please wrap code in code tags! This will preserve indentation you (hopefully) use when actually writing the code. The use of code tags is discussed in the watermarks of the message entry box and in the announcements at the top of the board. Problems I see in the actual code: … | |
Re: Look up bubble sort as it appears that that is what you are trying to do. Bubble sort usually is done with two loops, one nested inside the other. The outer loop controls which value you are looking at. The inner loop looks at all values in the array with … | |
Re: >>find a way to know when the string has ended look for a null char, that's the end of the string. >>find the last "]" of the string. Probably the easiest way is to start at the end of the string and search backwards through the string, though, if the … | |
Re: Since I don't see that you've posted to the C board and you are using pure C syntax within the code I'd encourage you to post there. I note a problem with the syntax you're using to declare arrays. When declaring arrays the size needs to equate to a const … | |
Re: You've alread used virtual functions in your code (lines 62-72) so presumably you know what they are in addition to how, why and when to use them, etc. In addition you already have code (lines 101-103) to do the calculations you want to do in calcInt(). Therefore I don't understand … | |
Re: >>How do I get the list to be sent to an output file? Should I put it in the MyList::print function or keep it in the Main function? My advice---Neither. Create a writeToFile() method for the MyList class. My second choice, create a generic print function and pass it the … | |
Re: You can't have an array of type char where each char in the array points to another char. The elements in an array either have to be of type char or to type pointer to char, but the elements can't be both at the same time. Though I have to … | |
Re: I suspect you've posted your interpretation of what you're supposed to do. I suspect there are a few more details that exist in the original instruction set. Here's how I would start thinking of class design based on the information posted and trying to read between the lines: [code] CarDistributor: … | |
Re: Sounds like a common project. I doubt that anyone will post a completed project for you. However, if you have a specific question feel free to ask. | |
Re: Think loop any time you want something to repeat. Just pick an appropriate control conditional for the loop and include any code you want to repeat within the body of the loop and you should be well on your way. If you don't already know there are three types of … | |
Re: Streams have a number of methods that may be useful. For example peek() allows you to look at the next char in the input stream without removing in from the stream, putback() allows you to put last char read from input stream back into to the input stream, seekg() resets … | |
Re: Her'es an abbreviated version of pseudocode that demostrates using nested switch statements that can be put in a loop in an effort to do this. You can choose which menu is for which set of choices. [code] cout list menu cin selection switch selection case displayActionMenu(choice) switch choice case list1.action1 … | |
Re: How about something like this: [code] class A { int avar; public: int operator++(int) { int temp = avar; ++avar; return temp; } }; [/code] | |
Re: int temp[20]; ProgEven >> temp[20]; The second line overreads the end of the array. You are trying to put information in the 21st element of temp, but temp can only hold 20 elments because that's how many you declared in the first line. The largest valid index of and element … | |
Re: Please indicate what line your compiler indicatecd the error was associated with. The actual error may not be on that line, but it's usually pretty close if it isn't. | |
Re: While this: switch (course1, course2, course3) May work I doubt it's going to do what you want. Only use one variable name inside the ()s. I'd rework the program. Have the user to input how many courses they want to take, up to three courses. Accept the user input into … | |
Re: Here's a revised version. It's not tested so you'll have to test it. If you don't know why I changed something ask. Basically you seemed to be trying too hard. [code] #include <iostream> #include <fstream> using namespace std; char get_Data(ifstream&); int convert_Roman_to_Decimal(char); int main () { // Declare variables char … | |
Re: You've declared a function with the correct name and correctly accepts reference parameters but you've forgotten the integer parameter. Initialize numDays to zero but putting a zero after the assignment operator. To have the user input a number of days use cout to prompt them to enter a number and … | |
Re: >>//system ("PAUSE"); // i am getting an error here, when i want the system to pause... return 1; Don't use system() functions unless absolutely necessary. Use something like cin >> ch; or cin.get() or some other istream method to pause the program until user inputs something if want before the … | |
Re: You will need a loop someplace to calculate more than one students grade, probably using everything in main() up to but not including this line: char letter; as the body of the loop. You either need these: double quiz1; double quiz2; double midtermExam; double finalExam; double courseAverage; which, by the … | |
Re: In a typical program when all calculations are done and no further input is expected the program will terminate and the console screen will disappear. That's what happens in program #2. To have the program pause so you can see what's sent to the screen you can place a cin.get(); … | |
Re: The first for loop is commonly called the outer loop and the second the inner loop and the two of them together are called a nested loop. Nested loops seldom go more than 3 deep, but can go deeper. The outer loop says the first column can range from 0-2 … | |
Re: Try putting a semicolon after the } in the declaration of the TsuPod type | |
Re: To my knowledge, there is no standard way to clear the screen in C/C++, because that's not the way the console was designed. If you want to clear the screen then you have to do it using some non-standard way. You can write your own function to do this or … |
The End.