1,608 Posted Topics
Re: This: while(in.eof()!= 1) is probably why it is always shows the last object read in twice. You shouldn't use the return value of eof() to control performance of a loop body for that very reason. Lot's of folks have bookmarked a reference to a technical explanation for why that's so, … | |
Re: >>never use floating point comparisons in your program, never! I agree with the sentiment, but the stridency is a bit much for my taste. True, other programming languages may deal with floating point values more elegantly that C/C++, but without comparing floating points there are lots of things we couldn't … | |
Re: >>is there a way to read the file + store the names in array without repeats in one go. Yes. One approach might be to: 1) Declare the final array with enough elements to hold all the data you want. Vectors work better because they are self expanding so you … | |
Re: There are lots of tools available. You can read one char at a time aor you can read delimited text that may be stored as text or converted to numerical types. You can create code to read in a defined group of variables using a single written command. You can … | |
Re: cin >> score[num_quizzes]; num_quizzes should never be used as an index for the array as it is out of bounds and will cause a run time error. If the above was an attempt to put all five scores into the array in one call to cin that's an error, too. … | |
Re: void displayResults( ); change this to: void displayResults(int *, int); Change declaration of counter to this: const int SIZE = 9; int counter[SIZE]; call displayResults() like this: dipsplayResults(counter, SIZE); Try to define it on your own. | |
Re: Yes, it is okay to define some functions/methods in a header file but you don't want to go there yet as it will just get you more confused. If I haven't blown it myself the general rules would be functions/methods to be declared inline can be defined in the header … | |
Re: I'm not sure that x has any memory declared for it before you call the switch statement, in which case the += operator might work better than the = operator. x += y[whatever]; I'm pretty sure you can append a char to an STL string object, though I don't have … | |
Re: For future reference, for (technical) reasons I've forgotten, if I ever knew them, you need to enclose the body of a case statement in curly brackets if you declare a new variable within the body of the statement. Or maybe it's like using curly brackets with single line bodies of … | |
Re: Good luck on finding a plug in or script. There are three options I can think of. 1) You can search the net and try to find something. 2) You can hang around here (or some other site) until someone gives you a reference. 3) You can work something up … | |
Re: You could try walking through the program with a debugger or throughing in a bunch of output statements to monitor value of x, y, and a_d through a number of iterations to see if you can figure out what is wrong (of course it also helps if you've used a … | |
Re: The logic of your delete function is just the first step towards where I think you want to go. That is, once you can delete a given node no matter where it is in the list, then you have to develop a method to retain a single occurrence of each … | |
Re: What's this? operstion2 Is it a typo? Is it a global object declared in a file included in the program (ala cout or cin)? | |
Re: Students.getline(S_ID,10, '-'); This might be appropriate for a dash delimited file, but it may well cause problems if S_ID is less than 10 char long in a space delimited file, which is what post #6 implies. Be prepared for problems if you mix getline() and other input methods, like >>, … | |
Re: The first question would be why do you want to do the conversion? There may be a way to do what you want without doing the conversion. I believe that the (default?) string type used for Text member of a textBox in Visual C++ 2008 (which I believe is the … | |
Re: Another approach might be to display as you go. Here's some pseudocode to rough out how that might work: 1) declare variables needed---stream to read file and two int variables 2) use a while loop to read in numbers from file body of the while loop will: 3) divide number … | |
Re: Option 5, Delete Marks. Once you have stored information in an array you can't delete it. There, plain and simple. Having said that you can create functionality to make the program act as though the information is deleted. To implement one such algorithm you could use a combination of two … | |
Re: I haven't compiled and run your program, but the first thing that makes me uncomfortable is the way you are using the menu and th switch statement. Stop trying to make the menu display a function since you only have to write it once either way, use a default switch … | |
Re: You have mixed use of >> and getline() in the same program. If you do that you need to be aware that >> will leave the terminating char in the input buffer which will be evaluted when the next call that accesses the input buffer is encountered. If the next … | |
Re: I find terminology used to describe 3D coding tend to be confusing---just like any new language when I start using it. To me, a point has no 3D representation visually. However, multiple points making up a single image can be displayed simulating 3D on a 2D surface. Then the "Z" … | |
Re: It's not that we've forgotten what it's like to be a newbie. Quite the contrary. I suspect all of us could relate any number of stories about advancing on the learning curve. It's just that this site has made the committment to keep things out in the open. One of … | |
Re: Create a node using template syntax as per Stinomus' post above. Create a list using template declarations for the List class which has all the variables and methods you want to use. Create whatever user defined classes you need to place in the list. Declare a separate node type for … | |
Re: Narue addresses your direct question. But to me it appears that you are confusing nodes with lists. Lists are built with nodes, but they aren't nodes. I think it would be better to separate the two concepts. For example where does start_ptr come from in the above code? Why should … | |
Re: The istream input buffer still has a newline char in it from some call to an istream method that doesn't clear terminating char, like >>, etc, when you call getline() the first time. | |
![]() | Re: An ifstream is a stream in dedicated ios::in mode. You only need to use that syntax on an fstream to put it in ios::in mode, but it's not needed with and ifstream. Unless you have some discreet reason for determining the length of a file in terms of the number … |
Re: Here's a general answer to a general question: Find a pencil and paper. Write out what you need to do using psuedocode. Then write regular code using your compiler. Never write more than one function or action at a time without compiling. If you want a more specific answer, ask … | |
Re: I would declare the Passenger class before the Flight class. Then I could create an array/list of Passengers for a given Flight. In addition, I would have a 2 dimensional array of char to represent seating chart to keep track of open seats, etc. If you are familiar with vectors, … | |
Re: The output you are seeing just means that each time you go through the loop the current node has the value you put in. It doesn't mean the nodes in the list have the values you think, or that the nodes point to where you think. In order to see … | |
Re: [code]//declare and initialize variables iterator current = vector.begin iterator stop = vector.end int n = 0; //loop de loop while(size of vector not equal one) { ++n; ++current; if(current equals stop) //reset current to beginning of vector current = vector.begin if n equals 3 { erase current //reset variables stop … | |
Re: What I've seen done is to create a class to represent a single Rubik's cube that consists of an array of 27 minicubes and 6 layers called top, bottom, middle, right, left, center. Each move consists of the twist of one layer at a time relative to the other two … | |
Re: The "number" is the index of the array element. So if you were to break between the beads at element 5 and 6 in the array, that would be the same as breaking between the 6th and 7th beads in the necklass if the beads are numbered 1 through n. … | |
Re: You definitely want to use a loop, not an if statement, since you need to run the list to find the correct spot for insertion. Once you find the right spot, then you can do the insertion. Without seeing code for doing that, I can't say whether setNext() will work … | |
Re: A simple approach might be to create a file that keeps track of first date and last date used. Then each time the program is opened, before progressing to the actual program itself you read the file. If current date is 31 day or more past first date, then don't … | |
Re: Use the ifstream, inData to read the file, not cin. | |
Re: Congratulations! If you've done this using structs, then you've essentially done this using classes as well. The reason is that in C++ the only difference between a struct and a class is the default access rights to members of the class/struct. Structs have public access by default, whereas classes have … | |
Re: You want i to run from 0-51 if i is the index of each card in the array representing a deck of cards. You wand 0-12, to get 13 cards, in each suit. You want each suit to have 13 cards .[code] for each suit for each face value assign … | |
Re: Use of code tags around your posts will get you more responses than if you don't use them. The use of code tags is discussed in the watermark of the Message box as well as in the Announcements section at the top of the board. While it's not illegeal to … | |
Re: My first piece of advice is to not have the same name for a class, a class member variable and a class method. Since the TravelVoucher class is derived publically from the Voucher class and company is a protected variable within the Voucher class then the public method exchange() within … | |
Re: First, why are you mixing C and C++ style file handling (I/O in general) in the same program? You are already using cerr and file streams so my strong advice is just stick with it and drop the C style file printing and error logging. Second, I'm not sure what … | |
Re: getseat is to check that user input is valid:[code] set flag to true while invalid row number ask user for row number of seat they want accept user input if user input is valid change flag to false set flag to true while invalid seat number (that is column number/character, … | |
Re: [url]http://en.wikipedia.org/wiki/Complex_number[/url] that's an explanation of the math involved. Now use the instructions provided as a guideline for the declarations of the class variables and methods, and translate the math into C++. Show us some of your work and somebody will likely help you understand errors, answer specific questions, etc. | |
Re: Use a loop to count down:[code] cout <<"The program will be terminated in "; for(int i = 5; i > 0; --i) { i << " seconds..." << endl; Sleep(1000); }[/code] | |
Re: Add functions to your class declaration that will get the area and get the unit values and return those values when called. In main() instead of declaring a variable of type int dynamically, declare a variable of type Area dynamically. Use the set() functions to set the units and area_value … | |
Re: There are multiple sorting protocols. vmanes and sharensla mention two options, but there are more. Pick a type and research how it is done. Bubble sort is generally one of the more commonly used versions for beginners because it is relatively easy to implement. Even more basic, however, is the … | |
Re: The pointers are used two different ways. One is to declare the Complex objects on the heap using dynamic memory as opposed to on the stack using static memory. The other way is to pass the Complex objects to member variables by reference rather than by value. Large objects are … | |
Re: Start at the beginning. You know user will not be able to enter more than 20 numbers, but you don't know exactly how many until run time. One approach is to declare memory for 20 possible numbers and use only as many as indicated. A second approach is to wait … | |
Re: cout << "input number of students"; int numStudents; cint >> numStudents; student * students = new students(numStudents); Be sure to delete any memory you declare dynamically using the delete[] operator. In this case, when you are done with the students array, delete using: delete[] students; | |
Re: Try outputting the value of sTr immediately before leaving the try block in the assignment operator. | |
Re: [code]struct Date { int day; int month; int year; void display(){cout << day << '/' << month << '/' << year;} }; struct Node { string item; int count; Date expirationDate; Node *link; }; Node * newNode = new Node; newNode->expirationDate.day = 1; newNode->expirationDate.month = 1; newNode->expirationDate.year = 2010; newNode->expirationDate.display(); … | |
Re: ios::ate is (primarily) for file writing, it truncates---overwrites previous file contents. ios::app appends to previous file contents. What type is SSN? If its a STL string then you can do something like this, where the += operator will append input to end of current string once it is validated: [code] … |
The End.