Change line 4 to:
string str = "ABCD";
P1.Inverte(str);
Change line 4 to:
string str = "ABCD";
P1.Inverte(str);
Here's an example of using ADO.NET (it's using VB.NET (viz AD's post) on an ASP.NET page but just ignore the ASP.NET part). You could use it with C++/CLI but that will require picking up some new syntax. If you have the fancier versions of VS (Professional or Team System or their equivalents in 2010) you can use VSTO to hook directly into Excel, but I don't know much more about it than that.
Hopefully that gives you some ideas.
Learn more. :) In a more concrete sense what I believe firstPerson was indicating (but I don't want to speak for him) was that you should look into using an array for the months so, int months[12];
instead of all your separate variables and January would be months[0]
. Look up enums in the long run to do what David was suggesting, but getting the arrays in there will go a long way towards consolidating that code. See if you can come up with a single "getter" function to get any month you specify rather than one for each month. As David mentioned look into vectors instead of the array for more flexibility etc.
The second point that FP was emphasizing is the "is-a" /"has-a" ideas of inheritance. Normally to have the kind of relationship you have designated (with Monthly inheriting from Customer) is an "is-a" relationship. If you had a class vehicle and derived motorcycle from it you could say a motorcycle is a vehicle. A better approach for you would be to have Monthy "has a"n array of customers (or even better a vector of them), which involves something like:
class Monthy
{
public:
//methods here
private:
Customer customerbase[25];
//or std::vector<Customer> customerbase; //#include<vector> for this
}
which illustrates composition.
Hopefully that gives you something to google on. Post back as stuff comes up.
umm...couple of ways, first is the easiest.
//option # 2 string path = "AMBER/data/runx/amhsk_run*.root"; string runNumber; cin >> runNumber; path.replace( path.find('*'),1,runNumber) ;
I think OP wants to replace both x'es. It doesn't change your code much but you'd need another find statement (and you'd have to adjust your replace call if runNumber was multiple digits, unless I misinterpreted it).
Where is getData()
defined (or declared for that matter). There may be a mismatch somewhere.
Why do we have these unresolved externals?
Would you rather your program run without the appropriate functions? ;)
You don't need the .eof() loop, the getline will return null when it runs out of lines. In fact the .eof() can end up reading the last value twice (see http://www.daniweb.com/forums/post155265-18.html).
Here's the correct code for the 2nd program
int num; cout<<"Please enter a number: "; cin>>num; for(int i=1;i<num;i=i+2) { cout <<" "<< num; } cout <<"end"; return 0; }
Please don't give away the answer if the OP is working towards it. Your code is also incorrect. Test it out.
And to tackle the problem of getting the string size, you could get the string class to return the character array of the string, and then use strlen to find the length of the string
Or use the .length()
member of your string.
Unmanaged arrays can't hold managed objects (and vice versa) due to garbage collection issues. If you are going to exchange data between the two it has to be marshaled.
Your best bet is to have a class member that's a cli::array and initialize it in the constructor of your ref class. You can pass the number of objects in the array,obtained from wherever, into the constructor.
i have already opened the file with ios::app.So the get and set pointer is already at the end of the file.
Didn't put 2 and 2 together, apologies
*I want to open that file in append mode and then i want to print the last line of that file.
I understand the immediate task at hand. I'm trying to get a handle on the big picture. I meant that I don't understand the constraints that are preventing you from opening the file without the append and seek back from the end (since maybe there is another way).
The best person to ask for the definition of "system hanging" would be the one that gave you the assignment. There's some ambiguity to the term.
I think the whole idea seems suspect but maybe it's me.
I'm not entirely clear on what you need done. If you want the last line you should probably use ios::end
instead of ios::cur
For that question, I'd start here : http://www.daniweb.com/forums/forum4.html
However, I'd ask why you would want to use such an old language?
Next time this happens just hit the Flag Bad Post button to get it moved rather than having the OP repost the same question (not to speak for mods but I think that's the preferred procedure)
f1.eof()
is a method and needs the parentheses. I know with text files that using .eof() can read the last line of the file twice, but I'm not sure how it behaves with binary.
You're missing a parens on 196 also.
Look at line 221 again, check() would have to be a static method for that to work.
It doesn't seem as if you've included <iostream>
for cin and cout. Even after including that you will also need to qualify the names. You can do this one of three ways.
First, qualify as std::cin
and std::cout
at each use of cin/cout, or alternatively use the statement using namespace std;
at the top of your code, or lastly (as a compromise) you could put using std::cout;
and using std::cin;
at the top just to qualify those two names only.
Also, these are a bad idea:
gets() //will not limit the number of characters you can enter, you can go way over the end of your char arrays into other memory
fflush(stdin); //undefined behavior, meant to be used with stdout
goto //reform your code into loops if you want this behavior
A couple of more things
3) It would be nice to be able to specify the number of posts per page. Sometimes it would be convenient to display 30 posts on one page so I can scroll up and down to follow long conversations
Dave
Control Panel/Edit Options/Thread Display Options/Number of posts to show per page. Dani just heard your request and coded it right up for ya. ;)
Is it just this "Receive Occassional Email from DaniWeb"? If so, then that is exactly my point! It doesn't say anything about DaniWeb Digest!
Dave
Yes. Well now you know, pass it on! :D
Myself, it seems much more feasible that he would want you to check if it were empty. Then you return -1 and the output of the numbers stops in printQueue. Based on the instructors own driver code returning a -1 stops the output process dead in its tracks, so why should the program not output a full queue? I could be missing something but that seems fishy to me.
I modified the dequeue method to this (in psuedocode so I don't take away your fun)
IF QUEUE IS NOT EMPTY
{
ELEMENT = QUEUE[0]
SHIFT ELEMENTS DOWN
DECREMENT LENGTH
}
RETURN ELEMENT;
You'll need to do the initialization of element and other housekeeping too
My output:
Queue properties:
isEmpty = 1
length = 0
size = 10
first element = -1
Queue properties:
isEmpty = 0
length = 5
size = 10
first element = 10
Queue elements:
10
13
32
3
16
Queue properties:
isEmpty = 1
length = 0
size = 10
first element = -1
Queue elements:
The queue is empty!
Queue properties:
isEmpty = 0
length = 10
size = 10
first element = 0
Queue elements:
0
10
20
30
40
50
60
70
80
90
The extraneous -1 from the listing ending in 16 has also disappeared.
Read over this portion again. Your if statement in the block is not doing any of these steps.
// TODO:
// This method removes and returns the first element
// in the queue. You should first check that the
// queue is empty. Adjust the length of the queue
// after dequeuing the element.
//
How do you check if the queue is empty? Use the isEmpty() method. Only if your queue is empty return -1 so that your printQueue function doesn't print anything.
I was asking you to trace through the printQueue so you could see that your dequeue method is in error. There's no need to change the driver. The if condition within the dequeue method will always be true for length the same as size so any queue of length 10 will return a -1 regardless of how many members are in it.
Add in a set of braces between line 71 and 72 and between 73 and 74. This isn't tha main problem but your enqueue was happening regardless of the length.
Trace through your portion that prints out the queue in the driver. After the queue is cleared and the 10 elements are added, you have size = 10 and length = 10. Therefore, length+1 >= size
and so dequeue returns -1. In your printQueue function this is taken as a signal to break.
Try making the changes around that and post back if something else arises.
You are only taking bits and pieces of what I have been telling you. In this latest version you have not closed main() with a } and kept your function definition, i.e. the
bool myFunction(string arr[],double darr[]) //no semicolon -- these parameters are just an example, use your real ones
{
}
outside of main. If you have a text, look up the use of the braces with loops -- it is critical that they match up, one for one, one { per each }. Also, look at some programs that have functions and note where the prototype and definition are located.
You'll need to fix your arrays as using MAXSIZE is correct in the definition of those arrays in lines 9 and 13 but when you try to access element MAXSIZE, you've overstepped the bounds of the array (since an array of size 4 will have index values of 0 through 3)on lines 33,37,38.
I know you think you've come too far to do this but it will save you an immense amount of time if you start a new project with no code other than the skeleton and fill in the pieces one by one, compiling as you go.
Refer back to the skeleton code I gave you to place the function definition. Line 32 in the above listing is completely wrong.
Also, your if statement doesn't have a closing brace and if you write else without the braces the statement will encompass the else and the line immediately following it.
if (condition)
I get executed
Not part of the statement
//versus having
if(condition)
{
I get executed
Part of the statement
}
else(condition)
Part of the else
Executed regardless
I tried to explain this before, but do you want to get the title each time the code goes through the for loop? No, so move line 31 out of there and before the for.
Here's some pseudocode for your loop
READ INPUT FROM USER
FOR (over the books array)
{
IF WE FOUND THE BOOK, SAY SO and RETURN TRUE
}
IF WE MADE IT THROUGH THE FOR LOOP, WE HAVEN'T FOUND IT
RETURN FALSE
See http://www.windows-tech.info/18/504d408117484041.php for a great reference.
Normally in C# I would add in another .resx file but there doesn't seem to be a way to do that in 2008 or 2010 Express Editions. You can add them to the existing Form1.resx (the IDE will balk at you): open that file up in one of the tabs (it may be hidden under Form1.h in the solution explorer) and go to the add resource. Note the name that VS gives your image for later.
Follow the steps in the link above, except instead of Project1.Form1 substitute <YourNameSpace>.Form1. Skip over the GetStream step and instead do pictureBox1->BackgroundImage = dynamic_cast<Image^>(myres->GetObject("thenameVSgaveyourresource"));
Give that a try...
Create a private int within your Form1 class (or could be public, if you needed that) and increment it in your button_Click method.
How does what you wrote relate to your original problem?
When declaring an array, the length must be a constant known at compile time. What you are using here is a language extension for C compilers that allows a "variable-length" array to be defined statically. The downside is that your solution will be non-portable and non-standard as not all compilers support this extension. See http://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html for example.
Grid_pos[2][2] is a single char but you told Print_Grid to expect an array with second dimension 2. If you want to print the whole grid make the function definition void Print_Grid(int i, int b, char Grid_pos[][3])
and pass in Print_Grid(i,b,Grid_pos);
so that you get a pointer to the array. Really i and b are not being used in the function body anyway so you don't need them.
but then there is no code
That's very metaphysical. It must have some code somewhere. It's not critical to see, it was just curious that you're having us critique an exe.
Your distance is not being shown on the screen because you don't include it in the cout statment.
An extra newline character in your text file is the culprit. Put the cursor at the end of the last line and hit delete (not backspace). I had thought that it was !infile.eof() that was causing the repeat. However, using .eof() is still a bad idea (see this http://www.daniweb.com/forums/post155265-18.html -- RIP Dave). Use the first getline statement to "drive" the loop.
while(getline(infile,station1,',')
{
getline(infile,station2,',')
getline(infile,distance);
//etc.
}
Also, you haven't converted your distance into the float variable, it is still a string.
Oh, and again, minor, but "Originally posted by cscgal" > "Quote originally posted by cscgal".
I'd prefer it as "Quoth the [username]..." ;)
It's because you are using an unsigned int. When the unsigned value is decremented by 1 beyond zero it goes to the maximum value of the unsigned int (see http://en.wikipedia.org/wiki/Signed_number_representations). Using regular ints it works just find since after 0 is -1.
Geez... I'm...shocked. Yeah. :D
I knew you'd be back. I'll bet you've been browsing C without logging in.
I'm trying really hard to come up with something but he has such an extensive website (http://www2.research.att.com/~bs/ if anyone doesn't know it) where he has answered so many questions already.
I might ask him if he's going to come out with a new edition of his book covering C++0x in its entirety.
or
(for some hard hitting journalism)
What language or library does he use that he doesn't want people to know he uses?
Simply pass the array in as matrix
each time without any of the brackets. You've already designated that the function is taking an argument that's a matrix with 2 dimensions in the prototype and definition. When it comes to the definition of the function, the array being passed into a function degrades to a pointer. Passing in matrix[][N] gives a pointer to the array that holds each of the rows of the 2D matrix, not the entire thing.
And the money machine is already working. There's going to be a "new" version released soon, which will be identical except it's 6 minutes longer.
And no doubt the crowds will once again flock to the cinemas and DVD stores to buy that one too even though they already have the original.
Well no doubt they've also unearthed 16 hours of promotional BS that had sat on the cutting room floor until someone figured out "Sigourney Weaver's What I Ate for Lunch Diary" might be of interest to a die-hard fan. You should come to expect this by now...
Next time please use the code tags
[code]
code goes here
[/code]
Why do you declare choice after you try to write to it? You need to move int choice = 0;
before std::cin >>choice;
Select the whole Form1 window in the designer (not the webbrowser bit) so on the properties window at the top it should say Form1 (or whatever you called it)
Use a stringstream object:
#include <sstream>
//...
stringstream ss;
double value = 10.4567;
ss<<value;
string valuestr = ss.str();
There are certainly other methods that will work but this one is more straightforward IMHO.
,use "b"and"d"variables for base and decimal respectively.
Wow, well... if you've gotten that far with it then by all means. I was kind of thinking of going with b for decimal. I'll have to go redesign...
You're not too far off.
With c-strings (strings terminated in '\0' as opposed to std::string which I'll get to in a minute) the variable is essentially a pointer, so saying
char * str1 = "Hello"; //a '\0' is automatically appended at the end of each of these
char * str2 = "Hello";
asking str1 == str2
will come up false every time because the pointers are not equal, they are stored in two different spots in memory. This same idea holds true for character arrays. Hence there's a need for a function like strcmp which does all the finagling for you.
On the other hand, std::strings, when you have
#include <string>
std::string mystr = "Hello";
std::string mystr2 = "Hello";
mystr == mystr2
will be true because the std::strings have an overloaded == operator (essentially a custom recipe specific to the class as to which components of the strings should be compared against each other).
Switch statements in C++ (and C) can only take ints (as well as chars which are basically 1 byte integers, and enumeration types which are implicitly converted to integers). It's been a while since I used VBA but it might be closer to .NET, where like in C# you can use strings in a switch statement.
I've probably glossed over some important points but others will be able to clarify if necessary. I may have known the internals of some of the string functions at one point but I …
If you hit the set button and then you hit the calculate button it's going to set bags of feed to 5 (see your button2_click handler). In order for the program to change farmer.NumberOfCows on line 28 of the first file you must move the numeric up/down to a new value and not hit the set button. Otherwise you would undo what you just did.
In terms of the second issue, your Form1 is a class. Just like any other class it can have private variables. On line 14 you are declaring a Farmer variable that is a private member. You could, as far as I can tell, have combined lines 14 and 18 and left it where line 14 is (as Farmer farmer = new Farmer() {NumberOfCows = 15};
). However, if you eliminated line 14 and tried to move the whole construct ( Farmer farmer = new Farmer() {NumberOfCows = 15};
)to line 18 farmer would be local to the Form1() constructor and invisible to the other methods which need to access it. The way you have it now allows the greatest flexibility and makes sure the farmer object is initialized only when Form1 is created.
Dude, you've got to listen to what people are trying to tell you and not just repeat your question. If there's something you don't understand, say so.
Look at the structure of your for loop. Compare it to other for loops you've seen. How many have had a ; directly after the for statement?
Everywhere you were accessing ".number" use your getter (like in lines 154 and 164). I don't know that you need the friend class bit up in the card class if you use the getter. Debugging the game itself is going to take time and making sure things are getting where they need to go. Start putting some cout statements around critical parts so you can see what the values are (like the cards you drew and the value of each, etc).
Don't give shuffle any arguments it knows the deck it's shuffling already
Make a quick "getter" for card that returns the card value
No biggie, it happens to everybody.
Try something like this:
string concat="";
foreach (Control ct in Controls)
if (ct is TextBox)
concat = (ct as TextBox).Text + "\r\n"+concat;
//this puts a CRLF in between each YMMV
(It seems that the foreach is iterating through the controls backwards -- I double checked that they were added in the .designer file in the right order so there must be some reason for it -- so I just adjusted the concatenation order)
Have you named your executable the same name as some other system software? It doesn't seem like your code has any error message like that. Try renaming your program.
Do you have the AcceptsTab property of the textbox set to true?
I was able to get it using
private: System::Void textBox1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if(e->KeyCode == Keys::Tab)
MessageBox::Show("Tabbed!");
}
I think this program is really easy, I tell you why:
When the user inputs the data forexample hours , minutes and seconds. It is possible to convert that into angles. On calculators there is special button to do that as well. You can check this link below and that should be it :]
http://id.mind.net/~zona/mmts/trigonometryRealms/degMinSec/degMinSec.htm
FWIW, that's not correct. You can have a bearing for a ship in degrees/minutes/seconds and it has nothing to do with time or the clock. Minutes are a division of degrees and seconds are divisions of a minute. See this which also calls them arcminutes and arcseconds.
(Pardon the off topic post and I know this thread is getting a little stale. Sometimes you can get good baked goods on the day old shelf in the grocery store though)