Professional Documents
Culture Documents
Csc 201 Lecture Note
Csc 201 Lecture Note
STUDENTS (200L)
COURSE UNIT: 4
COURSE OUTLINE
WEEK TOPIC
1 INTRODUCTION TO DIGITAL COMPUTERS,THEIR USES, AND STRUCTURE OF A
GENERAL PURPOSE-COMPUTER
2 BRIEF HISTORY OF COMPUTERS
3 GENERATION OF COMPUTERS
4 MODERN PROGRAMMING TECHNIQUES
5 GENERAL PROBLEM SOLVING, SYSTEMATIC DEVELOPMENT OF ALGORITHM,
ELEMENTARY NUMERICAL ALGORITHM
6 FLOW DIAGRAMS
7 MEANING OF LOGICAL PROCESSES, ANALYSIS OF COMPUTATIONAL PROBLEMS,
CODING OF PROGRAMMING
8 PRACTICAL EXPERIENCE OPERATING COMPUTERS AND PERIPHERAL
EQUIPMENT
9 EXTENSIVE PRACTICE WITH ONE OR MORE HIGH LEVEL LANGUAGE
10 EMPHASIS ON TECHNICAL APPLICATIONS
11 REVISION / CA
INTRODUCTION TO COMPUTER
A computer is a programmable machine (electronic and digital) that is capable of accepting data
(input) and performing a sequence of operations (process) in accordance with set of procedural
instructions (program) to produce a result in form of information or signals (output).
1. Input Device
2. Central Processing Unit (CPU)
3. Output Unit
1. Input Device: It reads information from input media and enters to the computer in a coded form
2. Central Processing Unit: this is sub-divided into three, namely;
3. Arithmetic Logic Unit: It performs arithmetic and logical functions
4. Control Unit: It controls the input and output devices
Memory Unit : It stores program and data e.g Register, Cache etc.
Data: It is the collection of raw facts, figures & symbols. Ex : Names of students and their marks in
different subjects listed in random order.
Information: It is the data that is processed & presented in an organized manner. For example:
When the names of students are arranged in alphabetical order, total and average marks are
calculated & presented in a tabular form, it is information.
Program: This is a set of instructions that enables a computer to perform a given task
ADVANTAGES OF COMPUTERS
1. High speed: Computers have the ability to perform routine tasks at a greater speed than human
beings. They can perform millions of calculations in seconds.
2. Accuracy: Computers are used to perform tasks in a way that ensures accuracy.
3. Storage: Computers can store large amount of information. Any item of data or any instruction
stored in the memory can be retrieved by the computer at lightning speeds.
4. Automation: Computers can be instructed to perform complex tasks automatically (which
increases the productivity).
5. Diligence: Computers can perform the same task repeatedly & with the same accuracy without
getting tired.
6. Versatility: Computers are flexible to perform both simple and complex tasks.
7. Cost effectiveness: Computers reduce the amount of paper work and human effort, thereby
reducing costs.
LIMITATIONS OF COMPUTERS
1. Computers need clear and complete instructions to perform a task accurately. If the instructions
are not clear & complete, the computer will not produce the required result.
2. Computers cannot think.
3. Computers cannot learn by experience.
Computer hardware is the collection of the physical parts of a computer system. This includes the
computer case, monitor, speaker, scanner, printer and mouse. It also includes all the parts inside the
computer case, such as the hard disk drive, motherboard, video card etc.
Output devices
1. Storage devices
2. Communication networks
3. Input devices
An input device is a piece of computer hardware used to send data into a computer system. An input
device allows users to communicate and feed instructions and data to computers for processing,
display, storage and transmission
1. Keyboards
2. Mouse
Digital camera
1. Light pen
2. Scanner
3. Joystick
1. Processing devices
A processing device is any device in a computer that processes data into a usable format for the user.
When a computer receives data from an input device (e.g keyboard or mouse) the data must go
through an intermediate stage before it can be sent to an output device (e.g monitor or printer). A
processing device handles the intermediate stage.
Motherboard
1. Network card
2. Sound card
3. Video card
The microprocessor is the major device in this category. It works closely with primary memory
during its operations. Data is stored temporarily in processor cache and primary memory during the
processing period.
The microprocessor is sub-divided into three important units, namely:
1. The Control unit: It manages and supervises the operations of the processor and other
components that are crucial in data manipulation.
2. Arithmetic and logic unit: The ALU is responsible for all arithmetic and logic operations like
addition, multiplication, subtraction, division, and comparison logic operations.
3.
Register and cache: These are storage locations inside the processor that respond to the
instructions of the control unit by moving relevant data around during processing.
Output devices
An output device is any peripheral that receives data from a computer, usually for display,
projection, or physical reproduction. An output unit is responsible for providing the output in user
readable form. It can be text, graphics, tactile, audio, and video.
1. Monitor
2. Printer
Plotter
1. Projector
2. Speaker
3. Storage device
Storage device refers to a computer hardware device used to store information permanently or
temporarily. The device can be external or internal to a computer, server, and other computing
systems.
1. Communication Networks
Computer hardware requires physical connections that allow components to communicate and
interact. A bus provides a common interconnected system composed of a group of wires or circuitry
that coordinates and moves information between the internal parts of a computer.
A bus is characterized by two features: how much information it can manipulate at one time, called
the bus width, and how quickly it can transfer these data.
1. A serial connection is a wire or set of wires used to transfer information from the CPU to an
external device such as a mouse, keyboard, modem, scanner, and some types of printers. This
type of connection transfers only one piece of data at a time, and is therefore slow.
2. A parallel connection uses multiple sets of wires to transfer blocks of information simultaneously.
Most scanners and printers use this type of connection. A parallel connection is faster than a serial
connection.
SOFTWARE
Software is a collection of programs that utilize and enhance the capability of the hardware.
1. System software
2. Application software
3. System software
System software is responsible for controlling, integrating, and managing the individual hardware
components of a computer system so that other software and the users of the system see it as a
functional unit without having to be concerned with the low-level details such as transferring data
from memory to disk, or rendering text onto a display.
Examples of system software include Microsoft Windows Operating System, Linux, UNIX, Macintosh
OS, Disk Operating System, AVG etc.
1. Operating System
2. Language translator
3. Utility programs
4. Device driver
5. Operating system
An operating system is a suite of programs that manage computer hardware and software resources.
1. It manages the computer’s resources such as central processing unit (CPU), memory, disk drives,
printer etc.
2. It provides services for applications software.
1. Language translator
Language translator is a computer program that performs the translation of a program written in a
given programming language into a functionally equivalent program in another computer language.
1. Utility programs
These programs are primarily used for diagnostic and maintenance tasks of the computer.
Examples include
1. Device Driver
Device driver is a type of system software that activates computer devices and peripherals. Drivers
make it possible for all connected components and external devices to perform their intended tasks as
directed by the operating system.
Soundcard
Network card
Display card
Application software
These include:
1. Entertainment software
2. Educational and Reference software
Specialty software
1. Productivity software
2. Personal software
Since the creation of man, a significant amount of human activities has been ascribed to organizing
and processing information so that it could be more easily presented for easy comprehension. It is
necessary to examine the evolution of computers.
1. Tally Sticks
A tally stick was an ancient memory aid device to record and document numbers, quantities, or even
messages.
2. Abacus
3. Napier’s Bone
In 1614, John Napier invented Napier’s Bone. This consists of small rods with appropriate markings
on them. It is a mechanical device used to perform multiplication, division and calculate square and
cube roots by moving the rods around and placing them in specially constructed boards.
4. Slide Rule
In 1622, William Oughtred invented the Slide Rule but announced it in 1632. The Slide Rule permits
calculation involving multiplication, division, exponents,logarithm, trigonometric functions etc.
Blaise Pascal, a French mathematician in 1642 invented the first adding machine called Pascaline. It
can perform addition and subtraction.
7. Jacquard Loom
1801, Joseph-Marie Jacquard invented Jacquard loom. His invention provided a mechanized means of
controlling weaving looms leading to woven fabrics such that complex patterns can be woven to the
cloth. It an automatic loom controlled by punched cards.
8. Arithmometer
In 1820, Thomas de Colmar invented a mechanical calculator, the first reliable, useful and
commercially successful calculating machine. The machine could perform the four basic mathematic
functions.
In 1812, Charles Babbage developed Difference Engine. This machine had the capability of
polynomial evaluation by means of finite difference and consequently was very useful in the
generation of mathematical tables.
In 1832, Charles Babbage made a more serious effort which resulted in his invention of the Analytical
Engine. The Analytical Engine was programmed by Lady Augusta Ada Byron.
In 1890, Herman Hollerith, an American Statistician developed Hollerith Machine to help Americans
in census result processing.
11. ENIAC
In 1946, John Presper Eckert and John Mauchly developed the first electronic general purpose
computer called ENIAC. ENIAC stands for Electronic Numerical Integrator And Computer.
Electronic Controls Company (ECC) was the First Computer Company founded by John Presper
Eckert and John Mauchly in 1949.
12. UNIVAC 1
The UNIVAC I (UNIVersal Automatic Computer 1) was the first commercial computer designed by
John Presper Eckert and John Mauchly in 1951.
13. EDVAC
EDVAC stands for Electronic Discrete Variable Automatic Computer. EDVAC was the first stored
program computer designed by Von Neumann in 1952. It has a memory to hold both a stored
program as well as data.
CLASSIFICATION OF COMPUTERS
1. According to size
2. ACCORDING TO GENERATION
The history of computer development is often referred to in reference to the different generations of
computing devices. Each generation of computer is characterized by a major technological
development that fundamentally changed the way computers operate, resulting in increasingly
smaller, cheaper, more powerful, efficient and reliable devices.
1. Transistor technology
2. Assembly language
1. Networking
2. Fourth Generation Languages
3. Fifth Generation – Present and Beyond: Artificial Intelligence
Fifth generation computing devices, based on Artificial intelligence and Expert Systems, are still in
development, though there are some applications, such as voice recognition, that are being used
today. The use of parallel processing and superconductors is helping to make artificial intelligence a
reality. Quantum computation and molecular and nanotechnology will radically change the face of
computers in years to come. The goal of fifth-generation computing is to develop devices that
respond to natural language input and are capable of learning and self- organization.
1. ACCORDING TO PURPOSE
General purpose computers: These are designed to perform a range of tasks. They have the ability to
store numerous programs, but lack in speed and efficiency.
Specific purpose computers: These are designed to handle a specific problem or to perform a specific
task.
Hybrid computers : Hybrid Computers combine the features of both analog and digital
computers. They are mostly used in specialized applications where the input data is in an analog
form i.e. measurement. This is converted into digital form for further processing.
1. According to size
2. Super Computer
The fastest and most powerful type of computer Supercomputers are very expensive and are
employed for specialized applications that require immense amounts of mathematical calculations.
For example, weather forecasting requires a supercomputer. Other uses of supercomputers include
animated graphics, fluid dynamic calculations, nuclear energy research, and petroleum exploration.
1. Mainframe Computer
Main frame computers are very large computers which process data at very high speeds of the order
of several million instructions per second. They can be linked into a network with smaller computers,
microcomputers and with each other. They are typically used in large organizations, government
departments’ etc. ex. IBM4381, CDC
1. Mini Computer
A mid-sized computer in size and power, minicomputers lie between workstations and mainframes.
A minicomputer is a multiprocessing system capable of supporting from 4 to about 200 users
simultaneously. They are mainly used in applications like payrolls, financial accounting, Computer
aided design etc.
Microcomputers are generally referred to as Personal Computers (PCs). They have smallest memory
and less power. They are widely used in day to day applications like office automation, and
professional applications, ex. PCAT, Pentium etc
APPLICATIONS OF COMPUTERS
Today computers find widespread applications in all activities of the modern world. Some of the
major application areas include:
1. Scientific, Engineering and Research: This is the major area where computers find vast
applications. They are used in areas which require lot of experiments, mathematical calculations
weather forecasting, and complex mathematical and engineering applications. Computer Aided
Design (CAD) and Computer Aided Manufacturing (CAM) help in designing robotics,
automobile manufacturing, automatic process control devices etc.
2. Business: Record keeping, budgets, reports, inventory, payroll, invoicing, accounts are all the
areas of business and industry where computers are used to a great extent.
3. Medicine: Computerized systems are now in widespread use in monitoring patient data like,
pulse rate, blood pressure etc. resulting in faster and accurate diagnosis. Modern day medical
equipment are highly computerized today. Computers are also widely used in medical research.
4. Information: This is the age of information. Television, Satellite communication, Internet,
networks are all based on computers.
5. Education: The use of computers in education is increasing day by day. The students develop the
habit of thinking more logically and are able to formulate problem solving techniques. CDs on a
variety of subjects are available to impart education. Online training programs for students are
also becoming popular day by day. All the major encyclopedias, dictionaries and books are now
available in the digital form and therefore are easily accessible to the student of today.
6. Games and Entertainment: Computer games are popular with children and adults alike.
Computers are nowadays also used in entertainment areas like movies, sports, advertising etc.
COMPUTER MEMORY
Computer memory is any physical device capable of storing information temporarily or permanently.
Types of Memory
Primary memory is also called internal memory and is an important part of a computer. It is the main
area in a computer where the data is stored. The stored data can be recalled instantly and correctly
whenever desired. This memory can be quickly accessed by the CPU for reading or storing
information.
Primary memory is further classified into two types:
1. RAM: RAM is also known as read/write memory as information can be read from and written
onto it. RAM is a place in a computer that holds instructions for the computer, its programs and
the data. The CPU can directly access the data from RAM almost immediately. However, the
storage of data and instructions in RAM is temporary, till the time the computer is running. It
disappears from RAM as soon as the power to the computer is switched off. i.e it is volatile
memory.
2. ROM: It is called Read-only memory as information can only be read from and not written or
changed onto ROM. ROM is the “built-in” memory of a computer. It stores some basic input –
output instructions put by the manufacturer to operate the computer. The storage of data and
instructions in ROM is permanent. It does not depend on the power supply. i.e it is non-volatile
memory.
3. Secondary memory
The secondary memory is for massive storage of data. It is also referred as backup storage as it is
used to store large volume of data on a permanent basis which can be transferred to the primary
memory whenever required for processing. Some of the devices of secondary storages are Floppy
Disk, Hard Disk, CD-ROM, DVD and Flash drive.
UNITS OF MEMORY
The computer stores a character in the storage cells with binary (0,1) mechanism. Thus the basic unit
of memory is a bit (binary digit – 0,1). To store a character, a computer requires 8 bits or 1 byte. This is
called the word length the storage unit. Hence the storage capacity of the computer is measured in
the number of words it can store and is expressed in terms of bytes.
1. 8 Bits = 1 Byte
2. 4 Bits = 1 Nibble
INTRODUCTION TO PROGRAMMING
PROGRAMMING LANGUAGES
1. The high level languages are convenient for writing programs as they can be written without any
codes. These languages follow rules like – English language.
2. They are machine independent. A program written in any HLL can be run on computers of
different types without any modifications.
1. Problem Definition
2. Program Design
3. Coding
4. Testing
5. Debugging
6. Documentation
7. Maintenance
1. a) Problem Definition: Thorough understanding and identification of the problem for which a
program is to be written.
2. b) Program Design: Tools like algorithms and flowcharts are used to design the program. The
techniques employed in design are modular-programming, top-down design.
3. c) Coding: At this stage, the actual program is written using a computer language.
4. d) Debugging: Here the errors in the program are detected and corrected. e) Testing: A test plan
for the program which has been done at the design stage is applied here to test the program on a
number of suitable test cases.
5. f) Documentation: This stage ensures that further modifications, redesign and maintenance can be
made easy to the user who maintains the software.
6. g) Maintenance: Updating and correction of programs is covered in maintenance.
ALGORITHM
1. Uniqueness: results of each step are uniquely defined and only depend on the input and the result
of the preceding steps.
2. Finiteness: the algorithm stops after a finite number of instructions are executed.
3. Generality: the algorithm applies to a set of inputs.
Example
Solution:
Step 1: Start
Step 3: A= L X W
Step 5: Stop.
FLOWCHART
A flowchart is the graphical or pictorial representation of an algorithm with the help of different
symbols, shapes and arrows in order to demonstrate a process or a program. The main purpose of a
flowchart is to analyze different processes.
BASIC is an acronym for Beginners’ All-purpose Symbolic Instruction Code. BASIC is the name of a
high level programming language developed at Dartmouth College, New Hampshire USA under the
auspices of professors John G. Kemeny and Thomas E. Kurtz during their academic years- 1963-64.
The language was developed to teach beginners the basic construct s of programming theory and as
much, one of the easiest programming languages to learn.
As a high level programming language program code written in written in BASIC must be translated
to its equivalence in machine code before it can be executed on the computer.
Limited portability as different versions requires different interpreter for source code translation.
More than 50 versions of BASIC exist today as a result of variations in hardware systems. All these
variations are expected to conform to the universally accepted standard set out by American National
Standard Institute (ANSI).
Some of these versions are: ANSI BASIC, VISUAL BASIC, GW BASIC, QUICK BASIC, TURBO
BASIC, BASICA, MFBASIC, CASSETTE BASIC, APPLE BASIC etc.
Each statement must be preceded by a line number (or statement number or label) which must be an
integer.
Two statements cannot have the same line number.
Blank spaces can be inserted wherever desired to improved readability of the program. Each line
number must be followed by a BASIC keywords which indicates the type of instruction that is to be
carried out in the line. Successive statements must have increasing statement numbers. Although
these rules are relaxed in some versions of BASIC, programs written with adherence to these rules
remain valid.
1. Program heading
2. Variable/Constant Declaration
Program Statement
1. Terminal Statement
Example
Write a BASIC program to compute the area of a rectangle whose length is 10cm and its width is 8cm.
30 LET L=10
40 LET W=8
50 LET AREA=L X W
60 PRINT AREA
70 END PROGRAM
BASIC Keywords or reserved words: these are identifiers that have predefined meanings e.g . LET,
PRINT, END, INPUT,etc.
BASIC User-defined names : these are identifiers created by the programmers according to his needs
and following Basic rules for creating such e.g. NAME$, SCORES%, ”CATERORY A” etc.
There are two types of user defined names or identifiers in BASIC, namely: i. Variables
1. Constants.
Variables in BASIC
A variable is a name or identifier that represents number or a string of characters whose value can
change during or after the execution of a BASIC program.
1. Numeric Variables
2. String Variables
The rule is that every alphanumeric, that is string variable must end with the data-type symbol $.
When a variable name has no $ symbol after it, it is taken to be a numeric variable.
Constants in BASIC
A constant is an identifier, a number, a string of characters whose value cannot change during or after
the execution of a BASIC program.
Operations in BASIC
Arithmetic Operations
Arithmetic Operators are used to carry out arithmetic operations in BASIC. These operators are
executed according to precedence of rule i:e hierarchy
1. Exponentiation
2. Multiplication/Division
Addition/Subtraction
Algebraic Expression
Logical operations in BASIC involve the use of logical operators e.g NOT, AND, OR which must yield
logical values TRUE (T) or FALSE (F)
NOT-this logical operator has the highest precedence or priority over others. It affects only one
operand or variable at a time.
There could only be two possible combinations and outcomes as shown in the truth table below:
INPUT OUTPUT
T F
F T
AND – this is another logical operator that affects two variables at a time thus providing four
possible combinations as shown below:
FUNCTIONAL OPERATORS
Functional operators are inbuilt operators that the programmer can call or invoke from BASIC
functions library to solve some programming related problems instead of writing the code that will
solve such problems himself. Examples of such functions include: COS, SIN, ABS, SORT, TAN, SUM,
LEN, etc for cosine, sine, absolute, square root, tangent, summation, and word- length functions
respectively.
o
Example: Given that x = 45 , Develop a BASIC program that generate and display the sine, cosine
and Tan of x.
Solution
10 REM PROGRAM TO GENERATE AND DEVELOP THE SINE, COSINE AND TAN OF X
20 INPUT X
30 LET X = 45
70 PRINT P, Q, R
80 END
PROJECT
1. Develop an algorithm, flowchart and write a BASIC program to input the radius of the base of a
cone at the keyboard of a computer, calculate the base area, volume and output these values to the
screen of a monitor.
2. Develop an algorithm, flowchart and write a BASIC program to calculate the simple interest on
#20,000 at 5% per annum for 4 years.
C++ is a high-level programming language developed by Bjarne Stroustrup at Bell Labs. C++
adds object-oriented features to its predecessor, C. The main highlight of C++ is a collection of
predefined classes, which are data types that can be instantiated multiple times. The language also
facilitates declaration of user-defined classes. Classes can further accommodate member functions to
implement specific functionality. Multiple objects of a particular class can be defined to implement
the functions within the class. Objects can be defined as instances created at run time. These classes
can also be inherited by other new classes which take in the public and protected functionalities by
default.
C++ includes several operators such as comparison, arithmetic, bit manipulation and logical
operators.
#include <iostream>
int main()
cout<<“Hello World!”;
return 0;
1. #include <iostream>
2. using namespace std
3. ;
4. int main() { }
5. cout << “Hello World!”;
6. return 0;
1. #include <iostream>
This statement includes the header file into the application so that you are able to use the
operations included in them. Also, you can create your own header files and include them in your
program using the #include.
iostream
iostream is what you call the header file. It is a standard C++ input/output library file.
It comes packaged with the compiler/IDE coupled with mechanisms to get the information from the
user and print same or added information to a file, screen or any other media.
What is #include?
The #include iostream file, into the program. This ensures that now you’re able to use the
operations, iostream operations (like: taking input from user, displaying output on the screen), in the
program.
2. What is using namespace std;”?
The statement is intuitive in itself; you are “using” the “namespace” “std” in your file.
We use the namespace std to make it easier to reference operations included in that namespace.
If we hadn’t used the namespace, we’d have written std::coutinstead of cout. This tells the
compiler that every cout is actually std::cout.
What’s a namespace?
It’s a region where your code resides. It limits or expands the scope of your code to one or more
files.
Like two persons can have the same name, variables and functions in C++ can have same names as
well. The use of namespace is to avoid the confusion of which variables/functions you are
referencing to.
What is std?
std is a standard namespace used in C++.
3. Semicolon ”;”
The semicolon is a terminal. It terminates a statement. When missed or incorrectly used, it will
cause a lot of issues.
4. int main() { }
As the name suggests, it is the main function of the program. The code inside { } is called the body
and is executed first when you run your C++ program.
It is one code that is mandatory in a C++ program. If you just have this line of code alone, your
program will be valid.
5. cout << “Hello World!”;
This statement prints “Hello World!” onto the output screen.
The cout is an object of standard output stream. What this means is, it outputs/prints the data
after <<, i.e. Hello World! into a stream (in this case, the output screen).
What is a stream?
Stream is basically a sequence of objects, usually bytes. It can describe files, input/output terminal,
sockets, etc.
What is <<?
<< is the insertion operator used to write formatted data into the stream.
Being a general-purpose language, C++ is undoubtedly feature-rich. Going through all the features
will take you some time but, as a beginner, below are the most important features you should know.
1. C++ is fast
Since, C++ is an extended version of C, the C part of it is very low level.
This offers a huge boost in speed that high level languages like Python, Java don’t give you.
2. C++ is statically typed
C++ is a statically typed programming language.
In simple terms, C++ doesn’t allow the compiler to make assumptions about the type of data e.g.
10 is different from “10” and you have to let C++ know which one you are talking about.
3. C++ is a multi-paradigm programming language
C++ supports at least 7 different styles of programming and gives developers the freedom to
choose one at their will.
4. Object oriented programming with C++
Object oriented programming helps you solve a complex problem intuitively.
With its use in C++, you are able to divide these complex problems into smaller sets by creating
objects.
5. Power of standard library (Standard template library – STL)
The power of C++ extends with the use of standard libraries contained in it.
These libraries contain efficient algorithms that you use extensively while coding.
This saves ample amount of programming effort, which otherwise would have been
wasted reinventing the wheel.
Programs are a sequence of instructions or statements. These statements form the structure of a C++
program. C++ program structure is divided into various sections, namely, headers, class definition,
member functions definitions and main function.
Escape Sequences
Commonly used escape sequences are \n, \t and \a. The escape sequences are enclosed in single
quotes. \n is a new line character and helps in transferring control to the next line. If more than one
line is to be skipped, \n is repeated as many times as the number of lines to be skipped. \n can also
be combined with any other message string to be displayed. \t is used for giving tab and \a is used
for giving a beep.
cin and cout are two predefined objects which represent standard input and output stream. The
standard output stream represents the screen, while the standard input stream represents the
keyboard. These objects are members of iostream class. Hence the header file <iostream.h> should be
included in the beginning of all programs.
Comments in C++
C++ supports comment format which is indicated by a // sign before the comment. In this case, the
comment can proceed only till the end of current line. In case it is required to extend the comment
beyond the current line, the comments should be preceded by the // symbol on subsequent lines also.
Expressions in C++
Expression can be described as a combination of variables, constants and operators that represents a
computation forms an expression. Depending upon the type of operands involved in an expression or
the result obtained after evaluating expression, there are different categories of an expression.
In C++, input and output (I/O) operators are used to take input and display output. The operator used
for taking the input is known as the extraction or get from operator (>>), while the operator used for
displaying the output is known as the insertion or put to operator (<<).
Operators
Operators act on expressions to form a new expression. For example, we could replace “Hello,
world!\n” with (4 + 2) / 3, which would cause the program to print the number 2. In this case, the +
operator acts on the expressions 4 and 2 (its operands).
Operator types:
1. Mathematical: +, -, *, /, and parentheses have their usual mathematical meanings, including using
-for negation. % (the modulus operator) takes the remainder of two numbers: 6%5 evaluates to 1.
2. Logical: used for “AND,” “OR,” ” NOT, “NOR,” etc.
3. Bitwise: used to manipulate the binary representations of numbers.
Data Types
A data type determines the type and the operations that can be performed on the data. C++ provides
various data types and each data type is represented differently within the computer’s memory.
Tokens are the minimal chunk of programs that have meaning to the compiler –the smallest
meaningful symbols in the language. Our code displays all 6 kinds of tokens, though the usual use of
operators is not present here:
Blog at WordPress.com.