C-2ND-SEM
C-2ND-SEM
C-2ND-SEM
Programming 2
Course code : IT CP12 | Prerequisite: IT CP11
Attendance 10
Examination 30
Class
60
Performance
Total: 100
Grading
Grading Criteria Percent
Attendance 10
Activity 15
Quiz 30
Major Exam 30
Total 100
What is programming?
• refers to the process of designing and building
an executable computer program to
accomplish a specific task or solve a particular
problem. It involves writing a set of
instructions in a way that a computer can
understand and execute. These instructions
are typically written in a programming
language.
What is programming
• language?
is a formal system that specifies a set of rules
and symbols for instructing a computer to
perform specific tasks. It acts as an
intermediary between human programmers
and the computer hardware, enabling humans
to communicate their instructions to the
machine in a way that is both readable and
understandable.
Programming languages can be broadly
categorized into high-level languages and low-
level languages:
Expected result
0
3
C++ Syntax
format or rules in scripting C++ code
C++ Syntax
Header file library
Remember!
2nd laboratory Activity
Create a program that the output the
console has horizontal tab, backslash
character and double quote character.
Ex) small personal essay, short story, local
news.
-double
>Use Cases:
>>double is commonly used when you need to work
with real numbers that may have a fractional part. It's
suitable for applications where precision is important,
such as scientific calculations, financial applications, and
graphics programming.
C++ variables
-float
>float is a fundamental data type used to represent
single-precision floating-point numbers and it is used to
store whole numbers WITH any decimal points.
>!Note! the use of the ‘f’ suffix to explicitly indicate that
the number is a float. Without the suffix, a decimal
literal in C++ is treated as a double by default.
C++ variables
-float
>Precision and Range of Values:
>>float is a single-precision floating-point type, which
means it provides less precision compared to the double
data type. Typically, it is represented using 32 bits and
conforms to the IEEE 754 standard. It can represent a
range of values, but with a smaller precision. The range
is approximately ±1.18 × 10^(-38) to ±3.4 × 10^(38),
and it can store decimal numbers with up to 7 significant
digits.
C++ variables
-float: Arithmetic operations
>You can perform various arithmetic operations on float
variables.
C++ variables
-float
>Use Cases:
>>float is commonly used when memory is a critical
consideration, and a lower precision is acceptable. It is
suitable for applications where storage space is at a
premium, such as in embedded systems, mobile
devices, and some graphics programming.
C++ variables
-char
>char is a fundamental data type used to represent
characters.
>!Note! A char variable stores a single character and is
enclosed in single quotes (‘F’).
>>ASCII Representation:
>>>Internally, char values are represented using ASCII
(American Standard Code for Information Interchange)
or a similar encoding. Each character is associated with
a unique numeric value. For instance, the ASCII value for
'A' is 65, 'B' is 66, 'a' is 97, and so on.
C++ variables
-char
>Use Cases:
>>char is commonly used to represent individual
characters, such as letters, digits, and special symbols.
It's frequently used in handling strings where each
character is stored in a contiguous sequence of char
variables.
C++ variables
-bool
>bool is a fundamental data type used to represent
Boolean values, which can only take on one of two
states: true or false; and also 1 or 0.
>bool is an essential data type for expressing and
working with conditions and logical operations in C++. It
is integral to writing expressive and effective code.
C++ variables
-bool: Logical operations
>bool variables are commonly used in logical
operations. The logical operators in C++ include ‘&&’
(logical AND), ‘||’ (logical OR), and ‘!’ (logical NOT)
C++ variables
-bool: Comparison operations
>bool variables are often the result of comparison
operations. Comparison operators include ‘==‘ (equal),
‘!=‘ (not equal), ‘<‘ (less than), ‘>’ (greater than), ‘<=‘
(less than or equal to), and ‘>=‘ (greater than or equal
to).
C++ variables
-bool
>Use Cases:
>>bool is commonly used to represent conditions and
control flow in programs. It is frequently used in if
statements, loops, and other decision-making
structures.
C++ variables
-string
>string is not a built-in data type like int or char; rather,
it is a part of the Standard Template Library (STL) and is
implemented as a class. The string class provides a
convenient way to work with strings of characters.
C++ variables
-string: Declaration and
Initialization
>To use the string class, you need to include the
<string> header. You can declare and initialize a string
as follows: