This 10 part series of posts will cover programming in C/C++. Through a series of code 'playbacks' I will guide you through the basics of computer programming.
I will cover declaring variables, if statements, loops, arrays/vectors, functions, structured data, pointers, classes, and some basic data structures. One way to describe C++ is "C with classes". I will cover classes pretty late in this series of posts so you will be learning the C language along the way until I get to classes. The things that you will learn here will help when learning other languages too because C and C++ have been around for a long time and have had an oversized influence on other programming languages.
Simply watching an experienced artist paint is not enough to say that you have learned how to become a painter. Watching an experienced artist is an important part of the learning process but you can only call yourself a painter after struggling to make your own paintings first. There are lot of similarities between learning to paint and learning to program. The only way to truly learn to program is to practice!
There are some great, free Integrated Development Environments (IDE) out there like visual studio and xcode. IDEs are tools that allow you to write your own programs. The simplest way to get started is to use a web-based IDE. I like replit and I can recommend it if you are unable to install one of the other IDEs.
So, let's get started. You will be asked to follow along with the programs below. Just click on the links and a code playback will load (you might want to open each one in a new tab). Then click on the comments on the left hand side of the screen or hit the play button to drive the development of the code. There are some controls in the top right hand side of the screen to make the text bigger or to switch to blog mode (which is good for small screens).
Flow of Control
In the following program I begin to discuss the 'flow of control' in a program by describing how to print to the screen from a program:
Variables and Types
This next group of programs describes declaring variables to hold data in a program. All variables have a type which specifies what can be stored in them and what operations can be performed on them.
Reading from the Keyboard
This final group of programs uses many of the concepts in the previous programs and they show you how to ask the user to enter data into a running program.
Call to Action
Now that you have reviewed the guided code walk-throughs in this post I ask that you write a program that prompts the user for three integers- one representing an hour, one representing a minute, and one representing a second. Next, calculate the number of seconds until midnight of that day. Print the number of seconds until midnight on the screen.
Then, make a second prompt for the user for a single integer that represents the number of seconds until midnight. From that value calculate the hour, minute, and second of that time. Print the number of hours, minutes, and seconds to the screen.
Comments and Feedback
You can find all of these code playbacks in my free 'book', An Animated Introduction to Programming in C++. I am always looking for feedback so please feel free to comment here or to send me a message. You can follow me on twitter @markm208.
Top comments (1)
Hi,
It would be nice if you could make this into a series. This would link all the C++ articles together.