Introduction to Programming with C++
Programming with C++
Welcome to Introduction to Programming with C++
Introduction to programming with C++
Installing Visual Studio 2017
How to install Visual Studio 2017 Community Edition
Link to page:https://visualstudio.microsoft.com/vs/older-downloads/
Starting with C++ & Programming Languages
Programming Languages
In this unit, we will examine programming languages and Visual C++. We will exam a typical C++ program and how the C++ application works.
Before we can start developing, we need to understand the process of communication between program and machine.
Programming Structure
First program “Hello World”
C++ programs follow a standard layout (In most cases). They start with Libraries, default function, and comments.
First, create a project using C++ and select an empty project.
Libraries & Pre-processor
/* A comment block should be the first thing in a file! Comments are ignored by the compiler.
They help explain the code. It should summarize what the program does.
It should identify who wrote the program and when it was written.
*/ // Pre-Processor directives should follow the comment block. //
A pre-processor directive is an instruction to the preprocessor (which runs before the compiler) as to where to find useful definitions used by the code in the file. //
For example, the following line tells the preprocessor to bring in all the definitions from the iostream header file provided by the system.
// This is where the cin and cout input and output streams come from that enable keyboard input and console output.
#include <iostream>
using namespace std;
int main() {
// Your code here
return 0;
}
Stream insertion operator & Es’cape sequences
cout << “name”;
The console displays the value “name”
Es’cape sequences
Common elements in programming languages
What are the elements of a program -Key Words examples using, namespace, int, string, void … -Programmer-Defined Identifiers examples are name, firstName, sum, num1, numberOne … -Operators example +, _, *. / and <<, >> – Punctuation example string name, firstName, lastName; -Syntax rules of grammar use when writing a program C++ Keywords This is a list of reserved keywords in C++. Since they are used by the language, these keywords are not available for re-definition or overloading.
Input, Process and output (IPO)
Input Process & Output –
IPO Model
// IPO Input, Process and Output
//Input -> Gather input data from keyboard from files and Disk Drives
//Process the input data
//Display the results as output
// Procedural programming focus on the process ( Procedures or functions are written to process data)
Input | Process | Output |
Hours Rate totalPayCheck ask user for input hours ask user to input rate | TotalPayCheck = Hours * Rate; |
Cout << “you get paid” << totalPayCheck << endl;
You get pay 200 |
Variable Names
The name of a variable in programming should represent the purpose of the variable in the program.
For example, when you are adding two numbers.
- First Number should be call number1 or num1 or numberOne or _num1
- num1 First letter should be lower case
- _num1 you can use underscore to start the name of a variable
- numberOne If you have more than one word to describe the variable the second word should start with Upper case
- @num1 can NOT use special characters to begin the name of a variable
- 1Num can NOT begin the name with a number
Integer Data Types
Integer Data Types
// holds whole numbers as 5, 7, 230
int num1; //-2, 147.483.647 to +2,147.483.647
unsigned int; // hold only 0 up no negative numbers
short num2;// 2 bytes negative values all the way to positive -32,7698 to + 32.767
long num3; // 4 bytes – 2, 147.483.647 to + 2, 147.483.647
unsigned long num4; //hold only 0 up no negative numbers
https://www.geeksforgeeks.org/c-data-types/
Floating Data Types
Floating Data Types
Float
double
long double
hold real numbers 12.50 -3.5
all floating-point numbers are signed
float num1; //4 bytes, +-3.
double num2; //8 bytes hold only 0 up no negative numbers
long double num3;// 8 bytes
//Float Data Types – float double – long double
//hold real numbers 12.50 – 3.5
//all floating – point numbers are signed
float distance = 1.45674837E11;
double mass = 1.98E30;
long double num3 = 4.963737;
Char & String Data Types
Char & String Data Types
Character data type
This data type stores character values. It takes 1 byte in memory and is used to represent letters, numbers, punctuation marks, and a few other symbols.
These types of values are typically given in single quotes.
EXAMPLE
‘a’, ‘5’, ‘#’, etc
Bool Data Types
Bool Data Types
Represent values that are TRUE or FALSE
Booleans are variables that are stored as small integers
False represents 0
True represents 1
Arithmetic Operators
Arithmetic Operators
//Binary Arithmetic Operators
+ addition, – subtraction, * multiplication, / division, % modulus
// input
double regularWeekPayCheck; // how much we get pay a week
double rate = 18.25;// 18.25 + 9.125 = 27.78
double hours = 40.0;
//————————-
double overtime;
double overtimeRate = 27.78;
double overtimeHours = 10.0;
//————————-
double totalWeekWages;
// module
int num1 = 13;
int num2 = 5;
int totalModule;
//process
regularWeekPayCheck = hours * rate;
// overtime
overtime = overtimeRate * overtimeHours;
//— total week wages
// process for module
totalModule = num1 % num2;//
totalWeekWages = regularWeekPayCheck + overtime;
// output
cout << “Your week pay check is:\t” << regularWeekPayCheck << endl;
cout << “Your week overtime amount is:\t” << overtime << endl;
cout << “Your total week pay check is:\t” << totalWeekWages << endl;
cout << ” you total is” << totalModule << endl;
return 0;
3 Expressions & Interactivity
Cin Object & Constants
// cin object Standard input object
// requires iostream file
// reads input from the keyboard
//information retrieved from cin with >> operator
// input is store in one or more variables
Rules of Operator Precedence
Evaluation of a Second-Degree Polynomial
To develop a better understanding of the rules of operator precedence, consider the evaluation of a second-degree polynomial y = ax 2 + bx + c:
The circled numbers under the statement indicate the order in which C++ applies the operators. There is no arithmetic operator for exponentiation in C++, so we’ve represented x 2 as x * x. We’ll soon discuss the standard library function pow (“power”) that performs exponentiation. Because of some subtle issues related to the data types required by pow, we defer a detailed explanation of pow until Chapter 6.
Suppose variables a, b, c and x in the preceding second-degree polynomial are initialized as follows: a = 2, b = 3, c = 7 and x = 5. Figure 2.11 illustrates the order in which the operators are applied and the final value of the expression.
Making Decisions
- Allows statements to be conditionally executed or skipped over
- Models the way we mentally evaluate situations:
- If I have valid ID I am welcome into the gym
- else I should try again
Relational Operators
- Boolean expressions – true or false
- Used to compare numbers to determine relative order
- Operators:
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
== | Equal to |
!= | Not equal to |
- Boolean expressions – true or false
- Examples:
12 > 5 is true
7 <= 5 is false
if x is 10, then
x == 10 is true,
x != 8 is true, and
x == 8 is false
Nested if Statements
The if
and else
statements are used in C++ for decision making. They allow your program to execute certain code only when a specific condition is true.
if
Statement
- The
if
statement checks a condition. - If the condition is true, the code block inside the
if
statement is executed. - If the condition is false, the code block inside the
if
statement is skipped.
else
Statement
- The
else
statement is used to execute a block of code if the condition in theif
statement is false. - It comes immediately after an
if
statement.
For example:
#include <iostream>
using namespace std;
int main() {
int number;
cout << “Enter a number: “;
cin >> number;
if (number > 0) {
// This block will execute if number is greater than 0
cout << “The number is positive.” << endl;
} else if (number < 0) {
// This block will execute if number is less than 0
cout << “The number is negative.” << endl;
} else {
// This block will execute if number is equal to 0
cout << “The number is zero.” << endl;
}
return 0;
}
Stay connected for Arrays, Function, classes, object and more...
Conclusion
Thank you for participation in this introduction to C++. There is some more to covert. If you have fun with this tutorials I would recommend you to read the suggested books and practice.
Book Suggestions:
Prof. Gonzalez At New York City College of Technology and Founder of Lecturus.org and Lecturus

Lecturus is a platform that offers training to individuals interested in developing or enhancing their computer skills, as well as a career change or advancement.
Get In Touch
147 Prince St, Brooklyn, NY 11201
- Email: lecturus@outlook.com
- Phone: 929-280-7710
- Hours: Mon-Fri 9 AM - 5 PM

Lecturus is a platform that offers training to individuals interested in developing or enhancing their computer skills, as well as a career change or advancement.
Get In Touch
147 Prince St, Brooklyn, NY 11201
- Email: lecturus@outlook.com
- Phone: 929-280-7710
- Hours: Mon-Fri 9 AM - 5 PM