nedd help with c++ homework

Discussion in 'Software' started by lostinthisworld, Feb 5, 2006.

  1. lostinthisworld

    lostinthisworld Private E-2

    Hi, I just started this c++ programming class(only because it's required)and I know absolutely nothing. I am so lost it drives me crazy.
    here are my assignments and I don't know where to begin.
    My home number is 757-466-7840. I live in Norfolk, Virginia.
     
    Last edited: Feb 28, 2006
  2. TR15220

    TR15220 Private First Class

    Yep - it can be tough to get started.

    Do you have any programming experience/exposure at all (Visual Basic)?

    Were you able to code/compile/run the "Hello World" sample progam?

    What editor for the program are you using?

    What text book are you using for the course?
     
  3. lostinthisworld

    lostinthisworld Private E-2

    Re: need help with c++ homework

    Thank you so much for responding, I am truley at witts end. I am using Dev and Yes I did the hello world. I have never done programming and I am using Computer Science a structured approach using C++, by Behrouz A. Forouzan and Richard F. Gilberg. Did you notice the attachments, they are the homework I was talking about. Hoping to hear from you soon. Thanks again.
     
  4. TR15220

    TR15220 Private First Class

    Well, you have to do the reading....

    If you work thru the 1st couple of chapters of your text and do all the exercises you should start to get the hang of it.

    There are some great places on the web too.

    http://www.daniweb.com/tutorials/tutorial1740.html
    http://cplus.about.com/od/beginnerctutorial/l/aa020502a.htm
    http://www.informit.com/articles/article.asp?p=384462&rl=1

    You have a great clue in the code segment for Assignment #2 in Item 6.

    cout <<"Press q and then Enter to quit-->";
    char dummy;
    cin>>dummy;

    The first line prints a "Prompt" that's what he is talking about in Item 4.
    The next line declares a variable to contain Charcter data.
    The last line takes what you type in in response to the "Prompt" and puts it into the "dummy" variable.

    The text shows that you should declare your variables at the beginning of the C++ program. So for "Price", "MarkUp" and "Tax" you need to declare them before you prompt for the user to type in a value for them.

    char wordVariable (holds Character data - cannot do Math with this)
    int numVariable (holds Integer data - 1, 46, 123 No decimal point)
    float realVariable (holds numbers with a decimal part - 1.46, 0.12)

    Which type of variable should you use for "Price", "MarkUp" and "Tax" ?
    Do you have to do Math with them? (Add, Subtract, multiply, Divide)
    If Yes - then you cannot use char or Character variables.

    Since they are numbers and you do want to do Math with them, will the numbers have any decimal part? If Yes - then you cannot use int or Integer variables.

    So, that leaves float for numbers that will have a decimal part.

    float Price, MarkUp, Tax;

    Then to get the user to type in a value for Price you would use

    cout <<"Type in the Price and press the Enter Key-->";
    cin>>Price;

    That should get you started.

    You're going to have to read the book and check out the web sites cause even with help on the programming assignmnets you won't be able to do well on the tests and exams if you do not understand the material.

    If you do all the exercises, sample programs and work from the book it will be a pain and take some time but you will definitely master the material!!!

    Let me know if you run into any problems...
     
  5. TR15220

    TR15220 Private First Class

  6. TR15220

    TR15220 Private First Class

    For Assignment #3 - C++ Formatted Output

    Assignment #3 requires you to format the output so that the decimal points are aligned and the dollar and cents look correct on the output.

    The C++ Glossary is a good place to lookup terms you may not be familiar with:

    http://cplus.about.com/od/cprogrammin1/l/blglossary.htm

    The following link discusses formatted output and has examples that you can use.

    http://www.mcs.drexel.edu/~introcs/F98/placement/MCS171/lab3/lab3.html

    This link talks about defining a "Constant Variable"

    http://cplus.about.com/od/cprogrammin1/l/bldef_define2.htm

    And the rest you shoule be able to get from the text book.

    Is there anyone else in the class you can from a "study group" with?
    Getting together and discussing the lectures, course material and jointly working on assignments can make the class much, much easier......
     
  7. lostinthisworld

    lostinthisworld Private E-2

    Re: need help with c++ homework

    Trust me I have tried. Everyone is just as lost and there is noone in the tutoring lab that teaches this, so I am basically up the creek without the paddle. I really appreciate you taking the time to help. I will take all into consideration, If I run across a problem, do you mind if I ask you for advice? Thank you so much again..............and now to do some programming!
     
  8. TR15220

    TR15220 Private First Class

    No problem-Let me know if you run into any snags

    Just copy your program and paste it in your post and I'll review it and get back to you.

    Good Luck!!!

    Talk with you later....
     
  9. lostinthisworld

    lostinthisworld Private E-2

    Re: need help with c++ homework

    your the bomb!!
     
  10. Romeo55

    Romeo55 Private E-2

    Re: nedd help with c++ homework ( me toooo!)

    Im so Lost its a shame too... I have gotten so desperate that i paid a site to help me... and they still havent responded. Oh well... I just need some advice.. I know aa little bit. But not enough. If its ok with you, ill post my stuff in Word Doc ... much safer and trustworthy. Please tell me what to do, because i have no idea of what the prof was talking bout.. I sent those stuff to him and he sends it back with RED errors in it. I have attached it in Word doc.
    I have Microsoft Visual BAsic.
    Book used is as below..
    Computer Science:
    A Structured Approach Using C++, 2nd Ed.
    Bundled with compiler software
    Forouzan & Gilberg
    Bundle 0619295600
     

    Attached Files:

  11. lostinthisworld

    lostinthisworld Private E-2

    Re: nedd help with c++ homework ( me toooo!)

    Hi, do you have a copy of the original assignments instructions. I can see about getting you help and maybe turning you on to someone. I will ask them about it first. I also have that class and it;s been hard. I go to tutoring at school. That's another thing you might look into, a tutoring lab at the school. You can call me today between now and 3:30pm at 1-757-466-2300. I live in Norfolk, Va. My name is Lydia. My cell phone is 757-477-0668. When do you need the work by?
     
  12. Romeo55

    Romeo55 Private E-2

    i will call you around that time hopefully. If i dont.. ill still call so expect a 713 or 832 number from texas.. Tutoring sux in my school.. the highest they have is College algebra Tutors... The orignal assignment is zipped and attached on this message.. And the due date i think is like 2 more weeks.. but i have 5 assignments to do.. Its an online class.!!!
     

    Attached Files:

  13. lostinthisworld

    lostinthisworld Private E-2

    Re: need help with c++ homework

    :rolleyes: I have a question, where are the figures or numbers that are needed to be inputed. I realize you have the source code which is half the battle, but I need some calculations to put int the code. I also wanted to know what compiler are you using? Dev is the better one, than borland's. I don't like borland's.
     
  14. QuickSilver

    QuickSilver Corporal

    Romeo5K, the homework assignment is asking you to code, and invoke a function to calculate the area of a triangle.
    Whilst it looks like you have had a go at this, you have also in your code duplicated the guts of that function into main. That is what your professor has graded you as wrong on.

    Consider the program B1_Lab_02.cpp and the following line:

    Code:
    answer = trapezoid_area(long_side, short_side, distance_between);
    What this line is saying is:
    "Call a function called 'trapezoid_area' with the value of 2 variables as parameters. Those values are held in float variables called 'long_side' and 'short_side' - when you have finished this function I am expecting a floating point value to be returend and thats going to be placed in a float variable called 'answer'."

    Further down the program there is another line:

    Code:
    float trapezoid_area (float base, float top, float height)
    THis is the start, and possibly most important line, of a function. (Note it is repeated at the top of the source code with a ';' on the end - we'll get to that in a moment).
    This line of code explains three very important things about your function:
    a) Does it return any data, and what format is that data in?
    - this is the 'float' that leads your function. Its actually telling the compiler that the funciton you are writing is going to return a value which is a floating point number.
    b) the name of the function.
    - this is 'trapezoid_area' in the above example. Any other part in the program can invoke it (More or less) by using that name.
    c) The parameters the function receives.
    - In this case the function expects 3 floating point values, and it puts them into the following local names 'base', 'top' and 'height'.

    A function is almost like a 'black-box' to the rest of the program. You push in a few values, and another value comes out.

    Quickly for completness we'll cover the function prototype. That is the line near the top of the program that goes :
    Code:
    float trapezoid_area(float base, float top, float height);
    
    This tells the compiler that later on in the code it can expect that function. Without this line your code will fail because the compiler won't look beyond the main function. A function prototype should look exactly like the start of the function, just without the ';' at the end.


    So.........

    WHat have you been asked to do? Essentially you've been asked to create a function called 'traingle area', that returns a value of type double and receives two values of type double.
    You have already nailed what the main bulk of that function should be by putting the line in your main. However your assignment sepcifically asks for it to be in a function.

    - Change your function and function prototype to use doubles.
    - Place the necessary calculation in the function.
    - Look at how the trapezoid function 'return's its value (the clue is in this sentence)
    - Change your main function to invoke your shiny new 'triangle_area' function

    Thats all there is to it.

    I hope that helps some...
     
  15. Romeo55

    Romeo55 Private E-2

    thnx, now i see what u r saying.. It is complicated.. but understanding.. This C++ is crazy.. Its like adding 2+3.. but u dont want it to be 2+3.. U want 3+2+0.. Both gives same answer.. just different way of writing.
     
  16. QuickSilver

    QuickSilver Corporal

    Yea with programming there are lots of ways of solving a problem - some are more optimal than others.

    I guess with the stage you're at to look at a program which is meant to calculate the area of a triangle (when the core calculation can be done in a single line) you're right to wonder 'whats the point of having a function? It's like 5 additonal lines of code where it doesn't need to be' but try to look at the concept thats being introduced.

    What I'm saying is, in the case of a triangle area calculation program a function to calculate a triangle might not seem like the kind of thing that should go in a function. The challenge you have been set can be accomplished with a linear set of instructions (indeed like you had in the program you sent your tutor - he returned it because he wanted it in a function) so why bother going through a functional approach?

    But if you understand functions you'll begin to see that they're very useful for doing repetitive bits of code again and again.

    When I was at University we once had to write an Air Traffic Control simulator - it'd plot planes positions on a screen. The planes were read in off a file, and plotting their positions and updating them regularly relied on several small functions which did relatively simple mathemtics. A couple of these would take a few simple parameters in and then provide a useful function which allowed the planes to be tracked. These functions were called many many times over a run of the program. The code only has to be written once though.

    This concept in programming is sometimes called Top-down. You break a whole problem down into a chunks. And if necessary you break those chunks down into smaller bits. You tackle each chunk when its at a manageable size and put all the pieces together.
    With some planning and careful coding it can lead to a very good solution.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds