Computer Programming 1 - Module 1
Computer Programming 1 - Module 1
Module #1
Name:__________________________
Date: _________________________
Section: _________
Productivity Tip:
“Successful and unsuccessful people do not vary greatly in their abilities. They vary in their desires to reach
their potential.” – John Maxwell
“Start strong! Train your brain to shift to work mode by setting a regular time during the day for your lessons.
Set an alarm and stick to your “working hours”
LESSON PREVIEW/REVIEW
Introduction
Steve Jobs once said, "Everybody in this country should learn how
to program a computer... because it teaches you how to think."
Forget the country, follow the rest. Computer programming is an
enormously flexible tool that you can use to do amazing things that
are otherwise either manual and labor some or are just impossible.
If you're using a smartphone, a chat app or if you're unlocking your
car with the push of a button, then you must know that all these
things are using some kind of programming. You're already
immersed in the programs of different types. In fact, software is
running your life. For example, you can write a program that can
automatically respond to every new text message on your phone. To a message like "Hi" or "Hey," the program
can read through the message to detect some pre-defined keywords like "Hi" and "Hey," and send an automatic
response, which could be anything like, "Hi! What's up?" without you needing to see that message. You can even
program it for specific people in your contact list. By learning how to program doesn't mean that you have a
responsibility of creating the next Facebook or the next Dropbox. There was a need - someone suffered from the
lack of something. And then, he dared to address that need because he could. He knew there was a way to solve
that problem and make things easier for himself and probably others. You don't have to learn computer
programming to solve the problems of the world, but you can very well solve yours.
B. MAIN LESSON
C++ Variables:
In programming, a variable is a container (storage area) to hold data.
Variable should be given a unique name (identifier). For example,
We will learn about all the data types in detail in the next tutorial.
The value of a variable can be changed, hence the name variable. Note: The int data type suggests that the
variable can only hold integers. Similarly,
int age = 14; // age is 14
we can use the double data type if we have
int age = 17; // age is 17
Rules for naming a variable to store decimals and exponentials.
A variable name can only have alphabets, numbers and the underscore
_. A variable name cannot begin with a number.
Variable names cannot begin with an uppercase character.
A variable name cannot be a keyword. For example, int is a keyword that is used to denote
integers. A variable name can start with an underscore. However, it's not considered a good
practice.
Note: We should give meaningful names to variables. Example, first_name is a better variable name than fn.
C++ Literals
Literals are data used for representing fixed values. They can be used directly in the code. Example: 1, 2.5, 'c' etc.
Here, 1, 2.5 and 'c' are literals. Why? You cannot assign different values to these terms.
Here's a list of different literals in C++ programming.
1. Integers
An integer is a numeric literal (associated with numbers) without any fractional or exponential part.
For example: 21, 4, (positive integers) 0, (neither positive nor negative) and -1, -6 (negative integers)
2. Floating-point Literals - is a numeric literal that has either a fractional form or an exponent form.
For example: 5.5 and 0.001
3. Characters - is created by enclosing a single character inside single quotation marks.
4. Escape Sequences - Sometimes, it is necessary to use characters that cannot be typed or has special meaning in
C++ programming. For example, newline (enter), tab, question mark, etc.
In order to use these characters, escape sequences are used.