Você está na página 1de 29

Computer

Programming and
Numerical
Methods
Input-Output Devices

 Input device is a peripheral (piece of computer hardware


equipment) used to provide data and control signals to an
information processing system such as a computer or information
appliance. Examples of input devices include keyboards, mouse,
scanners, digital cameras and joysticks.
 An output device is any peripheral that receives data from a
computer, usually for display, projection, or physical reproduction.
For example, the image shows an inkjet printer, an output device
that can make a hard copy of any information shown on your
monitor. Another example of an output device is a computer
monitor, which displays an image that is received from the
computer. Monitors and printers are two of the most common
output devices used with a computer.
Storage Devices

 A data storage device is a device for recording (storing) information


(data)A storage device may hold information, process information,
or both.
 There are two types of storage devices used with computers: a
primary storage device, such as RAM, and a secondary storage
device, like a hard drive. Secondary storage can be removable,
internal, or external storage.
Secondary Storage Devices

 The secondary memory is used to store the data permanently in the


computer. The secondary storage devices are usually as follows:
hard disk drives – this is the most common type of storage device
that is used in almost all the computer systems. The other ones
include the floppy disk drives, the CD ROM, and the DVD ROM. The
flash memory, the USB data card etc.

 Floppy discs
 A floppy disk is a data storage medium that is composed of a disk of
thin, flexible floppy)magnetic storage medium encased in squarer
rectangular plastic shell. Floppy disks are read and written by a
floppy disk drive.
Hard Discs

 A hard disk drive is the device used to store large amounts of digital
information in computers and related equipment like iPods and
games consoles such as the Xbox 360 and PS3.
Hard disk drives are used to store operating systems, software and
working data.
These are suitable for any application which requires very fast
access to data for both reading and writing to. However, Hard disk
drives may not be suitable for applications which need portability.
Almost all computers used a fixed hard disc. Used for on-line and
real time processes requiring direct access. Used in file servers for
computer networks to store large amount of data.
Memory sticks/Pen drives

 USB flash drives are typically removable and rewritable, much


smaller than a floppy disk. Storage capacities typically range from
64 MB to 64 GB. USB flash drives offer potential advantages over
other portable storage devices, particularly the floppy disk.
They have a more compact shape, operate faster, hold much more
data, have a more durable design, and operate more reliably due
to their lack of moving parts. Flash drives are widely used to
transport files and backup data from computer to computer.
Optical backing storage media

 CDs tend to be used for large files (but smaller than 1Gb) which are too big for a
floppy disc to hold such as music and general animation.
 DVDs are used to hold very large files (several Gb) such as movie films. Both CDs and
DVDs are portable i.e. they can be transported from one computer to another. Both
can be used to store computer data.
 CD ROM/DVD ROM Applications which require the prevention of deletion of data,
accidental or otherwise. CDs used by software companies for distributing software
programs and data; by Music companies for distributing music albums and by book
publishers for distributing encyclopedias, reference books etc. DVDs used by film
distributors.
 CD R/DVD R Applications which require a single ‘burning’ of data, e.g. CDs -
recording of music downloads from the Internet, recording of music from MP3 format,
recording of data for archiving or backup purposes. DVDs – recording of film movies
and television programs.
 CD RW/DVD RW Applications which require the updating of information and ability to
record over old data. Not suitable for music recording but is very useful for keeping
generations of files. DVDs have between five and ten times the capacity of CDs.
Programming Language

 A programming language is a formal constructed language


designed to communicate instructions to a machine, particularly a
computer. Programming languages can be used to create
programs to control the behavior of a machine or to express
algorithms.
Computer Programming

 Computer programming (often shortened to programming) is a


process that leads from an original formulation of a computing
problem to executable computer programs. Programming involves
activities such as analysis, developing understanding, generating
algorithms, verification of requirements of algorithms including their
correctness and resources consumption, and implementation
(commonly referred to as coding of algorithms in a target
programming language. Source code is written in one or more
programming languages. The purpose of programming is to find a
sequence of instructions that will automate performing a specific
task or solving a given problem. The process of programming thus
often requires expertise in many different subjects, including
knowledge of the application domain, specialized algorithms and
formal logic
 There is only one programming language that any computer can
actually understand and execute: its own native binary machine
code. This is the lowest possible level of language in which it is
possible to write a computer program. All other languages are said
to be high level or low level according to how closely they can be
said to resemble machine code.
 In this context, a low-level language corresponds closely to
machine code, so that a single low-level language instruction
translates to a single machine-language instruction. A high-level
language instruction typically translates into a series of machine-
language instructions.
The Basics of a C++ Program

 A C++ program is a collection of one or more subprograms


(functions)
 Function
 Collection of statements
 Statements accomplish a task
 Every C++ program has a function called main
#include <iostream>
using namespace std;
int main()
{
cout<<"Welcome to C++ Programming"<<endl;
return 0;
}
Identifiers

 Identifiers are names for entities in a C program, such as variables, arrays,


functions, structures, unions and labels. An identifier can be composed only of
uppercase, lowercase letters, underscore and digits, but should start only with
an alphabet or an underscore.
 Identifiers are user defined
 Rules for constructing identifiers
1. The first character in an identifier must be an alphabet or an underscore
and can be followed only by any number alphabets, or digits or underscores.
2. They must not begin with a digit.
3. Uppercase and lowercase letters are distinct. That is, identifiers are case
sensitive.
4. Commas or blank spaces are not allowed within an identifier.
5. Keywords cannot be used as an identifier.
6. Identifiers should not be of length more than 31 characters.
7. Identifiers must be meaningful, short, quickly and easily typed and easily
read.
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 (<<).
Data-types

 Definition:
a set of values
 combined with a set of operations.
Data-types

 Simple data types include


 Integers
 Floating point
 Enumeration
 Integer data types include
char
short
int
long
Floating Point

 Stored using scientific notation


 the sign of the number,
 the significant digits of the number
 the sign of the power of 10
 the power of 10
Character Set

 Character set is the combination of English language alphabets


and math symbols the c++ program can understand.
Tokens

 A token is the smallest element of a C++ program that is meaningful


to the compiler. The C++ parser recognizes these kinds of tokens:
identifiers, keywords, literals, operators, punctuators, and other
separators. A stream of these tokens makes up a translation unit.
Operators

 An operator is a symbol that tells the compiler to perform specific


mathematical or logical manipulations. C++ is rich in built-in
operators and provides the following types of operators:
 Arithmetic Operators
 Relational Operators
 Logical Operators
 Bitwise Operators
 Assignment Operators
 Misc Operators
Arithmetic Operators
Operator Description Example
Adds two
+ A + B will give 30
operands
Subtracts
second
- A - B will give -10
operand
from the first
Multiplies
* both A * B will give 200
operands
Divides
numerator
/ B / A will give 2
by de-
numerator
Modulus
Operator
and
% remainder of B % A will give 0
after an
integer
division
Increment
operator,
++ increases A++ will give 11
integer value
by one
Decrement
operator,
-- decreases A-- will give 9
integer value
by one
Logical Operators
Operator Description Example

Called Logical
AND operator.
If both the
&& operands are (A && B) is false.
non-zero, then
condition
becomes true.

Called Logical
OR Operator. If
any of the two
|| operands is (A || B) is true.
non-zero, then
condition
becomes true.

Called Logical
NOT Operator.
Use to reverses
the logical
state of its
! operand. If a !(A && B) is true.
condition is
true, then
Logical NOT
operator will
make false.
Relational Operators
Operator Description Example
Checks if the values
of two operands are
== equal or not, if yes (A == B) is not true.
then condition
becomes true.
Checks if the values
of two operands are
equal or not, if values
!= (A != B) is true.
are not equal then
condition becomes
true.
Checks if the value of
left operand is
greater than the
> value of right (A > B) is not true.
operand, if yes then
condition becomes
true.
Checks if the value of
left operand is less
than the value of
< (A < B) is true.
right operand, if yes
then condition
becomes true.
Checks if the value of
left operand is
greater than or equal
>= to the value of right (A >= B) is not true.
operand, if yes then
condition becomes
true.
Checks if the value of
left operand is less
than or equal to the
<= value of right (A <= B) is true.
operand, if yes then
condition becomes
true.
Expressions

 An expression is composed of one or more operations.


 It is a valid combination of operators,constants and variables.
 They can be arithmetic, relational or compound expressions.
 The type of the expression is determined by the type of operators
used in it.
 Eg; int a,b,c;
c=a+b;
This is an eg for an arithmetic operator.
General form of a C++ program
If Statement

 An if statement is a 2 way bancing of a program segment.


 The simplest general form is
 If(expression)
{ statements ;
}
Eg: if(n%2==0)
{cout<<“even”;
}
If…else statement
 The if statement is followed by an optional else statement that
executes itself when the original condition becomes false.
 The general form is:
if(expression)
{ statements:
}
else{
statements;
}
Nested If statement

 Including an if statement in another if or else statement is called nested if


statement.
 Eg:
#include<iostream.h>
main()
{ int a;
cout<<“enter a value”;
cin>>a;
If(a==1)
cout<<“one”;
else if(a==2)
cout<<“two”;
}
Switch Statement

 A switch statement is a multi branching statement.


 Synatx:
Switch(expression)
{
case label_1 :statement;break;
case label_2 :statement;break;
case label_n :statement;break;
default: statement;
}

Você também pode gostar