This document provides an overview of computer systems and programming. It defines a computer as a device that takes in raw data, processes it under a set of instructions called a program, and provides an output. Computers provide benefits like speed, accuracy, and ability to handle large workloads. The document then discusses computer hardware components, software components like operating systems and applications, and data representation in computers using bits, integers, and number systems. It also covers basic concepts in C++ programming like what a computer program is, compilers vs interpreters, and binary operations like addition and subtraction.
A digital system can understand positional number system only where there are only a few symbols called digits and these symbols represent different values depending on the position they occupy in the number.
Contents:
1.What is number system?
2.Conversions of number from one radix to another
3.Complements (1's, 2's, 9's, 10's)
4.Binary Arithmetic ( Addition, subtraction, multiplication, division)
A digital system can understand positional number system only where there are only a few symbols called digits and these symbols represent different values depending on the position they occupy in the number.
Contents:
1.What is number system?
2.Conversions of number from one radix to another
3.Complements (1's, 2's, 9's, 10's)
4.Binary Arithmetic ( Addition, subtraction, multiplication, division)
Logic Circuits Design - "Chapter 1: Digital Systems and Information"Ra'Fat Al-Msie'deen
Logic Circuits Design: This material is based on chapter 1 of “Logic and Computer Design Fundamentals” by M. Morris Mano, Charles R. Kime and Tom Martin
Decimal to Other Base System
Other Base System to Decimal System
Other Base System to Non-Decimal System
Shortcut method - Binary to Octal
Shortcut method - Octal to Binary
The 8th Digital Learning session - this time on the Binary number system.
There are walkthroughs on how to carry out the following arithmetic actions in binary:
Conversion
Addition
Subtraction
Multiplication
Aimed at the BTEC Unit 26 Maths for I.T module but great for all related purposes.
Logic Circuits Design - "Chapter 1: Digital Systems and Information"Ra'Fat Al-Msie'deen
Logic Circuits Design: This material is based on chapter 1 of “Logic and Computer Design Fundamentals” by M. Morris Mano, Charles R. Kime and Tom Martin
Decimal to Other Base System
Other Base System to Decimal System
Other Base System to Non-Decimal System
Shortcut method - Binary to Octal
Shortcut method - Octal to Binary
The 8th Digital Learning session - this time on the Binary number system.
There are walkthroughs on how to carry out the following arithmetic actions in binary:
Conversion
Addition
Subtraction
Multiplication
Aimed at the BTEC Unit 26 Maths for I.T module but great for all related purposes.
Number systems - Efficiency of number system, Decimal, Binary, Octal, Hexadecimalconversion
from one to another- Binary addition, subtraction, multiplication and division,
representation of signed numbers, addition and subtraction using 2’s complement and I’s
complement.
Binary codes - BCD code, Excess 3 code, Gray code, Alphanumeric code, Error detection
codes, Error correcting code.Deepak john,SJCET-Pala
Digital computers represent data by means of an easily identified symbol called a digit. The data may
contain digits, alphabets or special character, which are converted to bits, understandable by the computer.
In Digital Computer, data and instructions are stored in computer memory using binary code (or
machine code) represented by Binary digIT’s 1 and 0 called BIT’s.
The number system uses well-defined symbols called digits.
Number systems are classified into two types:
o Non-positional number system
o Positional number system
This is the second lesson of Computer and Network Technology subject of BCS HEQ Certificate Level exam.
Subject: Computer and Network Technology (CNT)
Chapter: Fundamentals
Lesson: Data Representation in Computers
This lesson discuss about how integers, floating point numbers and characters are handled by modern computers.
For more lessons please visit https://www.bcsonlinelectures.com website.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Digital Tools and AI for Teaching Learning and Research
chapter one && two.pdf
1. Chapter one
Basics of computer system
1.1 What is computer?
Computer is an advanced electronic device that takes raw data as input from the user and
processes it under the control of set of instructions (called program), gives the result
(output), and saves it for the future use.
1.2 Benefits of Computers
The three main benefits of using computers are :
1. Speed
2. Accuracy
3. Capacity to take large amount of work.
Computer work at a very high speed and are much faster than humans. The human equivalent of
an average computer would be more than one million mathematicians working 24 hours a
day. In addition to being fast, computers are very accurate. If the input and the instructions are
accurate the output will also be accurate.
Unlike humans, computers do not get bored or tired. The monotony of repetitive work for long
hours do not affect the computers.
Applications of Computers
Computers are used in various fields ranging from making cartoon films to space research. Some
applications of computers are:
1. Railway reservations
2. Banking and Accounts
3. Weather Forecasts
2. 4. Space Research
5. Medical Diagnoses
6. Chemical Analyses
Generally computer was developed from two parts, i.e from hard ware and software.
1.3 Hard ware component
Computer hardware includes all the electrical, mechanical, and the electronic parts of a
computer. Any part that we can see or touch is the hard ware. Computer hardware includes:
1. System Unit
2. Peripheral devices
3. Input devices i.e. keyboard, mouse etc.
4. Output devices i.e. Display Unit, printer etc.
5. Storage devices like hard disk, floppy disks etc.
1.4 Software component
The functioning of the computer is not dependent on hardware alone. So, what else is required?
It requires a set of instructions that tells the computer what is to be done with the input
data. In computer terminology, this set of instructions is called a program and one or more
programs is termed as software. This software can be categorized as system software and
application software.
Applications Software
Software specially suited for specific applications for example, railway and airline reservation,
billing, accounting or software which enables creation and storage of documents are termed as
application software.
System software
System software In the above airline reservation example, the clerk types your name and
other details through the keyboard. But how does this go to the system unit? This activity is
done by a set of instructions called the Operating Systems.
System software is a set of instructions that serves primarily as an intermediary between
computer hardware and application programs, and may also be directly manipulated by
knowledgeable users.
3. 1.3.1 Data representation in a computer
Computer uses a fixed number of bits to represent a piece of data, which could be a number, a
character, or others. A n-bit storage location can represent up to 2^n distinct entities. For
example, a 3-bit memory location can hold one of these eight binary
patterns: 000, 001, 010, 011, 100, 101, 110, or 111. Hence, it can represent at most 8
distinct entities. You could use them to represent numbers 0 to 7, numbers 8881 to 8888,
characters 'A' to 'H', or up to 8 kinds of fruits like apple, orange, banana; or up to 8 kinds of
animals like lion, tiger, etc.
Integers, for example, can be represented in 8-bit, 16-bit, 32-bit or 64-bit. An 8-bit unsigned
integer has a range of 0 to 255, while an 8-bit signed integer has a range of -128 to 127 - both
representing 256 distinct numbers.
It is important to note that a computer memory location merely stores a binary pattern. It is
entirely up to you, as the programmer, to decide on how these patterns are to be interpreted. For
example, the 8-bit binary pattern "0100 0001B" can be interpreted as an unsigned integer 65,
or an ASCII character 'A', or some secret information known only to you. The interpretation of
binary pattern is called data representation or encoding.
1.3.2 Integer representation
Computers use a fixed number of bits to represent an integer. The commonly-used bit-lengths for
integers are 8-bit, 16-bit, 32-bit or 64-bit. Besides bit-lengths, there are two representation
schemes for integers:
4. 1. Unsigned Integers: can represent zero and positive integers.
2. Signed Integers: can represent zero, positive and negative integers. Three representation
schemes had been proposed for signed integers:
1. Sign-Magnitude representation
2. 1's Complement representation
3. 2's Complement representation
n_bit unsigned integer
Unsigned integers can represent zero and positive integers, but not negative integers. The value
of an unsigned integer is interpreted as "the magnitude of its underlying binary pattern".
Example 1: Suppose that n=8 and the binary pattern is 0100 0001B, the value of this unsigned
integer is 1×2^0 + 1×2^6 = 65D.
Example 2: Suppose that n=16 and the binary pattern is 0001 0000 0000 1000B, the value of
this unsigned integer is 1×2^3 + 1×2^12 = 4104D.
Example 3: Suppose that n=16 and the binary pattern is 0000 0000 0000 0000B, the value of
this unsigned integer is 0.
An n-bit pattern can represent 2^n distinct integers. An n-bit unsigned integer can represent
integers from 0 to (2^n)-1, as tabulated below:
Signed integer
signed integers can represent zero, positive integers, as well as negative integers. Three
representation schemes are available for signed integers:
1. Sign-Magnitude representation
5. 2. 1's Complement representation
3. 2's Complement representation
n-bit sign integers in 1’s compliment representation
In 1's complement representation:
Again, the most significant bit (msb) is the sign bit, with value of 0 representing positive
integers and 1 representing negative integers.
The remaining n-1 bits represents the magnitude of the integer, as follows:
o For positive integers, the absolute value of the integer is equal to "the magnitude
of the (n-1)-bit binary pattern".
o For negative integers, the absolute value of the integer is equal to "the magnitude
of the complement (inverse) of the (n-1)-bit binary pattern" (hence called 1's
complement).
Example 1: Suppose that n=8 and the binary representation 0 100 0001B.
Sign bit is 0 ⇒ positive
Absolute value is 100 0001B = 65D
Hence, the integer is +65D
Example 2: Suppose that n=8 and the binary representation 1 000 0001B.
Sign bit is 1 ⇒ negative
Absolute value is the complement of 000 0001B, i.e., 111 1110B = 126D
Hence, the integer is -126D
n- bit sign integers in 2’s complement representation
6. In 2's complement representation:
Again, the most significant bit (msb) is the sign bit, with value of 0 representing positive
integers and 1 representing negative integers.
The remaining n-1 bits represents the magnitude of the integer, as follows:
o for positive integers, the absolute value of the integer is equal to "the magnitude
of the (n-1)-bit binary pattern".
o for negative integers, the absolute value of the integer is equal to "the magnitude
of the complement of the (n-1)-bit binary pattern plus one" (hence called 2's
complement).
Example 1: Suppose that n=8 and the binary representation 0 100 0001B.
Sign bit is 0 ⇒ positive
Absolute value is 100 0001B = 65D
Hence, the integer is +65D
Example 2: Suppose that n=8 and the binary representation 1 000 0001B.
Sign bit is 1 ⇒ negative
Absolute value is the complement of 000 0001B plus 1, i.e., 111 1110B + 1B = 127D
Hence, the integer is -127D
1.3.3 Decimal (base 10) number system
Decimal number system has ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, called digits. It
uses positional notation. That is, the least-significant digit (right-most digit) is of the order
7. of 10^0 (units or ones), the second right-most digit is of the order of 10^1 (tens), the third right-
most digit is of the order of 10^2 (hundreds), and so on. For example,
735 = 7×10^2 + 3×10^1 + 5×10^0
1.3.4 Binary (base 2) number system
Binary number system has two symbols: 0 and 1, called bits. It is also a positional notation, for
example,
10110B = 1×2^4 + 0×2^3 + 1×2^2 + 1×2^1 + 0×2^0
1.3.5 Hexadecimal (base 16) number system
Hexadecimal number system uses 16 symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F,
called hex digits. It is a positional notation, for example,
A3EH = 10×16^2 + 3×16^1 + 14×16^0
Hexadecimal system is used as a compact form or shorthand for binary bits. Each hex digit is
equivalent to 4 binary bits, i.e., shorthand for 4 bits, as follows:
Conversion from hexadecimal to binary
Replace each hex digit by the 4 equivalent bits, for examples,
A3C5H = 1010 0011 1100 0101B
102AH = 0001 0000 0010 1010B
Conversion from binary to hexadecimal
Starting from the right-most bit (least-significant bit), replace each group of 4 bits by the
equivalent hex digit (pad the left-most bits with zero if necessary), for examples,
8. 1001001010B = 0010 0100 1010B = 24AH
10001011001011B = 0010 0010 1100 1011B = 22CBH
Conversion from base r to decimal (base 10)
Given a n-digit base r number: dn-1 dn-2 dn-3 ... d3 d2 d1 d0 (base r), the decimal equivalent is
given by:
dn-1 × r^(n-1) + dn-2 × r^(n-2) + ... + d1 × r^1 + d0 × r^0
For examples,
A1C2H = 10×16^3 + 1×16^2 + 12×16^1 + 2 = 41410 (base 10)
10110B = 1×2^4 + 1×2^2 + 1×2^1 = 22 (base 10)
Conversion from decimal (base r) to base r
Use repeated division/remainder. For example,
To convert 261D to hexadecimal:
261/16 => quotient=16 remainder=5
16/16 => quotient=1 remainder=0
1/16 => quotient=0 remainder=1 (quotient=0 stop)
Hence, 261D = 105H
The above procedure is actually applicable to conversion between any 2 base systems. For
example,
To convert 1023(base 4) to base 3:
1023(base 4)/3 => quotient=25D remainder=0
25D/3 => quotient=8D remainder=1
8D/3 => quotient=2D remainder=2
9. 2D/3 => quotient=0 remainder=2 (quotient=0 stop)
Hence, 1023(base 4) = 2210(base 3)
General conversion between two base system with factorial part
1. Separate the integral and the fractional parts.
2. For the integral part, divide by the target radix repeatably, and collect the ramainder in
reverse order.
3. For the fractional part, multiply the fractional part by the target radix repeatably, and
collect the integral part in the same order.
Example 1:
Convert 18.6875D to binary
Integral Part = 18D
18/2 => quotient=9 remainder=0
9/2 => quotient=4 remainder=1
4/2 => quotient=2 remainder=0
2/2 => quotient=1 remainder=0
1/2 => quotient=0 remainder=1 (quotient=0 stop)
Hence, 18D = 10010B
Fractional Part = .6875D
.6875*2=1.375 => whole number is 1
.375*2=0.75 => whole number is 0
.75*2=1.5 => whole number is 1
.5*2=1.0 => whole number is 1
Hence .6875D = .1011B
Therefore, 18.6875D = 10010.1011B
Example 2:
10. Convert 18.6875D to hexadecimal
Integral Part = 18D
18/16 => quotient=1 remainder=2
1/16 => quotient=0 remainder=1 (quotient=0 stop)
Hence, 18D = 12H
Fractional Part = .6875D
.6875*16=11.0 => whole number is 11D (BH)
Hence .6875D = .BH
Therefore, 18.6875D = 12.BH
Binary addition
Example1: Add 010011112 to 001000112 using signed-magnitude arithmetic.
We find 010011112 + 001000112= 011100102 in signed-magnitude representation.
Example2: Add 010011112 to 011000112 using signed-magnitude arithmetic.
We obtain the erroneous result of 79 + 99 = 50.
Binary subtractions
Example1: Subtract 010011112 from 011000112 using signed-magnitude arithmetic.
We find 011000112-010011112=000101002 in signed-magnitude representation.
Example2: Add 100100112 (-19) to 000011012 (+13) using signed-magnitude arithmetic.
11. The first number (the augend) is negative because its sign bit is set to 1. The second number (the
addend) is positive. What we are asked to do is in fact a subtraction. First, we determine which of
the two numbers is larger in magnitude and use that number for the augend. Its sign will be the
sign of the result.
Chapter two
Fundamentals of C++ programming
2.1 Introduction to computer program
A computer program is a sequence of instructions written using a Computer Programming
Language to perform a specified task by the computer.
A computer program is also called a computer software, which can range from two
lines to millions of lines of instructions.
Computer program instructions are also called program source code and computer
programming is also called program coding.
A computer without a computer program is just a dump box; it is programs that
make computers active.
There are hundreds of programming languages, which can be used to write computer programs
and following are a few of them:
C
C++
Java
Python
a computer can only understand
binary numbers, so we need to
convert a text file into a binary
format or machine languages, so the
computer can easily understand.
12. PHP
Perl
Ruby
Compiler
Actually, the computer cannot understand your program directly given in the text format, so we
need to convert this program in a binary format, which can be understood by the
computer. The conversion from text program to binary file is done by another software
called Compiler and this process of conversion from text formatted program to binary
format file is called program compilation. Finally, you can execute binary file to perform the
programmed task.
Interpreter
13. Compilers are required in case you are going to write your program in a programming
language that needs to be compiled into binary format before its execution. There are other
programming languages such as Python, PHP, and Perl, which do not need any
compilation into binary format, rather an interpreter can be used to read such programs
line by line and execute them directly without any further conversion. So, if you are
going to write your programs in PHP, Python, Perl, Ruby, etc., then you will need to install
their interpreters before you start programming.
2.2 Algorithm
An algorithm is an effective method of step by step procedure which expressed as a finite
set of well-defined instructions.
2.3 Flowchart
The flowchart is a diagram which visually presents the flow of data through processing systems.
This means by seeing a flow chart one can know the operations performed and the
sequence of these operations in a system. Algorithms are nothing but sequence of steps for
solving problems. So a flow chart can be used for representing an algorithm.
2.3.1 Flowchart Symbols
There are 6 basic symbols commonly used in flowcharting of assembly language
Programs: Terminal, Process, input/output, Decision, Connector and Predefined Process.
14. Symbol Name Function
Process Indicates any type of internal
operation inside the Processor
or Memory
input/output Used for any Input / Output (I/
O) operation.
Decision Used to ask a question that can
be answered in a binary format
(Yes/No, True/False)
Connector Allows the flowchart to be
drawn without intersecting
lines.
Terminal Indicates the starting or ending
of the program, process, or
interrupt program
Flow Lines Shows direction of flow.
2.2.2 Type of Algorithms and flowchart
The algorithm and flowchart can be classified into three types of control structures. They are:
1. Sequence
The sequence is exemplified by sequence of statements place one after the other – the one above
or before another gets executed first. In flowcharts, sequence of statements is usually contained
in the rectangular process box.
Example 1: Write an algorithm and draw flowchart to read two numbers and find their sum.
Inputs to the algorithm:
First num1
Second num2
Expected output:
Sum of the two numbers
Algorithm:
Step1: Start
Step2: Readinput the first num1.
Step3: Readinput the second num2.
15. Step4: Sum num1+num2 // calculation of
sum
Step5: Print Sum
Step6: End
2. Branching (Selection)
It refers to a binary decision based on some condition. If the condition is true, one of the two
branches is explored; if the condition is false, the other alternative is taken. This is usually
represented by the ‘if-then’ construct in pseudo-codes and programs. In flowcharts, this is
represented by the diamond-shaped decision box.
example1: write algorithm and draw flowchart to find the greater number between two numbers
Step1: Start
Step2: Read/input A and B
Step3: If A greater than B then C=A
Step4: if B greater than A then C=B
Step5: Print C
Step6: End
3. Loop (Repetition)
16. It allows a statement or a sequence of statements to be repeatedly executed based on
some loop condition. It is represented by the ‘while’ and ‘for’ constructs in most
programming languages, for unbounded loops and bounded loops respectively. In the
flowcharts, a back arrow hints the presence of a loop.
Example1: An algorithm and draw flowchart to calculate even numbers between 9 and 99
1. Start
2. I ← 10
3. Write I in standard output
4. I ← I+2
5. If (I <=98) then go to line 3
6. End
2.4 Variables
A variable is a symbolic name for a memory location in which data can be stored and
subsequently recalled. Variables are used for holding data values so that they can be utilized in
various computations in a program. All variables have two important attributes:
A type which is established when the variable is defined (e.g., integer, real, character).
Once defined, the type of a C++ variable cannot be changed.
A value which can be changed by assigning a new value to the variable. The kind of
values a variable can assume depends on its type. For example, an integer variable can
only take integer values (e.g., 2, 100, - 12).
Example
#include <iostream>
int main ()
{
int workDays; //workdays is a variable,
int is data type
float workHours, payRate, weeklyPay; //
float is data type the other is variable
workDays = 5; // 5 is value of workDayays
in the memory allocation
workHours = 7.5;
17. payRate = 38.55;
weeklyPay = workDays * workHours *
payRate;
cout << "Weekly Pay = ";
cout << weeklyPay;
cout << ' n';
}
2.5 Simple input/output
The most common way in which a program communicates with the outside world is through
simple, character - oriented Input/output (IO) operations. C++ provides two useful operators for
this purpose: >> for input and << for output. #include <iostream.h>
Example
int main ()
{
int workDays = 5;
float workHours = 7.5;
float payRate, weeklyPay;
cout << "What is the hourly pay rate? ";
cin >> payRate;
weeklyPay = workDays * workHours *
payRate;
cout << "Weekly Pay = ";
cout << weeklyPay;
cout << ' n';
}
Integer numbers
An integer variable may be defined to be of type short , int , or long . For example, on the
author’s PC, a short uses 2 bytes, an int also 2 bytes, and a long 4 bytes.
short age = 20;
int salary = 65000;
long price = 4500000;
A literal integer (e.g., 1984 ) is always assumed to be of type int , unless it has an L or l and U
or u suffix, in which case it is treated as a long . For example:
1984L, 1984l, 1984U, 1984u, 1984LU, 1984ul
An integer is taken to be octal if it is preceded by a zero ( 0 ), and hexadecimal if it is preceded
by a 0x or 0X . For example:
92 // decimal
0134 // equivalent octal
0x5C // equivalent hexadecimal
Real number
A real variable may be defined to be of type float or double . The latter uses more bytes and
therefore offers a greater range and accuracy for representing real numbers. For example, on the
author’s PC, a float uses 4 and a double uses 8 bytes.
float interestRate = 0.06;
double pi = 3.141592654;
18. A literal real (e.g., 0.06 ) is always assumed to be of type double , unless it has an F or f
suffix, in which case it is treated as a float , or an L or l suffix, in which case it is treated as a
long double .
0.06F 0.06f 3.141592654L 3.141592654l
Characters
A character variable is defined to be of type char. A character variable occupies a single byte
which contains the code for the character. For example, the character A has the ASCII code 65,
and the character a has the ASCII code 97.
char ch = 'A';
A litera l character is written by enclosing the character between a pair of single quotes (e.g.,
'A' ). Nonprintable characters are represented using escape sequences. For example:
'n' // new line
'r' // carriage return
't' // horizontal tab
'v' // vertical tab
'b' // backspace
'f' // formfeed
Single and double quotes and the backslash
character can also use the escape
notation:
''' // single quote (')
'"' // double quote (")
'' // backslash ( )
Strings
A string is a consecutive sequence (i.e., array) of characters which are terminated by a null
character. A string variable is defined to be of type char* (i.e., a pointer to character). For
example, consider the definition:
char *str = "HELLO";
2.6 Names
Programming languages use names to refer to the various entities that make up a program. We
have already seen examples of an important category of such names (i.e., variable names). Other
categories include: function names, type names, and macro names.
C++ imposes the following rules for creating valid names (also called identifiers). A name
should consist of one or mor e characters, each of which may be a letter (i.e., 'A'- 'Z' and 'a'- 'z'),
a digit (i.e., '0' - '9'), or an underscore character ('_'), except that the first character may not be a
digit. Upper and lower case letters are distinct. For example:
salary // valid identifier
19. salary2 // valid identifier
2salary // invalid identifier (begins with a digit)
_salary // valid identifier
Salary // valid but distinct from salary
Reserved words
In C++ there are called reserved words or keywords and are summarized in Table.
Expressions in C++
C++ provides operators for composing arithmetic, relational, logical, bitwise, and conditional
expressions. It also provides operators which produce useful side effects, such as assignment,
increment, and decrement. C++ provides five basic arithmetic operators. These are summarized
in Table.
C++ provides six relational operators for comparing numeric quantities. These are summarized
in Table.
20. C++ provides three logical operators for combining logical expression. These are summarized in
Table.
C++ provides six bitwise operators for manipulating the individual bits in an integer quantity.
These are summarized in Table.
The next table illustrates bit sequences for the sample operands and results in the above Table. To
avoid worrying about the sign bit (which is machine dependent), it is common to declare a bit
sequence as an unsigned quantity:
unsigned char x = ' 011';
unsigned char y = ' 027';
21. The auto increment (++) and auto decrement (--) operators provide a convenient way of,
respectively, a dding and subtracting 1 from a numeric variable. These are summarized in Tabl e
suppose K=5.
The assignment operator is used for storing a value at some memory location (typically denoted
by a variable). Its left operand should be left value, and its right operand may be an arbitrary
expression. The latter is evaluated and the outcome is stored in the location denoted by the left
value.
Any number of assignments can be concatenated in this fashion to form one expression. For
example:
22. int m, n, p;
m = n = p = 100; // means: n = (m = (p = 100));
m = (n = p = 100) + 2; // means: m = (n = (p = 100)) + 2; i.e m=100
m + = n = p = 10; // means: m = m + (n = p = 10)