Visit the following for c++ programs

  • C/C++
  • Thread starter chandubaba
  • Start date
  • Tags
    C++ Programs
In summary, it would be nice to see some more meaningful variables names, comments, and better use of labels and the goto statement. Furthermore, your code is misleading with the use of by value. You should either pass by reference or use a function that takes no additional parameters.
Technology news on Phys.org
  • #2
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.
 
  • #3
yes sir,I used Turbo c++
 
  • #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:
  • #5
thank you for your suggestions .I will sure work on them.
 
  • #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:
...

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:
...

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:
  • #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 learned 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?
 
  • #8
chandubaba said:
should I delete my website?

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:

1. What is the purpose of visiting the following for c++ programs?

The purpose of visiting the following for c++ programs is to learn and practice writing programs in the c++ programming language. This can help improve programming skills and understanding of the language's syntax and structure.

2. Do I need any prior knowledge or experience with c++ to benefit from visiting the following for c++ programs?

Some basic knowledge of programming principles and concepts is helpful, but no prior experience with c++ is necessary. The programs provided can be used as a learning tool for beginners or as a reference for more experienced programmers.

3. Are there any specific requirements or resources needed for visiting the following for c++ programs?

To run and test the c++ programs, you will need a c++ compiler installed on your computer. Some popular options include GCC, Clang, and Visual Studio. You may also want to have a text editor or integrated development environment (IDE) to write and edit the code.

4. Can I use the programs on the website for personal or commercial purposes?

Yes, the c++ programs on the website are available for personal and commercial use. However, please be sure to check the license or terms of use for each individual program as some may have specific restrictions or requirements.

5. How often are new c++ programs added to the website?

The frequency of new c++ programs being added to the website may vary. It depends on the contributors and authors who share their programs on the platform. You can also contribute your own c++ programs to the website to help expand the collection.

Similar threads

  • Programming and Computer Science
Replies
4
Views
608
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
8
Views
868
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
17
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
Replies
65
Views
3K
  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
2
Replies
69
Views
4K
Back
Top