1,608 Posted Topics

Member Avatar for yun

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, …

Member Avatar for kvprajapati
0
461
Member Avatar for RoninMastaFX

>>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 …

Member Avatar for jephthah
0
135
Member Avatar for gretty

>>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 …

Member Avatar for Lerner
0
96
Member Avatar for clutchkiller

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 …

Member Avatar for siddhant3s
0
176
Member Avatar for begnnr_help

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. …

Member Avatar for begnnr_help
0
655
Member Avatar for TheSilverFox

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.

Member Avatar for tux4life
0
763
Member Avatar for goody11

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 …

Member Avatar for goody11
0
392
Member Avatar for Zay

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 …

Member Avatar for Lerner
0
118
Member Avatar for slawted

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 …

Member Avatar for Lerner
0
218
Member Avatar for DarkoX

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 …

Member Avatar for yazooney
0
119
Member Avatar for nakemaro

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 …

Member Avatar for Ancient Dragon
1
122
Member Avatar for star34

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 …

Member Avatar for NeoKyrgyz
0
114
Member Avatar for guest7

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)?

Member Avatar for Topi Ojala
0
204
Member Avatar for bjanbkboi

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 >>, …

Member Avatar for ArkM
1
108
Member Avatar for azjherben

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 …

Member Avatar for Lerner
0
89
Member Avatar for yun

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 …

Member Avatar for vmanes
0
2K
Member Avatar for boiishuvo

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 …

Member Avatar for VernonDozier
0
532
Member Avatar for goyofoyo

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 …

Member Avatar for Lerner
0
123
Member Avatar for FaMu

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 …

Member Avatar for FaMu
0
254
Member Avatar for vs.vaidyanathan

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" …

Member Avatar for vs.vaidyanathan
0
291
Member Avatar for IT_wannabe

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 …

Member Avatar for Narue
0
125
Member Avatar for HUPextreme

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 …

Member Avatar for HUPextreme
0
859
Member Avatar for adrian_tc

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 …

Member Avatar for Lerner
0
100
Member Avatar for losh177

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.

Member Avatar for tux4life
0
164
Member Avatar for nalasimbha

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 …

Member Avatar for Lerner
0
240
Member Avatar for leowasif

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 …

Member Avatar for Nick Evan
0
317
Member Avatar for k007

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, …

Member Avatar for k007
0
2K
Member Avatar for BlackStar

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 …

Member Avatar for BlackStar
0
505
Member Avatar for karlad

[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 …

Member Avatar for ArkM
0
86
Member Avatar for anoop sharma

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 …

Member Avatar for Lerner
0
120
Member Avatar for di mo

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. …

Member Avatar for Lerner
0
207
Member Avatar for localp

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 …

Member Avatar for Narue
0
82
Member Avatar for tksrules

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 …

Member Avatar for Lerner
0
90
Member Avatar for billsmith7
Member Avatar for M^2

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 …

Member Avatar for Lerner
0
93
Member Avatar for goldstmarc

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 …

Member Avatar for siddhant3s
0
121
Member Avatar for smitem03

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 …

Member Avatar for jephthah
0
103
Member Avatar for halfnode

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 …

Member Avatar for siddhant3s
0
150
Member Avatar for guest7

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 …

Member Avatar for nucleon
0
240
Member Avatar for sabian4k

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, …

Member Avatar for Lerner
0
154
Member Avatar for namour84

[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.

Member Avatar for ArkM
0
104
Member Avatar for Akis2000

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]

Member Avatar for Akis2000
-1
797
Member Avatar for deppsgirl

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 …

Member Avatar for tux4life
0
171
Member Avatar for jam7cacci

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 …

Member Avatar for jam7cacci
0
176
Member Avatar for Behi Jon

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 …

Member Avatar for siddhant3s
0
127
Member Avatar for songweaver

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 …

Member Avatar for songweaver
0
196
Member Avatar for atreides27

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;

Member Avatar for jbennet
0
268
Member Avatar for u8sand

Try outputting the value of sTr immediately before leaving the try block in the assignment operator.

Member Avatar for tux4life
0
124
Member Avatar for endisbegun

[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(); …

Member Avatar for endisbegun
0
128
Member Avatar for CPPRULZ

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] …

Member Avatar for ArkM
0
116

The End.