![]() |
|
#1
|
|||
|
|||
File linking and Structure Manipulation lab... lostWell, here's my newest one... I'm not at all familiar with structure manipulation though from what I understand it's very similar to using classes. Just lacks the member methods.
1. Download the solution to the previous lab and make sure it compiles and runs properly. 2. Divide the file so that the object class and all related methods (including the #includes ABOVE the class) are in one file called "rat5Nest.h" ("h" for header) and everything else is in a second file called "rat5Nestdr.cpp" ("dr" for driver). Place a statement similar to the following after the other #include statements in driver program: #include "rat5Nest.h" Close the file with the .h suffix, then compile and run the driver program. If it fails to compile, examine the path. 3. Divide "rat5Nest.h" again by placing the implementation in a file called "rat5Nest.cpp". Leave the interface in "rat5Nest.h". Place the following in interface as the first executable line of code: #ifndef RAT5NEST_H #define RAT5NEST_H At the bottom of the interface, place the following: #include "rat5Nest.cpp" #endif 4. Place the correct path to rat5Nest.cpp in the include line above. Now close everything except the driver program. Compile and execute it. If it does not execute, recheck each of the steps above. 5. a. Develop a menu-driven test driver program that uses the object. Ignore error trapping. b. Develop implementations for the constructor, allOK, adding, and finding stock. Here's my rat5nest.h CPP / C++ / C Code:
And rat5nestdr.cpp CPP / C++ / C Code:
My rat5nest.cpp CPP / C++ / C Code:
And the new program, 5rationalNesting.cpp CPP / C++ / C Code:
Now... I'm unsure I correctly followed the instructions. I'm not sure if the last addition, the one's with the #if, are in the right file. I assume it's just a way of linking the files together, but it was never explained to us what all of these things did. We were just told to do them. So I don't have a great handle on it. For that reason, I think, some pieces of my structure in the new program don't work. They're commented out. We had no lab for this assignment so, much like the first assignment I posted here, there's little guidance. Professor was sick. From what I've gathered I'm just allowing the user to make a stock database, and find a stock. But, I don't really know how to make a database like that with a structure. Any help would be appreciated, I'll probably be messing with this late into the night. Digging through the textbook that hasn't been much help at all, etc. |
|
#2
|
||||
|
||||
Re: File linking and Structure Manipulation lab... lostQuote:
I believe what you're asking is as simple as that. __________________
Age is unimportant -- except in cheese |
|
#3
|
|||
|
|||
Re: File linking and Structure Manipulation lab... lostIt's been cleared up some. My file linking is fine now, for some reason I had an extra file in the above post I made. I now only have to work on one piece of this program. Group project, and we don't have to do all of the methods, etc. So here's my dilemma.
CPP / C++ / C Code:
I'm in charge of the addStock method, and rank method. One question is simple... what's the proper code to call information out of a structure? Mainly, how do I specifically get the name from a stock that is passed to the rank method? I'll need it to give it a number ranking. The second is I need to come up with a good way to put the stocks in alphabetical order. I've got an idea of how to do it obviously. The easiest I've figured out is to start at the end of the array, and compare. If the stock in question belongs farther into the array, move the stock in count's location of the array over and decrement count. Pop the new stock in where it needs to be. I just lack a good comparison. Should I convert the 3-4 letter name code into a number rank like I'm hoping to when I figure out how to get the name out or is there an easier way? |
|
#4
|
||||
|
||||
Re: File linking and Structure Manipulation lab... lostQuote:
Quote:
Note to others: Yes there are better sorts, but they are difficult to understand and impossible for a newbie to program. Leave the others for advanced programming techniques... __________________
Age is unimportant -- except in cheese |
|
#5
|
|||
|
|||
Re: File linking and Structure Manipulation lab... lostWell, I've got everything but ranking the 4 letter stock names. My sorting through the array of stocks and putting them in alphabetically seems fine (I think)....
The only code I came up with for ranking that seemed like it should do it was full of problems, and was ridiculously long. If I put ifs in letter by letter it takes unbelievable amounts of code. It just seems like there should be a more efficient.... shorter section of code that does the same thing as 26 if statements. At any rate: CPP / C++ / C Code:
This won't work. I can't test to see if a location in the name is a certain letter. How do I go about that? |
|
#6
|
|||
|
|||
Re: File linking and Structure Manipulation lab... lostNevermind that hideous thing. I think I'm on to something with this. I've got 2 errors that come out of this, centered around the fact that I'm testing for a >0 out of the strcomp (That is what it returns, yes? How do I make it work?)
CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
Re: File linking and Structure Manipulation lab... lostWell, I think this actually works. However, I'm having the hardest time testing the thing.
CPP / C++ / C Code:
Any main driver program I write has to put data into the name for me to test this method.... and well, I can't figure out how. I haven't found a solution on the net to that one, so... does this look like it will work? Or how can I enter data to name portion of the stock? CPP / C++ / C Code:
Nothing like that seems to work. I'm still very weird on using these struct/class prefixes and manipulating data structures and strings, so it's probably a dumb mistake on my part. |
|
#8
|
||||
|
||||
Re: File linking and Structure Manipulation lab... lostQuote:
A couple problems I see: Your definition of stock.name seems to be wrong. For the definition CPP / C++ / C Code:
2) You don't need * and [], so the definition should be simply CPP / C++ / C Code:
Therefore, your strcmp() should be CPP / C++ / C Code:
A couple formatting suggestions: more SPACES between terms use 4 SPACES instead of TABS line up the comments vertically Check out this tutorial for detailed information, and pass it to the rest of your team... __________________
Age is unimportant -- except in cheese |
|
#9
|
|||
|
|||
Re: File linking and Structure Manipulation lab... lostWell, I think I've finally gotten somewhere. I fixed the obvious error you pointed out, and I managed to incorporate the rest of the pieces from my team and get it running. The only problems now are in the main, which is just menus and input/output. So I'm good to go. I appreciate it.
By the way, I think the help I've gotten on this forum is a great deal of the reason I managed an A on the last test (one of 2 grades above a B). So I really appreciate that. |
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The