Dificulty getting problems started in C++

  • C/C++
  • Thread starter i_wish_i_was_smart
  • Start date
  • Tags
    C++
In summary: Afterhand, my program produced the following output: In summary, the maximum absolute value of MA is found when angle a is between 30-60 degrees. The corresponding value of angle a is also displayed.
  • #1
i_wish_i_was_smart
91
0
if this is in the wrong forum i truly apologize but this is an engineering question and who better to answer but engineers, i have dificulty getting problems started in C++, i just don't know how to get a problem started, writing the rest of the program is easy but i can't diagnose it properly, any of you know what i mean?? anyways hee is my problem.
moment MA about A due to the force exherted by the spring on the circular bar B is given by MA=h Fx - d Fy
where
Fx = F cosβ
Fy = F sinβ
F = (20) (L-1)
L = [(3-h)ˆ2 + (4cosα)ˆ2]ˆ0.5
β = tanˆ-1[(3-h)/(4cosα)]
d = 4(1-cosα)
h = 4sinα
units force length N and m respectively
write a C++ program to do the following
compute values of MA fo angle a ranging from 30 - 60 degrees in intervals of 0.1 degrees
compute and display the maximum absolute value of MA and the corresponding value of angle a in degrees
can anyone help me get started please
http://memimage.cardomain.net/member_images/5/web/557000-557999/557901_38_full.jpg
picture reads from left to right
4m, 3m, k, angle α, B and A
thanks
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
Sounds pretty straight forward, a structured program. You are given all the equations you need as well as the input range..

*No matter what language I code in, I always start out by working out the mechanics of the problem. In this kind of program, even hand-calculate a few of the inputs (say the endpoint angles and midpoint). Then when I generate some output, I can verify that my output is correct.
*Next I draw a flow-chart of the program.. (The last C++ instructor I had said , to either draw a flowchart or you could write pseudo-code). It may seem like an added step, but really defines the flow of your program.. You will see ahead of time things you would miss if you jumped right into coding..
In a flowchart you would indicate inputs (declare variable types, define constants etc.), show equations, as well as branching or looping structures, and outputs..
here are a couple of refs that describe the art of flowcharting --->http://www.hci.com.au/hcisite2/toolkit/flowchar.htm
--->http://www.nos.org/htm/basic2.htm
you can pretty much code into any language from there.

*Next step is code in C++
*Be sure to include lots of comments (so you can understand what you did
a month from now)
*Compile and run your code, debug errors
*Verify that your output is correct (as i mentioned above)
*Put finishing touches on your output using formatting syntax.
*Even if not required I like to save a copy of my hand calculations worksheet, flowchart, code, input and output.

That should get you off and running...
 
Last edited by a moderator:
  • #3
alright thx... there is one thing though, i am alright at determining what type of program i have to write, its the righting process i have trouble with, what code comes before another, it takes me too much time troubleshooting how to write my program... if you have any advice on how to effeciently write a program it would be greatly apreciated thx
 
  • #4
How much formal CS have you taken? Engineers tend to think 'coding' is easy especially in a high level language but when you get to large, complex systems it is anything but.
 
  • #5
this is just a first year engineering class here, everything is so compressed i barely learned anything, i only did 1 and 1/2 months of it, i am sure if i use it in my career i'll get better but right now its difficult for me
 
  • #6
i_wish_i_was_smart,
I've sent you a personal message for my next help on this one..
 
  • #7
i_wish_i_was_smart said:
alright thx... there is one thing though, i am alright at determining what type of program i have to write, its the righting process i have trouble with, what code comes before another, it takes me too much time troubleshooting how to write my program... if you have any advice on how to effeciently write a program it would be greatly apreciated thx

Not sure if you have read any of my personal messages to you, so will repeat here to see if you are receiving them all right.
Did you try making a flow chart of your problem? (or write pseudocode)?
While attempting to understand the problem, it is useful to do a hand calculation. This is like a simulation for what you will write using C++ code.

I made a hand caculation of the first input on your program. As I did this, I could see "one" order to list the equations in your program, that may be useful (They may differ from the order you find, but that's fine, there is more than one correct program).

Example: We need MA= hFx-dFy
but we don't have h, so h = 4sin(a) could be done before that.
For 'h', we don't have 'a' yet so we know that establishing the input (30-60, by 0.1 increments) must come before calculating h.
The other parameters were arranged using similar logic. Do you follow me?

After listing all the equations (and handcalculating) I noticed that one term occur several times. e.g. cos(a), This is a short program so it probably won't take very long to run. But if you also wanted to write more efficient code, you could calculate cos(a) all by itself [cos_a = cos(a)] and use the variable cos_a in place of cos(a) in the equations. That way the computer doesn't need to calculate cos(a) every time, it would just use the same value it calculated for cos_a, until 'a' changed to a new input value.

For a = 30 degrees, I found MA=92.38
(looking at the equation for MA, what units should that be in?) :rolleyes:
I don't know yet, if my solution is correct. My brain is not as efficient as a computer and could have made a mistake along the way.. If you try a hand calculation and get the same answer, there is a good chance, we both got it right. As you go thru the engineering program, you will find it is best to find a solutions to a problem more than one way. That will strengthen your belief, that you have the right answer.

Do you happen to have a program like MathCAD?
As you enter equations, it looks like real math equations, not like lines of program code. I am going to try this problem in MathCAD and if i get the same answer, that is a reasonable confirmation for the hand calculated output. Also in MathCAD once I have it working for one input, I can change the input value and it quickly finds the solutions for the rest of the equations.
 
  • #8
I was just in the process of adding my 2 cents when I noticed that Quabache had already posted what I wanted to say. No matter how simple you suspect the code is going to be, definitely get into the habit of drawing up a flow chart. Once you have the flow chart drawn out to handle the problem correctly, writing the code for each section is generally a piece of cake. And definitely use comments liberally. It's an unpleasant feeling to pull something up 6 months later and find that you nearly have to rewrite the code because you couldn't remember what it is you were trying to do.
 

1. What are some common reasons for difficulty starting problems in C++?

Some common reasons for difficulty starting problems in C++ include not fully understanding the language syntax, not having a clear understanding of the problem or how to approach it, and not having enough practice with problem-solving in C++. Additionally, not having a strong foundation in basic programming concepts can also contribute to difficulty in starting problems in C++.

2. How can I improve my ability to get started on C++ problems?

One of the best ways to improve your ability to get started on C++ problems is to practice regularly. This will help you build your knowledge and skills in the language, as well as improve your problem-solving abilities. It can also be helpful to seek out resources such as tutorials, online courses, or working with a mentor to gain a better understanding of the language and its concepts.

3. What are some techniques for overcoming difficulties in starting C++ problems?

Some techniques for overcoming difficulties in starting C++ problems include breaking down the problem into smaller, more manageable parts, brainstorming possible solutions, and seeking help or guidance from others. It can also be helpful to take breaks and come back to the problem with a fresh perspective.

4. Are there any resources that can help with getting started on C++ problems?

Yes, there are many resources available that can help with getting started on C++ problems. These include online tutorials, textbooks, coding forums, and even online communities where you can ask for help or collaborate with other programmers. It can also be helpful to have a reference book or website on hand for quick access to information and examples.

5. How can practicing with C++ problems benefit me as a programmer?

Practicing with C++ problems can benefit you as a programmer in several ways. It can help you improve your problem-solving skills, deepen your understanding of the language, and build your confidence and proficiency in C++. Regular practice can also help you become more efficient and effective at writing code, which can be valuable in any programming role.

Similar threads

  • Programming and Computer Science
Replies
1
Views
936
  • Introductory Physics Homework Help
Replies
11
Views
763
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
6
Views
7K
  • Programming and Computer Science
Replies
6
Views
1K
Replies
31
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
824
  • Engineering and Comp Sci Homework Help
Replies
23
Views
2K
  • Programming and Computer Science
Replies
2
Views
16K
Back
Top