[C++] Which programs to write to learn more C++?

In summary: I use lists all the time. The second part I'm not so sure about. While I do think they are better for certain algorithms, I also think there are other containers that can do the same thing better. For sorting algorithms specifically, I think there are other ways to do it that are more efficient.In summary, I think that if you want to learn more about c++, you should get a book like "C++ From the Ground Up" or "SICP" and start from there. I also think that if you are going to do a computer science degree, you should focus on discrete mathematics.
  • #1
Mgkov18
20
1
Alright guys so I just finished my freshmen intro course in c++ and I found it interesting. This course only taught up to classes and file i/o. I want to learn more of c++ and overall many more programs. How do I teach myself c++ more indepth or are there any free sites you recommend to learn it or any other program?
 
Technology news on Phys.org
  • #2
I've been looking at 'C++ From the Ground Up' by Herbert Schildt (on the regrettably few occasions when I have time) and I've found it helpful, with unpacked explanations of what each piece of the code is doing along with other tips and things to be aware of. It goes all the way through from complete beginner level but you can just skip ahead to whatever suits your previous experience.

It is quite behemoth of a book, so you'd probably keep it at home, but my copy says $34.99 which is less than I would have expected for such a huge book. I avoided paying though by getting it from my university library, which is worth doing if you can. You might find the library has other books you like as well/instead.
 
  • #3
Don't use that book. Look up the term "bullschildt".
 
  • #4
I would recommend the book SICP by MIT. Even though it isn't in C++, rather Scheme. It's a great intro to CS book, and by the time you are done you will be a better coder for sure.
 
  • #5
I suggest Koenig and Moo's "Accelerated C++". Although it's supposedly for beginners, it takes a very different path from most C++ textbooks. It focuses on the container data types in the standard library (vector, string, list, set, etc.) instead of C-style arrays and pointers like most intro books do (or at least did when I used to teach intro C++).
 
  • #6
I second Accelerated C++ (by Koening) and agree with avoiding Schildt.
 
  • #7
I looked at these books online and they look pretty helpful and I will probably get them, but is there a good free way to learn programming or should I go with the book.
I just got out of college for the summer and moved back home so I do not have access to the school library
 
  • #9
Thanks. Also, if I want to get a minor in computer science, what would be most helpful to learn to prepare myself?
 
  • #10
I don't actually know what a minor as I am unfamiliar with the terms used by your country's (USA?) education system.

However if you do an honours degree, as in BSc, then Computer Science is heavy on mathematics no matter where you study it. In some cases it's more maths than programming. You'd probably want to look at a branch of mathematics called "discrete mathematics". The best thing to do is look on university websites and see the structure of their course, to give you an idea of what is in it.

I assume you are also aware of the difference between Computer Science and the other computing degrees?
 
  • #11
I have a computer science degree. This is what I use when I need to know something about C++: www.cplusplus.com. There is also C In a Nutshell (I think there is a C++ version too.) In response to what you need: math. Specifically boolean math, proof by induction, boolean operator identities:
x | (y & z) = (x | y) & (x | z)
!x & !y = !(x | y)
x & (y | z) = (x & y) | (x & z)
...
 
  • #12
We used to play documentation roulette with cplusplus.com. You picked a random page on the documentation and if there were precisely zero errors on the page, you survived. Otherwise, you were eliminated.
 
  • #13
Oh, that sounds like fun. I haven't run across very many errors in documentation there though.
 
  • #14
cplusplus.com was notorious for having lots of mistakes. It's not a community-developed product (e.g., wikipedia is a community-developed product), so it takes a while for errors to be corrected. If the author of a page doesn't think there is a mistake (but there is), it can take a long, long time for that error to get corrected. The community-developed competitor to cplusplus.com is en.cppreference.com. Errors in content are quickly corrected. Errors in context (an overly-technical, very unclear explanation): Those aren't so quickly corrected at cppreference.
 
  • #15
cppreference tends to avoid idioms and contextual issues as they're complex and mostly based on consensus, or require advanced understanding.

I noticed this on the 2nd page I checked when OP linked cplusplus.com.

std::list on cplusplus.com
"Compared to other base standard sequence containers (array, vector and deque), lists perform generally better in inserting, extracting and moving elements in any position within the container for which an iterator has already been obtained, and therefore also in algorithms that make intensive use of these, like sorting algorithms."

The first part I haven't a problem with. However the second part, sorting? You don't have random access so you are limited in your choice of algorithms, and how are you obtaining the links to the insertion points without iterating? Once you iterate over a linked list, it performs worse than a vector. In fact in most cases I have seen, you could insert into the middle of a vector, copying everyhing down 1 element, quicker than you can find the insertion point to do the same thing in a list. Traversing all those pointers plays hell with your cache pipeline.

Of course, as in all cases, profile your code if it matters. :-)
 
  • #16
Carno Raar said:
However the second part, sorting?
They really shouldn't write stuff like that, should they?

In their favor (I'm being generous), if it's a std::list<MyReallyBigHonkingClass>, there might be something to be said for sorting a list versus sorting a vector. The swaps used by std::sort will be expensive in this case. But ... they're stuck with something like mergesort to sort a list; no quicksort, heapsort, introsort, and they still have to traverse the list, on the order of N*log(N) times.

Oftentimes, it's faster to copy to a vector, sort that, and copy back to the list than it is to use std::list::sort.

Of course, as in all cases, profile your code if it matters. :-)
Of course.
 
  • #17
The best way to learn C++ is to think of what you want to do with the programs and try to apply it! Perhaps try to simulate physics models with them or something of the sort. Now although there will be guides online to do this. There will be plenty of forums (this one included!) that would love to help you with any ideas that you might have. I know C from programming an Arduino, and I found following tutorials very dull, and I found it more enjoyable to think of an experiment or a project and tackling it head on and felt like I learned a lot more head on!
 
  • #19
HallsofIvy said:
JAVA is a language similar to C++ and Sun Computers, who created it, have a free on-line tutorial at
http://www.homeandlearn.co.uk/java/java.html
Hallsoflvy is right, they are both objective languages and JAVA is a very useful language to learn! Very applicable and is used to program the apps on Androids. I might suggest learning python too, but it doesn't seem to be as useful or as widely known as C and JAVA. If you want something that you can make cool projects with, then starting with a raspberry pi would be a great idea!
 
  • #20
Another very nice property of Java is that you can download a Java compiler, for free, at https://www.java.com/en/download/help/index_installing.xml
 
Last edited by a moderator:
  • #21
HallsofIvy said:
Another very nice property of Java is that you can download a Java compiler, for free, at https://www.java.com/en/download/help/index_installing.xml
It's worth mentioning that you can also get the express version of Microsoft's Visual Studio (including C++) for free: https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx For most purposes, it is identical to the expensive professional version.
 
Last edited by a moderator:
  • #22
And to add to what jbunniii said, since the title of this thread includes C++ twice, one might surmise that you're interested in learning C++. In one regard Java is simpler to learn, because any objects you create are automatically destroyed when they're no longer in use, a feature that is not part of C++, where you have to keep track of heap usage on your own. Pointers are a part of C++, but not Java, and understanding how pointers work is a valuable skill.
 
  • #23
Java would be easier to learn than C++. It manages your memory for you, which can be a pain in C++.
 
  • #24
If we are discussing things that are not C++, then
  • To do anything with the browser, you need Javascript. It's the only way.
  • You may want a low level language in case you need to do some low level coding. --- C, C++ or Rust (if it's stable).
  • You may want a general purpose programming language for writing most of your stuff. --- Java, C#. Assume that anything running on a Windows desktop that isn't a game or scientific software is C# until proven otherwise. Java is slightly less well designed but is more compatible with non-Windows platforms and better for web.
  • You may want a dynamic language for rapid development and doing simple stuff fast. The speed at which you can write programs with these languages is incredible. --- Python, Ruby, Javascript w/ Node..JS. https://xkcd.com/353/
  • You may want a functional language to learn a new paradigm and do difficult algorithms with --- Haskell, LISP, Scheme, F#.
If you want to do mobile development then
  • Apple iOS uses Objective C and Swift. I do not know how much C++ they use.
  • Android uses C++ for gamedev and java for mostly anything else
If you want to write games
  • Simple games can be implemented in the language of your choice.
  • For complex game, use a game engine and learn whatever language it requires (Unity uses Javscript and C#).
  • You will probably end up writing some C++ in a complex game.
  • On a console, you need C++.
If you want to do websites
  • You will need JS for the browser.
  • You will need something like PHP, Python, Ruby or Node.JS for the back end. If the site is too slow, use Java where necessary.
 
  • Like
Likes Tosh5457
  • #25
newjerseyrunner said:
Java would be easier to learn than C++. It manages your memory for you, which can be a pain in C++.

Managing memory is a pain in C++ if you insist on programming as if it were C instead of using the standard library containers properly.
 
  • #26
Mark44 said:
And to add to what jbunniii said, since the title of this thread includes C++ twice, one might surmise that you're interested in learning C++. In one regard Java is simpler to learn, because any objects you create are automatically destroyed when they're no longer in use, a feature that is not part of C++, where you have to keep track of heap usage on your own. Pointers are a part of C++, but not Java, and understanding how pointers work is a valuable skill.
newjerseyrunner said:
Java would be easier to learn than C++. It manages your memory for you, which can be a pain in C++.

That is a myth, and has been for quite some time.

The trick is to avoid raw pointers. C++ has "smart pointers." C++11 has nailed this concept down. The concept goes by the terrible acronym is RAII, Resource Acquisition Is Initialization. Use RAII classes and class templates and your resource management worries go away. With regard to memory, the C++11 std::unique_ptr, std::shared_ptr, and related concepts (see http://en.cppreference.com/w/cpp/memory) means you don't need to keep track. (You do need to worry about problems that result from circular references such as in a circular linked list.) RAII, done correctly, means your resource management worries go away. All of them, not just memory. In Java you have to close files, sockets, etc. That's not the case in C++. They close themselves when the RAII objects that contain them go out of scope.
 
  • #27
D H said:
RAII, done correctly, means your resource management worries go away. All of them, not just memory. In Java you have to close files, sockets, etc. That's not the case in C++. They close themselves when the RAII objects that contain them go out of scope.

I am glad you mentioned that. Too many people regard garbage collection as magic that prevents all leaks. In truth, file handles and network sockets can both be limited and should be returned ASAP. When I write to a file I want that file updated and no-longer locked now, not at some future point when the gc deems it convenient.
 

1. What are some good beginner programs to write for learning C++?

As a beginner in C++, it is recommended to start with simple programs that cover the basic concepts of the language, such as variables, arrays, loops, and functions. Some popular beginner programs include a calculator, a guessing game, a temperature converter, and a simple text-based adventure game.

2. Are there any specific programs that can help me practice specific C++ concepts?

Yes, there are many programs that are designed to help you practice specific C++ concepts. For example, if you want to practice object-oriented programming, you can try creating a program that simulates a bank account or a library management system. If you want to practice working with files, you can create a program that reads and writes data to a text file.

3. Can you recommend any online resources for finding C++ program ideas?

There are many websites and forums dedicated to C++ programming that offer ideas and suggestions for programs to write. Some popular resources include Stack Overflow, Reddit's r/cpp_questions, and Codecademy's C++ forum. You can also find ideas by browsing through C++ project repositories on GitHub.

4. Should I focus on writing console-based programs or graphical programs?

It is recommended to start with console-based programs as they are simpler and provide a good foundation for understanding the basics of C++. Once you are comfortable with console-based programs, you can move on to creating graphical programs using a library such as SFML or SDL.

5. How can I challenge myself and improve my C++ skills once I have mastered the basics?

Once you have a good understanding of the fundamentals of C++, you can challenge yourself by creating more complex programs that require you to use multiple concepts and features of the language. You can also try participating in coding competitions or collaborating on open-source projects to further enhance your skills.

Similar threads

  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
8
Views
878
  • Programming and Computer Science
2
Replies
69
Views
4K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
3
Replies
86
Views
10K
  • Programming and Computer Science
Replies
9
Views
2K
Back
Top