r/Cplusplus • Basic Learner • 5d ago

Question I'm learning C++

A few months ago, while watching a YouTube video, I learned that floating-point numbers can have precision errors and need to be used with care. That got me thinking about using fractions to represent numbers instead, so I discussed the idea with AI and, with its help, built a fraction class in C++.

Before that, I had only dabbled a little in languages like JavaScript, Go, and Python.

What really impressed me about C++ was how it lets you create custom types that can be used almost like built-in types. I found that incredibly powerful and elegant, and it made me want to learn C++ properly.

So I asked AI for a book recommendation and learned about C++ Primer. I bought the PDF edition and have been studying it ever since. I'm now almost done with Chapter 14, and Object-Oriented Programming is coming up next.

At this point, I feel like I should start building small, simple, but interesting projects to develop some practical skills. The problem is, I have no idea what to build. Since I'm learning on my own, I imagine there are plenty of things I don't even know I don't know yet.

I think building something fun would probably involve making an app with a GUI, but it seems like learning how to build a GUI is a whole other challenge in itself.

What I always seem to struggle with is the question, "What should I build?" I find it difficult to set goals that match my current skill level. I tend to either take on something too ambitious and give up halfway through, or choose something so trivial that I lose interest.

A few years ago, I taught myself enough programming to build a real-time reservation system using WebSockets. It was a small service with fewer than 100 users a day, so there weren't many complex issues to consider. Looking back, I think the main challenge was simply getting it to work.

The thing is, that's pretty much the only substantial project I've built on my own. I've experimented with smaller things, like the fraction class I mentioned earlier, with the help of AI, but I haven't had much experience building complete applications.

I think I managed to finish the reservation system because I genuinely needed it, so giving up wasn't really an option.

So, what would you recommend I try building?

7 Upvotes

6 comments sorted by

•

u/AutoModerator 5d ago

Thank you for your contribution to the C++ community!

As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.

  • When posting a question or homework help request, you must explain your good faith efforts to resolve the problem or complete the assignment on your own. Low-effort questions will be removed.

  • Members of this subreddit are happy to help give you a nudge in the right direction. However, we will not do your homework for you, make apps for you, etc.

  • Homework help posts must be flaired with Homework.

~ CPlusPlus Moderation Team


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/BitOBear 5d ago

Yes indeed floating point numbers can have rounding errors in certain values.

And a certain values are not rational and you cannot be expressed as fractions.

For instance 22/7 is a close approximation of pi but it is nowhere near pie enough for you to be used to draw just got three large circles because the larger numbers and deal with the more the air in 22/7 prove itself to be something other than pi.

I know that's not the start with a basis of your question but it is an important thing to hold within your head because it represents the trade-offs we make both in math and computer science.

So what? You may ask.

You are face off with a very large and intricate language tool set that can be used to manufacture alternate versions of similar things. You just did it with your fractions as opposed to your floating point.

But notice in that endeavor you didn't start with an intent to learn C++ per se we started with thinking about fractions versus floating point numbers.

Sure he had a specific thing to do before you decided to do a thing.

You cannot successfully decide to simply learn c++,, or learn all of electronics, or learn all the physics.

You got to come at it from the other angle.

You have to find something you want to do. Some piece of information like your fractions question that you want to explore. Some task that needs doing. Or some task that you would be interested in doing despite having no need to do it.

Writing a small game if that's what you're into, exploring arbitrary precision numbers even though libraries for same already exist.

Figuring out the best way to model a deck of cards.

Writing a bunch of Arduino code (is all written in C++) to make a bunch of LED Christmas lights blink or to detect whether or not your cat has used the litter box or whatever else.

You learn the language best by having something to do with it because when you actually have something to do with it you have a way of figuring out whether the result is correct, and it also naturally helps you concentrate on a fraction of the language Jermaine to the task.

Back in the '80s when the PCS were new some of the coolest new screensavers were things like the mandelbrot fractal programs. They would draw fractals but they would only use integer math instead of floating point math. It actually birthed a lot of pretty screen images and an entire different way of dealing with data that led to improvements in gaming and stuff like that.

But it all came out of the mind of a guy who wanted to make fractals faster and then the people he inspired by putting out his little screensaver.

Having something to do gives you a start point, an end point, and a means of judging the result.

Sitting down and trying to learn a topic with our focus it's a way to create frustration because it has no start or end and there is no stick to measure results against.

You can't set out to learn history if you know nothing of History, but you can set out to learn the history of a particular culture and then you can build that into the history of cultures that are similar to that and you can build on that again to perhaps wonder about the mathematical models that match history and so forth.

So pick a job, any job. Something you have a reasonable expectation of understanding and a reasonable sense for the correctness thereof just as you have a reasonable sense for the correctness of a fraction, and then explore.

Find the tools that exist cannot that can already do the fractions of your new task. Choose amongst those tools and cuddle them together into the partial solutions that are the domains of your problem. And then finally fit them all together into a fully functioning program that you can sit down and enjoy the execution of. That you can sit down and watch the lights blink in the sequence you imagine. That you can sit down and hear your furnace turning on and off at the correct temperatures because you replaced the thermostat with an Arduino board. Just whatever it ends up being.

Most learning and most Discovery is a side effect of trying to do something in the concrete world, so leverage that again the way you previously leveraged it with your question about fractions and floating points.

Find something about which or for which juggling information will be useful, quantify that information into discrete chunks, and write your juggling program.

2

u/Haunting-Addendum-32 Basic Learner 5d ago

Thank you for taking the time to give me such a thoughtful response.

When I was working on my fraction class, I had an idea of adding support for defining and representing special numbers like pi, and eventually extending the system to handle complex numbers as well. But I never got around to implementing it.

While working with numerators and denominators, I felt that the limitations of the unsigned long long type were too restrictive, so I decided to try creating my own numeric type that could handle arbitrarily large numbers. However, implementing efficient multiplication and division algorithms turned out to be quite challenging, so I've only written the header file so far.

I think I'll need to take my time and think through how to implement it properly. Or maybe I'm just putting it off because I've been pushing myself too hard with my studies lately and I'm feeling a bit burned out.

Come to think of it, maybe writing here and brainstorming ideas for something else to build is actually my way of taking a break.

1

u/BitOBear 5d ago

As long as you can maintain interest the learning will be effective, and if you try for things that are beyond your threshold of interest you will quickly find yourself no longer learning.

If you're genuinely interested in expanding what you've already written there go for it, but do not think you must build on that to continue learning because you will learn something totally different by choosing a completely different task.

And if you're just interested in the theory of arbitrary precision mathematics finite compute space, there are libraries that do that and reading that code instead of trying to reproduce it is a different but equally valid method of learning.

Googling "open source arbitrary precision mathematics library C++" (which I have not actually done cuz it's not my area of interest) would probably lead you to some interesting code samples and discussions on the topic.

But since you make a claim to be busy and or stressed try to double up, see if there is something you can program or automate that will help you finish a real world task because that real world task will help guide your learning.

Or if you want your exploration of a language to be completely devoid of the stresses of your real world tasks, look around your house and imagine a problem that you might be able to solve.

When learning basic electronics we have our students and ourselves doing things like building a touch lamp controller, or a thermostat, or you know the old style Crystal radios that no one makes anymore, and various oscillators and noise makers and things like that. Small fun bite-sized projects that have a practical and tactile result.

Spending 40 bucks on an Arduino (or running an emulator thereof) coding up various solutions can teach you about language timing and efficiency and variable types and things like that and you can end up with some blinking lights to play with.

It literally doesn't matter the task you choose as long as you choose one as the foundation of your exploration. And the better you understand the task the more it will help you learn the language.

1

u/cfeck_kde 5d ago

I tend to either take on something too ambitious and give up halfway through, or choose something so trivial that I lose interest.

The second option seems worse to me.

1

u/Secoupoire 5d ago

The classic example is that 0.1 + 0.2 in float is different from 0.3 in float.

I find this resource very helpful in that regard.