Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Visit the following for c++ programs

  1. Nov 29, 2006 #1
  2. jcsd
  3. Nov 29, 2006 #2

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    You'll want to specify what environment you're using: it's not standard C++. For example, the "conio.h" header, and the getch() and clrscr() commands are not part of the C library.
     
  4. Nov 29, 2006 #3
    yes sir,I used Turbo c++
     
  5. Nov 30, 2006 #4
    You should wrap your code in <pre> </pre> tags, so that we can see the indenting. Alternatively, it would be nice to see a syntax highlighter. Such code exists in PHP.

    A several things now...

    It would be nice to see some more meaningful variables names.

    Comments are always good. I still haven't found a single comment in any of your programs.

    Check your input for validity. How do you know the user isn't inputting any trash? How can you be sure he/she selected one of the options provided?

    Likewise, make sure you aren't dividing by zero. What if the user enters in 0 for #2 in Chapter 1?

    Furthermore, make sure you aren't square rooting a negative number. The user could easily enter a negative number for #1 in Chapter 2.

    As Hurkyl suggested, you need to specify the environment. People don't like finding code that won't work on their compiler. Better yet, write the code so its portability is not restrticed in the first place.

    Don't use labels and/or the goto statement. This is generally horrible coding practice. Although the script kiddies will understand your code, Bjarne Stroustrup would come straight to your doorstep and set you straight, if it weren't for so many others making the same mistake. The only time a goto is ever tolerated, is whilst exiting an extremely deeply nested loop. And even then, the question how you got there in the first place is brought to attention. I'd suggest that you return, instead of using a goto.

    You are placing things that suggest a subroutine, by nature, into main. Although this is tolerable, a better programming habit would lead you to fold your routines into separate functions, pass in the appropriate values from main, and output the corresponding message afterwards. The advantage to this, is people would actually find it beneficial to make use of your code, in light of it being extendable to something useful.

    My mouse wheel is getting worn down, so I'll stop here at Chapter 2. I don't mean to discourage you. I'd just like to see some of this shaped up a little. You have something to offer, it would be nice to see it offered to the extent of your abilities. It's not kind to misguide others into poor programming habits.

    If you require any clarification of any ideas I have suggested, please ask. I'd like to help you strengthen your website.
     
    Last edited: Nov 30, 2006
  6. Dec 1, 2006 #5
    thank you for your suggestions .I will sure work on them.
     
  7. Dec 1, 2006 #6
    Have you learned how to write a function in C++? If you would like some help, or if you are still uncomfortable with them, I could give you some assistance.

    Edit : I've noticed in your later chapters, you do have some understanding of functions and structures, which is excellent. But I've noticed that there are some weird things that you do. From Chapter 5:

    Code (Text):
    ...

    int main () {
       ...
       comp c1,c2,cs,cm,cd;
       ...
       cs=add (c1,c2,cs);
       ...
    }

    comp add(comp c1,comp c2,comp cs)
    {
       cs.r=c1.r+c2.r;
       cs.i=c1.i+c2.i;
       return cs;
    }

    ...
    The "cs" variable that you pass into the function add, is not the same variable that's recieved. Since you are passing by value, an actual copy of the variable is made before entering the next function. It's misleading to see it done that way.

    It does not make sense to need to pass the additional structure in by value. It would be more appropriate to see:

    Code (Text):
    ...

    int main () {
       ...
       comp c1,c2,cs,cm,cd;
       ...
       cs=add (c1,c2);
       ...
    }

    comp add(comp c1,comp c2)
    {
       comp cs;
       cs.r=c1.r+c2.r;
       cs.i=c1.i+c2.i;
       return cs;
    }

    ...
    I think there's a mistake in your multiply function.

    I tried to multiply 78 + 12i by 65 + 43i. The answer I got was 88 + 4134i, when it is actually 4554 + 4134i.

    Division worked great.
     
    Last edited: Dec 1, 2006
  8. Dec 1, 2006 #7
    I never realized that making a website on c++ ,because I am unexperienced in this field,could have such serious consequences as leading others to bad programming habits.Actually I learnt c++ on my own.I never thougth that somebody would LEARN from my website when there is a glut of much better c++ websites!should I delete my website?
     
  9. Dec 1, 2006 #8
    Of course not! Yikes! :eek:

    I did not mean to make it sound like people couldn't benefit from your code. Many people learn by reading other peoples' code, especially when your examples are so similar to the kind of programs most people will be writing in College and High School!

    Your code only requires little improvements to make the difference between executable and exceptional. I'm making these observations so hopefully you can break that boundary.

    There are never too many sites containing code snippets. If you do some of the things I've suggested to help perfect what you've got, who knows? It could become well known one day.

    Also, you have more potential for writing this than I do. You know exactly what another student will need to see and learn. I don't. That's why I'm not building a website right now!
     
    Last edited: Dec 1, 2006
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Visit the following for c++ programs
  1. C program (Replies: 4)

  2. C Program (Replies: 3)

  3. C program (Replies: 0)

  4. C programming (Replies: 9)

Loading...