Programming in C++ (Part 1 Variables)

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, structur…


This content originally appeared on DEV Community and was authored by Mark Mahoney

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.


This content originally appeared on DEV Community and was authored by Mark Mahoney


Print Share Comment Cite Upload Translate Updates
APA

Mark Mahoney | Sciencx (2021-04-14T23:02:06+00:00) Programming in C++ (Part 1 Variables). Retrieved from https://www.scien.cx/2021/04/14/programming-in-c-part-1-variables/

MLA
" » Programming in C++ (Part 1 Variables)." Mark Mahoney | Sciencx - Wednesday April 14, 2021, https://www.scien.cx/2021/04/14/programming-in-c-part-1-variables/
HARVARD
Mark Mahoney | Sciencx Wednesday April 14, 2021 » Programming in C++ (Part 1 Variables)., viewed ,<https://www.scien.cx/2021/04/14/programming-in-c-part-1-variables/>
VANCOUVER
Mark Mahoney | Sciencx - » Programming in C++ (Part 1 Variables). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/14/programming-in-c-part-1-variables/
CHICAGO
" » Programming in C++ (Part 1 Variables)." Mark Mahoney | Sciencx - Accessed . https://www.scien.cx/2021/04/14/programming-in-c-part-1-variables/
IEEE
" » Programming in C++ (Part 1 Variables)." Mark Mahoney | Sciencx [Online]. Available: https://www.scien.cx/2021/04/14/programming-in-c-part-1-variables/. [Accessed: ]
rf:citation
» Programming in C++ (Part 1 Variables) | Mark Mahoney | Sciencx | https://www.scien.cx/2021/04/14/programming-in-c-part-1-variables/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.