1,608 Posted Topics

Member Avatar for dkwantee

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 …

Member Avatar for Lerner
0
519
Member Avatar for mostafa mahmoud

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

Member Avatar for Narue
0
103
Member Avatar for nurulshidanoni
Re: Why

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 …

Member Avatar for nurulshidanoni
0
112
Member Avatar for aminit

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 …

Member Avatar for Sky Diploma
0
299
Member Avatar for d0ugg

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 …

Member Avatar for unclepauly
0
89
Member Avatar for infernojmd

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.

Member Avatar for Lerner
0
108
Member Avatar for tosh123

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

Member Avatar for tosh123
0
152
Member Avatar for jiah

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 …

Member Avatar for TMD
0
507
Member Avatar for Arne Kristoffer

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

Member Avatar for Lerner
0
149
Member Avatar for Rotvailera

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

Member Avatar for Lerner
0
72
Member Avatar for leverin4

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

Member Avatar for Lerner
0
130
Member Avatar for Mel(plusplus)

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.

Member Avatar for WaltP
0
84
Member Avatar for lizhiyuan

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 …

Member Avatar for Lerner
0
105
Member Avatar for mhuneidi

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 …

Member Avatar for Lerner
0
151
Member Avatar for Narue

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 …

Member Avatar for ivailosp
1
680
Member Avatar for Galaxiaunit

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 …

Member Avatar for Traicey
0
574
Member Avatar for VernonDozier

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 …

Member Avatar for VernonDozier
0
925
Member Avatar for bramprakash1989

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 …

Member Avatar for Lerner
0
145
Member Avatar for Jennifer84

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 …

Member Avatar for Ancient Dragon
0
206
Member Avatar for Moporho

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

Member Avatar for JRM
0
183
Member Avatar for mzdiva041986

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 …

Member Avatar for mukulbudania
0
124
Member Avatar for ichigoSJ

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

Member Avatar for dougy83
0
103
Member Avatar for maheshkumar

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

Member Avatar for Ancient Dragon
0
109
Member Avatar for kartouss

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 …

Member Avatar for vmanes
0
5K
Member Avatar for andyg55

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 …

Member Avatar for Lerner
0
167
Member Avatar for amroto

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

Member Avatar for amroto
0
484
Member Avatar for Majestics

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

Member Avatar for Lerner
0
57
Member Avatar for Ben10

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 …

Member Avatar for Ben10
0
127
Member Avatar for Jennifer84

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

Member Avatar for Jennifer84
0
95
Member Avatar for nelsonsu

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 …

Member Avatar for nelsonsu
0
261
Member Avatar for gothicmisery85

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 …

Member Avatar for Lerner
0
212
Member Avatar for darklich13

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

Member Avatar for darklich13
0
169
Member Avatar for rsk8332

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 …

Member Avatar for Agni
0
143
Member Avatar for R3B3L

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

Member Avatar for R3B3L
0
128
Member Avatar for hafhag

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.

Member Avatar for hafhag
0
288
Member Avatar for monroe85

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 …

Member Avatar for Necrolis
0
72
Member Avatar for GPXtC02

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 …

Member Avatar for GPXtC02
0
804
Member Avatar for Bastler

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 …

Member Avatar for Lerner
0
81
Member Avatar for amitahlawat20

How about something like this: [code] class A { int avar; public: int operator++(int) { int temp = avar; ++avar; return temp; } }; [/code]

Member Avatar for Lerner
0
64
Member Avatar for d0ugg

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 …

Member Avatar for Lerner
0
150
Member Avatar for guitarrick

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.

Member Avatar for guitarrick
0
131
Member Avatar for yarita

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 …

Member Avatar for Lerner
0
162
Member Avatar for mamaChaos

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 …

Member Avatar for mamaChaos
0
98
Member Avatar for arlene1

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 …

Member Avatar for amitahlawat20
0
180
Member Avatar for bugmenot

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

Member Avatar for Lerner
0
787
Member Avatar for ssharp77

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 …

Member Avatar for ssharp77
0
557
Member Avatar for wannabeIT

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

Member Avatar for Lerner
0
123
Member Avatar for Allen 0108

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 …

Member Avatar for Allen 0108
0
247
Member Avatar for Uso
Member Avatar for Uso
0
79
Member Avatar for bhoot_jb

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 …

Member Avatar for Majestics
0
3K

The End.