Course Learning outcomes
S.
N
o
CourseLearning Outcome (CLO’s) Bloom’s
Learnin
g Level
1 Learn skills to propose solutions for real
life problems in terms of computer
programs.
C2
2 Analyze programs with standard notation/
methods to identify their structures.
C3
3 Develop programs using high level C3
Computer Languages
• Highlevel language resemble human
language. It is easy for human beings to
write programs in it e.g., C++, C#, Java,
Python, Pascal etc.
High level Languages
• One to one correspondence with machine
language. Use symbols or mnemonics to
represent instructions and data.
Assembly Language
• It is executed directly by hardware. Machine
instruction consists of binary e.g., 0s and
1s. .
Machine Language
10.
CONTD…
Any high-level languageprogram must
be translated into machine language
before the computer can understand and
follow the program
11.
Compiler
• A programthat translates a high-level language like
C++ to a machine language that the computer can
directly understand and execute.
• The input to the compiler is a program in high level
language (source program or source code) and the
translated version produced by the compiler is called
the object program or object code.
Assembler
• The Assembleris a Software that converts an assembly
language code to machine code.
• We can also name an assembler as the compiler of assembly
language.
• An assembler works by assembling and converting the source
code of assembly language into object code or an object file
that constitutes a stream of zeros and ones of machine code,
which are directly executable by the processor.
Linker
The object codefor your C++ program must be
combined with the object code for routines (such as
input and output routines) that your program uses. This
process of combining object code is called linking and
is done by a program called a linker.
Algorithms
A sequence ofprecise instructions which leads to a
solution is called an algorithm.
To qualify as an algorithm, a set of instructions must
completely and unambiguously specify the steps to be
taken and the order in which they are taken.
Logical error
The programwill run perfectly but it
will not behave in desired manner. It is
most difficult to spot logical errors. Can
only be resolved by careful testing.
28.
Example
If you intendto write:
“A dog bit a man…”
BUT mistakenly end up with
“A man bit a dog…”
29.
Runtime Error
There arecertain kinds of errors that the
computer system can detect only when a
program is run, these are called run-
time errors.
30.
Example
If the computerattempts to divide a
number by zero, that is normally a
run-time error.
31.
Brainstorming Time
Why studyC++ language??
What are latest job trends in
C++??
What are major applications
of C++ in the field of
computing ??
….
…..
Sample Program
• //This is a simple C++ program.
#include <iostream>
using namespace std;
int main()
{
cout<<“Welcome to Computer
Programming course”;
return 0;
}
36.
CONTD…
#include<iostream>
• A programincludes various programming elements
that are already defined in the standard C++ library.
• In order to use such pre-defined elements in a
program, an appropriate header/directives must be
included in the program.
• Directives always begin with the symbol #.
• <iostream> is the name of a library that contains the
definitions of the routines that handle input from
the keyboard and output to the screen.
• Do not include extra space between the < and the
iostream file name or between the end of the file
name and the closing >.
37.
• using namespacestd;
– This line says that the names
defined in iostream are to be
interpreted in the “standard way”.
• int main()
– It tells that your main part of a
program starts here.
• { }
– Braces mark beginning and end of
the main function.
• return 0;
– The last line in the program. It
marks end of the program.
38.
Variables
• Variable isthe basic storage unit in a program. It is
a name given to a memory location.
• The compiler assigns a memory location to each
variable name in the program. The value of the
variable, in a coded form, is kept in the memory
location assigned to that variable.
• We do not know what addresses the compiler will
choose for the variables in our program.
• Data held in a variable is called its value or a
literal; Number/data held by a C++ variable can be
changed.
• A C++ variable is guaranteed to have some value in
it, if only a garbage number left in the computer’s
memory by some previously run program.
39.
Names:
Identifiers
• Identifiers areused as names for variables
and other items in a C++ program.
• To make your program easy to understand,
you should always use meaningful names
for variables.
• Rules for naming variables:
– You cannot use a C++ keyword (reserved
word) as a variable name.
– Variable names in C++ can range from 1
to 255 characters.
– All variable names must begin with a
letter of the alphabet (a-z, A-Z) or an
40.
CONTD…
• After thefirst initial letter, variable
names can also contain letters and
numbers.
• No spaces or special characters
allowed.
• C++ is case Sensitive. Uppercase
characters are distinct from lowercase
characters.
• Examples:
– A, a_1, x123 (legal)
– 1ab, da%, 1-2, (not acceptable)
– Test, test, TEST (case-sensitive)
41.
Variable
declarations
• Every variablein a C++ program must be
declared before the variable can be used.
• When you declare a variable, you are
telling the compiler—and, ultimately, the
computer—what kind of data you will be
storing in the variable, and what size of
memory location to use for the variable.
• Each declaration ends with a semicolon (;).
• When there is more than one variable in a
declaration, the variables are separated by
commas.
• The kind of data that is held in a variable is
called its type and the name for the type,
such as int or double, is called a type name.
42.
Syntax
• The syntaxfor a programming languages is
the set of grammar rules for that language.
• The syntax for variable declarations is as
follows:
• Syntax
– Type_Name Var_Name_1, Var_Name_2, ...;
• Examples
– int count, sum, number_of_person;
– double distance;
43.
Assignment
statements
• In anassignment statement, first the
expression on the right-hand side of the
equal sign is evaluated, and then the
variable on the left-hand side of the equal
sign is set equal to this value.
• In an assignment statement, the
expression on the right-hand side of the
equal sign can simply be another variable
or a constant.
• Syntax
– Variable = Expression;
• Examples
– sum=a; //variable
– distance = rate * time; //expression
44.
Uninitialized
variables
• Variable thathas not been given a
value is said to be uninitialized.
• One way to avoid an uninitialized
variable is to initialize variables at
the same time they are declared.
• You can initialize some, all, or none
of the variables in a declaration that
lists more than one variable.
• Examples:
• int count=0; double avg=99.9; int
a=10, b, c=0;
Output using cout
•The values of variables as well as strings of
text may be output to the screen using
cout.
• The arrow notation << is often called the
insertion operator.
• You can simply list all the items to be output
preceding each item to be output with the
arrow symbols <<.
• Strings must be included in double quotes.
• Examples:
– cout<<“This is our first c++ program”;
– cout<<“The sum is”<<sum;
– cout<<“distance is”<<(time * speed);
47.
Input using cin
•A cin statement sets variables equal to
values typed in at the keyboard.
• cin is a predefined variable that reads data
from the keyboard with the extraction
operator (>>).
• Syntax
• cin >> Variable_1 >> Variable_2 >> ... ;
• Example
• cin >> number >> size;
• cin >> time;
48.
Data Types
• Datatypes are used to tell the variables
the type of data it can store.
• Whenever a variable is defined in C++, the
compiler allocates some memory for that
variable based on the data-type with which
it is declared.
• Every data type requires a different amount
of memory.
49.
Integer types
• Theinteger data type basically represents
whole numbers (no fractional parts).
• The reason is threefold.
– First, some things in the real world are
not fractional.
– Second, the integer data type is often
used to control program flow by counting.
– Third, integer processing is significantly
faster within the CPU than is floating
point processing.
Floating point types
•The floating-point family of data types
represents number values with fractional
parts.
• They are technically stored as two integer
values: a mantissa and an exponent.
• They are always signed.
• A floating_point number can also be a scientific
number with an "e" to indicate the power of 10:
52.
Type char
• Valuesof the type char are single
symbols such as a letter, digit, or
punctuation mark.
• A variable of type char can hold any
single character on the keyboard e.g., ’A'
or '+' or an 'a’.
• Note that uppercase and lowercase
versions of a letter are considered
different characters.
• The text in double quotes that are output
using cout are called string values.
• Be sure to notice that string constants
are placed inside of double quotes, while
53.
Type
bool
• Expressions oftype bool are called Boolean
after the English mathematician George
Boole, who formulated rules for mathematical
logic.
• Boolean expressions evaluate to one of the
two values, true or false.
• Boolean expressions are used in branching
and looping statements.
54.
Comment
• In C++the symbols // are used to indicate
the start of a comment.
• All of the text between the // and the end of
the line is a comment.
• The compiler simply ignores anything that
follows // on a line.
• Anything between the symbol pair /* and
the symbol pair */ is considered a comment
and is ignored by the compiler. Unlike the //
comments, /* to */ comments can span
several lines,