Monday, May 24, 2010

Linked Stack C++?

I have a program that uses a linked Stack to store the data. I need to know how I would go about displaying the data inside the stack. I'm having programmers block....

Linked Stack C++?
Something like this:





void DumpStack( Node * pNode ) {


....while (pNode != NULL) {


........cout %26lt;%26lt; pNode-%26gt;data %26lt;%26lt; endl;


........pNode = pNode-%26gt;next;


....}


}
Reply:You could cout the top item, copy it into a second stack, and then pop it. This way, when you've reached the last item in the original stack, the second stack will be an upside down copy of the original. You could either get rid of the first one or, if you need to maintain the order, put everything back into the first stack as you pull it off the second one.





Sorry, I hope you weren't looking for code.

salary survey

C++ question?

Input stream buffer contains


22 34.5\nHello A\nWorld 34 45 //\n represents new line chara


What is the output to the terminal when the code segment is executed





Code


int m; float x; string text; char ch;


cin %26gt;%26gt; m %26gt;%26gt; x;


getline(cin,text);


cin.get(ch);


cout %26lt;%26lt; m %26lt;%26lt; "-" %26lt;%26lt; x %26lt;%26lt;"-" %26lt;%26lt; text %26lt;%26lt; "-" %26lt;%26lt; ch %26lt;%26lt; endl;





Can one of you programmers help with this

C++ question?
You could just compile %26amp; run this and get the answer.





1) I typed up this program.


#include %26lt;iostream%26gt;


#include %26lt;string%26gt;





using namespace std;





int main()


{


int m; float x; string text; char ch;





cout %26lt;%26lt; "Enter stuff:\n";


cin %26gt;%26gt; m %26gt;%26gt; x;





getline(cin,text);





cin.get(ch);





cout %26lt;%26lt; m %26lt;%26lt; "-" %26lt;%26lt; x %26lt;%26lt;"-" %26lt;%26lt; text %26lt;%26lt; "-" %26lt;%26lt; ch %26lt;%26lt; endl;





return 0;


}





2) I compiled it with g++.





3) I ran the executable and I had the answer within seconds.
Reply:Trace it or run it.


Tracing it is easy. match the variables in with the stream of characters. EX:


m will get 22


x will get 34.5 Notice x is also a float (real number)


So trace and tell the result.


Why didn't you try running it/????


C# drawing question (asked in an easier to understand way). A best answer will be awarded.?

I have a class that draws itself.





The class draws a picture of what a node looks like in a B tree. But this takes a lot of method calls.





1. draw top line


2. draw bottom line


3. draw left arc


4. draw right arc


5. draw diving lines inside node


6. draw left rectangle


7. draw left circle


8. draw right rectangle


9. draw right circle


10. draw rectangle between left and right (in a for statement, so if there are 50 data cells this code runs 48 times)


11. draw in numbers on each data cell





etc etc etc





I dont want the computer to have to execute all of that code every time it has to repaint the window (due to it being minimized or another window dragged over top of it, etc).





So I just want to know how programmers usually deal with something like this. Is it okay to have it go through all of that drawing every single time it needs to repaint? Mind you, this will be the drawing of only one node.... there could be hundreds that need to be drawn!





thanks for your help!

C# drawing question (asked in an easier to understand way). A best answer will be awarded.?
You can make a path and save it. I assume that since you are drawinf nodes, that each looks the same. I program in VB.Net, but the code is virtually the same for C#...





Dim path As New GraphicsPath


Dim rectRoundBounds As New Rectangle





path.StartFigure()


path.AddLine(rect.X + Radius, rect.Y, rect.X + rect.Width - 2 * Radius, rect.Y)


path.AddArc(rect.X + rect.Width - 2 * Radius, rect.Y, 2 * Radius, 2 * Radius, 270, 90)


path.AddLine(rect.X + rect.Width, rect.Y + Radius, rect.X + rect.Width, rect.Y + rect.Height - 2 * Radius)


path.AddArc(rect.X + rect.Width - 2 * Radius, rect.Y + rect.Height - 2 * Radius, 2 * Radius, 2 * Radius, 0, 90)


path.AddLine(rect.X + rect.Width - 2 * Radius, rect.Y + rect.Height, rect.X + Radius, rect.Y + rect.Height)


path.AddArc(rect.X, rect.Y + rect.Height - 2 * Radius, 2 * Radius, 2 * Radius, 90, 90)


path.AddLine(rect.X, rect.Y + rect.Height - 2 * Radius, rect.X, rect.Y + Radius)


path.AddArc(rect.X, rect.Y, 2 * Radius, 2 * Radius, 180, 90)


path.CloseFigure()








Then call





g.FillRegion(brushBackground, New Region(path))





or


g.DrawPath(BorderPen, path)
Reply:Hm, I already answered this question elsewhere ;-)


My advice is to use double buffering, or just ignore it. It might not even be a problem unless youve tonnes of them





Remember modern graphics cards can thousands and thousands of polygons per second without even sweating
Reply:a simple and fast solution would be to following: I am assuming that you are writing to a picture box.





Im not going to provide the code since you seem to know what you're doing.





after you draw the image that you want save it as a .bmp to memory. when the screen needs to be refreshed simply draw the .bmp image to the device context (aka the picture box).





good luck

survey

Which one of the following individuals would be most likely to vote?

A. A 19-year-old high school graduate who likes to complain about the government


B. A 22-year-old computer programmer





C. A 30-year-old college graduate who has just moved to a new state





D. A 50-year-old corporate executive who holds a master's degree in business








Anyone able to find documentation on this, or have definite knowledge to this answer, I'd really appreciate it. I'm honestly stuck between answer D, it sounds logical, but I'm worried I'm going more so by age. Thanks anyone =)

Which one of the following individuals would be most likely to vote?
As far as I know, age IS the determining factor for voting. As a general rule, the older you are, the more likely you are to vote. That's why you have to be 21 to drink instead of 18, like in the 70s. There weren't any kids voting to vote against it.


Which one of the following individuals would be most likely to vote?

A. a 19-year-old high school graduate who likes to complain about the government?


B. a 22-year-old computer programmer?


C. a 30-year-old college graduate who has just moved to a new state?


OR...


D. a 50-year-old corporate executive who holds a master's degree in business?








THESE ARE QUESTIONS THAT COME OUT OF MY HIGH SCHOOL QUESTION'S BOOK! I HAVE EXAM TEST AFTER EACH CHAPTER! %26amp; I STILL HAVE NO CLUE? help me please. I really do need answers that are correctly answered and not people who are going to mess around and be mean or try and say something stupid. Like they have before. THX

Which one of the following individuals would be most likely to vote?
I would say the corporate executive.... he makes tons of money and needs to vote people in who will give him tax breaks.... and tax the sh/t out of the poor.
Reply:The 50 year old. He has seen enough elections to be pissed off about the way somthing is going in the government and his company probably contributes to the Republican party.
Reply:Well it depends if the 19 yrd is a conservative they WILL vote if the twenty-two year old is a conservative they WILL vote. The thirty year old is a conservative they will Vote. The fifty year old will probably vote irregardless unless they are cynical about government.





Now a liberal 19, 22,30 will probably not vote.
Reply:Older and richer are always more likely to vote. Older and richer.
Reply:D. a 50-year-old corporate executive who holds a master's degree in business.





They have the most to lose financially, and we all know about how the rich want to hold on to their money. It's how they define themselves.
Reply:I think it's D, since the reason for it would be that for A. the kid is probably just like to make themselves feel important by voicing his/her opinion, but when it comes to action, probably the student would not actually take the effort to vote.





B. In a choice like this, when the subject (programmer) has really nothing to do with politics, there's really no motivation for the programmer to vote.





C. College graduate is not the same kind of easily excited high school student, and is usually more moderate in their actions. So, while a college graduate can still be interested in voting (in fact every choice can be somebody who is interested to vote), a thirty year-old who has just moved to a new environment would tend to see things more objectively and act after more consideration and more experience living in that new state.





D. The real incentive for this guy to vote is that a corporate executive is really concerned with money!!! And a right or left wing party can really make a huge difference to the economy. So, the executive would care to vote for somebody who would support the kind of business that he/she is doing.





And of course, I don't know what subject of study does this question belong to. I would be interested to know.
Reply:A,D, and D
Reply:I would say teh High School Graduate. They are complaining about teh government, so they would be motivated to influence change. The computer Programer would be secure enough finanicaly to probably not worry to much about it, the executive is set up- his life is so hetic right now, that following the election would be to much bother (if he did vote he would vote along party lines the same way he has done for 30 years), and teh 30 year old that just moved to a new state probably hasn't register to vote in his new home yet. This is assuming a national government. When it comes to city/ state elections, I'd put my money on teh executive who probably has kids in teh eduational system and might gain a few tax breaks with new laws, etc.
Reply:This happens to be my area of expertise....


The first correlate of voting is age....young people DO NOT VOTE....scratch those under 24.


Secondly, income/education is the second correlate....as income and education rises so does the incedence of voting.


Thirdly, race.....minorities are least likely to vote.





The 'just moved' is a trick....it DEPENDS ON THE STATE....


some states (six to be exact) allow you to register and vote THE DAY of a an election You can read more here: http://www.epic.org/privacy/voting/regis...
Reply:after som pondering, and trying to think like a high school text book lol ok. 19yr-30yr are the hardest ages to get to the polling stations, because they dont believe their vote will make a difference, their lives are usually self absorbed and generally they are removed from the political happenings of the country. Therefore, the 50yr Corporate Exec would be most likely to vote, because he knows what a vote can do for his company. Good Luck!
Reply:I considered myself a diehard voter after seeing 9/11, and couldn't wait to cast my vote come election time; but because I was so caught up in work and school, I kinda got sidetracked and had to do some last minute registration. It took hours for me and my wife to even find the place to cast our votes! (Which turned out to be inside a church...wtf) anyway, I ended up voteing for Al in the end, but my point is sometimes no matter how badly you want to vote, if you are caught up with personal stuff, (which most of us are) you can easly forget to vote, let alone know how in some areas. So, yes, my answer is D. Everyone else is too buisy with jobs/social life to follow through. But the old fart doen't have anything else better to do.


Why is goto in programming frowned upon?

Being a hobby programmer (c++ and any other language I feel like learning) I have read from numerous source that using the


goto keyword is a bad thing and should be avoided.





From what I've read it is avoided because it basically makes your code hard to read/understand, but I think that if used properly it can be usefull.





I also dabble in assembly, and was getting confused with the jmp until I learned about the goto and then it hit me....





jmp is almost exact to goto.





So wouldn't goto help people who want to learn oh say assembly??





I have also found goto helpfull in rare cases.





what about you??

Why is goto in programming frowned upon?
A program statement is like a sentence. It can be direct. It can also be long and rambling, taking you from the court of Saladin the Magnificent to H. P. Lovecraft's dinner table where you will learn he detested fish.





I have no doubt you have found gotos useful. C has a statement called break, which gets you out of whatever loop or switch statement you hapen to be in. There are certainly cases where they are called for. Generally, though, they are so useful in redirecting program actions that they can give you a scope as broad as my sentence with Saladin and Lovecraft. And it makes it very easy to forget that happens after the sentence is complete. The program can hang or terminate without accomplishing its original purpose.





If you expect to be the person maintaining this code until it's finished or the Messiah comes, fine. If not then you are well advised to think of others and plot things from the top down so you do leave the most direct and uncluttered sentences for them to look at you can.





%26lt;/tongue in cheek %26gt;
Reply:Using goto does make you code harder to follow and opens up the possibility that another person that modifies the code will make a mistake. If it wasn't for the use of gosub it might be alright. If one uses a goto after a gosub and before the return then you can imagine how confusing it could become.





If there are several gosubs within gosubs then it gets even worse.


Time is money and all the employers I have worked for do not like spending money on spaghetti code problems.





Top down and modular, that's the ticket


The project role most involved in interacting with users to determine their specific needs is the:?

a)system analyst


b)programmer


C)project manager


D)inteface designer

The project role most involved in interacting with users to determine their specific needs is the:?
Is this a test question or are these your choices? I would say that the Business Analyst or Application Architect are most involved with client requirements. I am a sales rep for a consulting company and that's my opinion for what it's worth. If this is a test and these are my options - C or D would be most involved.

land survey