Tuesday, July 28, 2009

Pascal Programming- Arrays?

Hi! I'm taking a computer science class in which we use Pascal to write all of our programs. IRight now we're working with arrays, and I'm completely lost.





The program we're supposed to write is:


Write a program that computes grades for a class of up to 50 students. The program reads in a score in the range 0 . . 100 for each student and then outputs the grades, identifying each student by number (first is 1, second is 2, etc) Any student who receivces 10 points below the average receives an F. Any student who receives above that and at most 10 points above the average receives a C. Any student who receives a score above that receives an A. There are no D's or B's. To use your program for a larger class, you should not need to change anything except the constant declaration section.





I know I need


const maxstudents = 50





And I'm guessing I would need to use parallel arrays?





I really just need help getting it started. Thanks!

Pascal Programming- Arrays?
you can add this in your const :


valueBelowAvg = 10;


valueAboveAvg = 10;


so when their ask you to change the rules to get a grade, you just change their constant value.





you can use this for array :


var arrType : array [1..maxStudents] of integer;





and for grading, make a function with if.. then.. else.. and compare it with your constant value.
Reply:hi sam, actually despite of the programming language, i think you should concentrate on the program logic. You can start with defining a class of students. I cant answer much but im a computer science student also in Malaysia. You can contact my handphone number. 016-2417247. Take care
Reply:Right. You use array to store the scores.





type


arraytype = array [1..50] of integer;








Another tip is use "case" command to shorten your program when assigning A, C or F


Find an equation?

A point M is moving in a 2D plan. Its coordinates are functions of time x(t) and y(t). The initial position of M at t=0 is known (x0, y0).





Constraint 1:


==========


M(x, y) moves along the curve y = ax^2 + bx + c





Constraint 2:


==========


The speed vector orientation of M will change but its length remains constant:


(dx/dt)^2 + (dy/dt)^2 = const





Question:


=======


How can we express x(t) and y(t)?

Find an equation?
Very difficult question. Will give it a shot. Answer not guaranteed right but probability very high.





D^2 = dx^2 + dy^2 = dx^2 * (1 + [2ax + b]^2)





(dy = dx * derivative of the function).





For x(t) we find differential equation





dx = 1/sqrt(1 + [2ax + b]^2) dt





since p = -b/2a, therefire


dx = 1/sqrt(1 + (2a)^2 (x-p)^2) dt





int value is





t = (x-p)/2 * sqrt(...) + 1/4a * ln {2ax + b + sqrt(...)} + C





where (...) = (1 + [2ax + b]^2)
Reply:In other words, you want to travel along a parabola at constant speed.





The squared distance between points M(x, y) and a neighboring point M(dx, dy) is equal to





D^2 = dx^2 + dy^2 = dx^2 * (1 + [2ax + b]^2)





(dy = dx * derivative of the function).





For x(t) we find differential equation





dx = 1/sqrt(1 + [2ax + b]^2) dt





Using p = -b/2a, we can reduce this to





dx = 1/sqrt(1 + (2a)^2 (x-p)^2) dt





and the integral would be





t = (x-p)/2 * sqrt(...) + 1/4a * ln {2ax + b + sqrt(...)} + C





where (...) = (1 + [2ax + b]^2)





It is not easy to solve this for x !
Reply:First start off with x=t and therefore y=at^2+bt+c.





What you want to do is normalize the velocity vector:





So, find (dx/dt)^2+(dy/dt)^2= 1+(2at+b)^2 = 4at^2+4abt+b^2+1.


Do u think the govern should ban assault rifles?

I was reading the sunday paper when i came across an article about Newark's rise in gun violence, i am scared out of my life right now, b/c i was suppose to go to Rutger's law school a yr later, which is located in Newark! I strongly believe we should ban guns all together except for of course, the police, the soldiers, and others who help out with the public's safety, but other than that i dont think the citizens should have a right to have guns, plus in our Const., it doesnt say citizens have the right but the militia has the right to use guns!!

Do u think the govern should ban assault rifles?
This will be a debated subject for as long as the United States is a functioning republic. There is no question that the initial reaction to any type of violence is repulsion and to some degree fear. You and I (and thankfully most Americans) wake up every day, trying to do what is best for ourselves and our communities. It never crosses our minds to harm another.





But there is another element in our society that is not wired this way. The are predators who seek out harm innocent people. Most of us will never be a victim of a violent assault or an attempt on our lives or on the lives of a loved one; but, heaven forbid, if that situation were to arises, how would you respond? If you give up control to the predator and let them injure or kill you or your loved one, then that is a conscious choice. If however, you value your life and the the lives of your loved ones, you will realize that the police cannot protect us one on one.





Many studies have shown that weapons in the hand of law abiding citizens are used thousands of times of year to PREVENT a violent act from occurring. A recently published report by the Federal Government stated that the numerous restrictive gun laws (including the Assault Weapons Ban) had had no effect in reducing violent crime. In fact, just the opposite was true. In each of the States that have passed Concealed Weapons Laws, violent crime has been reduced.





If you take the time to study these statistics in thoughtful way, you may begin to understand that it is not the instrument (the gun) that is inherently harmful.





Careful study of the intent of the 2nd Amendment reveals that citizens of that day were extremely distrustful of a central government. No doubt, the citizens of any repressive regime would agree that only allowing the government, police or military to have the guns is a bad idea.





Anyway, this is just some food for thought. I know that you probably have already made up your mind on this issue. I rarely (if ever) had heard anyone say lately..."Gee, I never thought of it that way..."





Perhaps you will surprise me.
Reply:You can ban all the guns you want but people will always find a way to hurt one another. Better to approach the underlying causes of violence.
Reply:I don't think the public should be allowed to own assault (AUTO) rifles, while I do disagree with your thoughts on owning firearms. You have had some good answers before mine, how ever like one person said you have your mind made up and I doubt that we will change it.
Reply:The fundamental problem people fail to recognize is that 9 times out of 10, a criminal who commits a crime using a firearm did NOT purchase the weapon legally.





Banning guns will only prevent law-abiding citezens from a freedom provided by the constitution and the right to pursue lawful activities such as hunting, sport shooting, and home defense. The criminals will still obtain guns, but now the law abiding citezen will be unarmed and criminals will know this causing a rise in crime.





The problem is that most states don't enforce the death penalty as much as they should. If the punishment were severe enough, it would deter many individuals from commiting violent crimes involving weapons. Instead, the liberal judges sentence short terms and the criminal is left to do it again...either on the streets or in prison.





I own firearms and use them for lawful purposes such as trap shooting, target shooting, and hunting. I am no threat to other citezens. I went to a retail store and purchased my firearms using my I.D., passing background checks and registering those weapons legally. Banning weapons would have prevented me from this lawful activity. Why? Because you are scared of criminals? That has nothing to do with people like me. Criminals don't walk into a sporting goods store and purchase firearms with their own I.D.!!!! They obtain them be illegal means.





Bottom line......banning weapons would only punish law-abiding citezens like me. It is NOT a solution. Accoutabilty is the problem and the solution....hold individuals responsible for his/her actions instead of blaming an industry or punishing others.





Good Luck!
Reply:You are wrong about what the constitution says:





"A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed."





Gun control does not make us safer simply because bad guys get illegal things from the blackmarket no matter what. By illegalizing certain kinds of guns you merely disarm the innocent who are too honest to go to the black market. NOW who has all the guns? The bad guys! I don't personally own a gun but i see the sense in being prepared to defend yourself from intruders.





I have got some very informative links for you...
Reply:But then, how are we going to defend ourselves from other citizens with guns?

surveys

What event will be issued to the MDIChild when the MDIParent form gets deactivated?

The below sample C# code is to capture something when our UI form is issuing specific event (in this sample, I have captured close event of the specific form).





private const int WM_CLOSE = 0x0010;


protected override void WndProc(ref Message m)





{





if ( (m.Msg == WM_CLOSE) )





{





//do our own work





}





}








My Qyery:





What event will be issued to the MDIChild (Constant), when the MDIParent form (this is the main form in the whole application) gets deactivated?

What event will be issued to the MDIChild when the MDIParent form gets deactivated?
It's probably "DestroyWindow" which in turn calls other window messages depending on what you're trying to do...you should ask this on a C++ forum like devshed or codeguru to get a better answer. To really see the messages, though you need to use Spy++


Escape Velocity Physics?

(a) What is the escape speed on a spherical asteroid whose radius is 540 km and whose gravitational acceleration at the surface is 2.6 m/s2?





Ve = √(2 R g)


i found that to be 1680 m/s





(b) How far from the surface will a particle go if it leaves the asteroid's surface with a radial speed of 1000 m/s?





used const. acc. equation





Vf^2-Vo^2 = 2 * a * x





-(1000m/s)^2 = 2 * (-2.6m/s^2) * x


x= 192000 m


^^^getting a wrong answer





(c) With what speed will an object hit the asteroid if it is dropped from 1000 km above the surface?

Escape Velocity Physics?
(a) correct, although you obviously need a refresher on WHY this equation works.





(b)


You can't use constant acceleration, because the gravitational force isn't constant. We only use that near the earth's surface where the radius isn't changing much.





You have to use conservation of energy.





Potential energy = -GmM/r


Kinetic energy = 1/2mv^2





So the particle starts with potential and kinetic energy (which is zero if the particle has exactly enough speed to escape to infinity and negative if it doesn't have enough to escape--notice how if you set the total energy equal to zero, you get the equation you used in part (a)).





The particle ends with only potential energy (negative since it didn't escape). Set the energies equal and solve for final position.





You may have noticed that the equations call for M, but your problem only gives you g at the surface. No problem. F = GmM/r^2 = mg. Solve that to get g = GM/r^2.





(c) Just do the same thing in reverse. You have initial position and speed (0). You have final position. Set energies equal. Solve for final speed.


An elevator and its load weigh 160N.?

find the tension in the supporting cable,if after it was moving downward at 30m/s,it's brought to rest with const.acc.in a distance of 20m.With what force will the feet of the passenger press downward on the elevator floor,when the elevator has an acc.of 30m/s2 upward,if the passenger weighs,a.)16N;b.)640N;c.)64N?

An elevator and its load weigh 160N.?
For the first problem, you need a law of motion. (final velocity)^2=(initial velocity)^2+2*acceleration*displacement. Substituting, you get 0=30^2+2*a*20m and a=22.5 m/s^2. Now, we need to write a force equation: ma=Tension force-weight. To find the mass of the elevator and its load, divide its weight by gravity (9.8 m/s^2) to get about 16.3 kg. And you already calculated the net acceleration. Our force equation can now be rewritten as (16.3 kg)*(22.5 m/s^2)=Tension force-160N. The tension force is about 207N.





For each of the weight scenarios in the second problem, you know the net acceleration to be 30 m/s^2. You can also find the mass of the passenger by dividing his/her weight by gravity. With the force equation ma=(force of feet up)-(weight) with respect to the passenger, you can find the force of his/her feet. Here is the work for the first scenario.





16N/(9.8 m/s^2)=1.63 kg


1.63 kg*30 m/s^2=(force of feet)-16N


Force of feet=64.9N





Answers for the second and third scenario:


b) 2600N


c) 260N
Reply:this aint 7th grade science class damn


Please help w/ making a program, it just doesn't make any sence?

ok in school we're using Visual Basic 2005 to make an application program. We're basically finding how far away from the horizon this person is standing. The user has to be able to type in the number of feet high they are (standing on a platform). we're assuming that the earth is exactly round and the radius is 4000 miles. So it's a pathogorean theorem thing (a^2 + b^2 = c^2) where c=4000 miles + (whatever the user types in) * 5280, because it has to be converted to miles. b=4000, that's the constant. and we're trying to find a. This is what i've come up w/, but it didn't work:





Const sngB As Single = 4000


Dim sngC1 As Single


sngC1 = Val(txtprompt.Text)


Dim sngC As Single


sngC = sngC1 + 4000


Dim sngA As Single


sngA = (sngC^2) - (sngB^2)


Dim sngResult As Single


sngResult = Math.sqrt(sngA)


lblResult.Text = sngResult





if that doesn't make sence but you know how to do this, please email me, i really need help with this

Please help w/ making a program, it just doesn't make any sence?
Your equation is right.





A = sqrt( (c^2) - (b^2) )





Plugging in easy numbers (for instance, 1 mile above the ground), you get:





A = sqrt( (4001^2) - (4000^2) )





Which comes out to 89.448.





If when you run the program you get something close to that, good. Everything is fine.





If you're not, perhaps you're entering the height of the platform in feet, but forgetting to change it to miles before it gets added to C. In that case, you'd want to do something like:





sngC1 = Val(txtprompt.Text)


sngC1 = sngC1 / 5280


sngC = sngC1 + 4000





As for the other answers, Jamall has no idea what he's talking about. Ignore him.


Mom23 forgot the radius of the earth in his or her answer. What he or she should have written is


c = sqrt(4000^2 + ((a / 5280)+4000)^2)





If you continue to have issues, feel free to e-mail me. I'll try to help as much as I can.
Reply:c is the hypotenuse so the diagonal value is c which what you should be looking for


b is either the opposite side or the adjacent side but since you defined it as the earths radius it is the adjacent side or the height of the earth's radius


%26lt; he is here


\


| \


a \ c = is the distance between you and him


|__\ %26lt; you are here


b = distance between you and earth center


a = distance between him and earth he is standing on a


flatform so = earth's radius + vertical distance





so you really should compute for c





c^2 = a^2 + b^2


sqrt(c) = sqrt(a^2 + b^2)





so your code should be


a= b + (val(txtprompt.text) / 5280) ' converting it feet to miles


c = sqrt( (a * a) + (b *b))





i'm not really sure but it think this is the answer :)





sorry I can't get the diagram right.
Reply:I think your math is wrong.





C does not = 4000 + a*5280





c = sqrt(4000^2 + (a*5280)^2)





try that





**************





update: thanks to the guy below - sorry for trying to solve to quickly at night after wrangling 3 kids! (Ya lose it if ya don't use it!) LOL!
Reply:Well it most DEFINATELY doesn't make sense because B=C is logically impossible. If c=4,000 Miles, then why would you multiply that again, because C is your answer. If you're going to do anything with C, it's divide. I don't know the answer, but that's some math help that's probably REALLY good to know...

survey monkey