Escolar Documentos
Profissional Documentos
Cultura Documentos
The control unit maintains order within the computer system and directs
the flow of traffic(operations) and data. The flow of control is indicated by the
dotted arrows on figure 1-1. The control unit selects one program statement
at a time from the program storage area, interprets the statement, and
sends the appropriate electronic impulses to the arithmetic-logic unit and
storage section to cause them to carry out the instruction. The control unit does
not perform the actual processing operations on the data. Specifically, the
control unit manages the operations of the CPU, be it a single-chip microprocessor or
a fill-size mainframe. Like a traffic director, it decides when to start and stop(control
and timing), what to do (program instructions),where to keep information
(memory), and with what devices to communicate (I/O). It controls the flow of all
data entering and leaving the computer. It accomplishes this by communicating
or interfacing with the arithmetic-logic unit, memory, and I/O areas. It
provides the computer with the ability to function under program control. Depending
on the design of the computer, the CPU can also have the capability to
function under manual control through man/machine interfacing. The control unit
consists of several basic logically defined areas. These logically defined areas work
closely with each other. Timing in a computer regulates the flow of signals that
control the operation of the computer. The instruction and control portion makes up
the decision-making and memory-type functions. Addressing is the process of
locating the operand(specific information) for a given operation. An interrupt
is a break in the normal flow of operation of a computer (e.g., CTRL + ALT + DEL).
Control memory is a random-access memory (RAM)consisting of addressable
storage registers. Cache memory is a small, high-speed RAM buffer located
between the CPU and main memory; it can increase the speed of the PC. Read-only
memory (ROM) are chips with a set of software instructions supplied by the
manufacturer built into them that enables the computer to perform its I/O operations.
The control unit is also capable of shutting down the computer when the power
supply detects abnormal conditions.
ARITHMETIC-LOGIC UNIT
Software Define
Software is a general term for the various kinds of programs used to operate
computers and related devices. (The term hardware describes the physical aspects of
computers and related devices.) Software is a generic term for programs that are used
by computers and other products that contain logic circuitry (i.e., embedded systems).
In a broader sense it can also refer to all information (i.e., both programs and data) in
electronic form, and it can provide a distinction from hardware, which refers to media
and systems on which software can exist and be used.
variable
In object-oriented programming , each object contains the data variables of the class it
is an instance of. The object's method s are designed to handle the actual values that
are supplied to the object when the object is being used.
ARRAYS
An array is data structure (type of memory layout) that stores a collection of individual
values that are of the same data type. Arrays are useful because instead of having to
separately store related information in different variables (named memory locations),
you can store them—as a collection—in just one variable. It is more efficient for a
program to access and process the information in an array, than it is to deal with many
separate variables.
All of the items placed into an array are automatically stored in adjacent memory
locations. As the program retrieves the value of each item (or "element") of an array, it
simply moves from one memory location to the very next—in a sequential manner. It
doesn't have to keep jumping around to widely scattered memory locations in order to
retrieve each item's value.
FUNCTIONS
ADVANTAGES:
*It reduces the Complexity in a program by reducing the code.
*It also reduces the Time to run a program.In other way,Its directly proportional to
Complexity.
*Its easy to find-out the errors due to the blocks made as function definition outside
the main function.
POINTER
Call by value:
We have seen that a function is invoked there will be a link established between the
formal and actual parameters. A temporary storage is created where the value of
actual parameters is stored. The formal parameters picks up its value from storage
area the mechanism of data transfer between actual and formal parameters allows the
actual parameters mechanism of data transfer is referred as call by value. The
corresponding formal parameter represents a local variable in the called function. The
current value of corresponding actual parameter becomes the initial value of formal
parameter. The value of formal parameter may be changed in the body of the actual
parameter. The value of formal parameter may be changed in the body of the
subprogram by assignment or input statements.
fncn(p,q)
int p,q;
{
p=p+p;
q=q+q;
}
Call by Reference:
When we pass address to a function the parameters receiving the address should be
pointers. The process of calling a function by using pointers to pass the address of the
variable is known as call by reference. The function which is called by reference can
change the values of the variable used in the call.
/* Include <stdio.h>
void main()
{
int x,y;
x=20;
y=30;
printf(“n Value of a and b before function call =%d %d”,a,b);
fncn(&x,&y);
printf(“n Value of a and b after function call =%d %d”,a,b);
}
fncn(p,q)
int p,q;
{
*p=*p+*p;
*q=*q+*q;
}
Introducing to C structure
In some programming contexts, you need to access multiple data types under a single
name for easier data manipulation; for example you want to refer to address with
multiple data like house number, street, zip code, country. C supports structure which
allows you to wrap one or more variables with different data types. A structure can
contain any valid data types like int, char, float even arrays or even other structures.
Each variable in structure is called a structure member.
Defining structure
To define a structure, you use struct keyword. Here is the common syntax of structure
definition:
struct struct_name{ structure_member };
The name of structure follows the rule of variable name. Here is an example of
defining address structure:
struct address{
char street_name
[50];
int zip_code;
char country[
50];
};
The address structure contains house number as an positive integer, street name as a
string, zip code as an integer and country as a string.
Declaring structure
The above example only defines an address structure without creating any structure
instance. To create or declare a structure instance, you can do it in two ways:
The first way is to declare a structure followed by structure definition like this :
struct struct_nam
e{
structure_mem
ber;
...
} instance_1,instance_2
instance_n;
In the second way, you can declare the structure instance at a different location in
your source code after structure definition. Here is structure declaration syntax :
struct struct_name instance_1,instance_2
1
instance_n;
Opening a file
Before we perform any operations on a file, we need to identify the file to the system
and open it. We do this by using a file pointer. The type FILE defined in stdio.h allows
us to define a file pointer.Then you use the function fopen() for opening a file. Once
this is done one can read or write to the file using the fread() or fwrite() functions,
respectively. The fclose() function is used to explicitly close any opened file.
Taking the preceding statements into account let us look at the following example
program :
Program 13.1
#include
main ()
{
FILE *fp;
fp = fopen("data.txt", "r")
if (fp == NULL) {
printf("File does not exist,
please check!\n");
}
fclose(fp);
}
fopen()
Let us first discuss fopen(). This function accepts two arguments as strings. The first
argument denotes the name of the file to be opened and the second signifies the
mode in which the file is to be opened. The second argument can be any of the
following:
fclose()
The fclose() function is used for closing opened files. The only argument it accepts is
the file pointer.
The functions fprintf() and fscanf() are similar to printf() and scanf() except that these
functions operate on files and require one additional and first argument to be a file
pointer.
Program 13.2
#include
main ()
{
FILE *fp;
float total;
fp = fopen("data.txt", "w+")
if (fp == NULL) {
printf("data.txt does not exist, please check!\n");
exit (1);
}
fprintf(fp, 100);
fscanf(fp, "%f", &total);
fclose(fp);
printf("Value of total is %f\n", total);
}
The functions getc() and putc() are equivalent to getchar() and putchar() functions
which you studied in Chapter 12 on Input and Output, except that these functions
require an argument which is the file pointer. Function getc() reads a single character
from the file which has previously been opened using a function
like fopen(). Function putc() does the opposite, it writes a character to the file
identified by its second argument. The format of both functions is as follows :
getc(in_file);
putc(c, out_file);
Note: The second argument in the putc() function must be a file opened in either write
or append mode.
#include
main ()
{
char in_file[30], out_file[30];
FILE *fpin, *fpout;
int c;
printf("This program copies the source file to the destination file
\n\n");
printf("Enter name of the source file :");
scanf("%30s", in_file);
printf("Enter name of the destination file :");
scanf("%30s", out_file);
if((fpin=fopen(in_file, "r")) == NULL)
printf("Error could not open source file for
reading\n");
else if ((fpout=fopen(out_file, "w")) == NULL)
printf("Error could not open destination file for
reading\n");
else
{
while((c =getc(fpin)) != EOF)
putc(c, fpout);
printf("Destination file has been copied\n");
}
}
The functions fread() and fwrite() are a somwhat complex file handling functions used
for reading or writing chunks of data containing NULL charactesr ('\0') terminating
strings.
You may notice that the return type of fread() is size_t which is the number of items
read. You will understand this once you understand how fread() works. It
reads n items, each of size sz from a file pointed to by the pointer fp into a buffer
pointed by a void pointer ptr which is nothing but a generic pointer.
Function fread() reads it as a stream of bytes and advances the file pointer by the
number of bytes read. If it encounters an error or end-of-file, it returns a zero, you
have to use feof() or ferror() to distinguish between these two. Function fwrite() works
similarly, it writes n objects of sz bytes long from a file pointed to by fp to a location
pointed to by ptr, and returns the number of items written to fp.
GENERATIONS OF COMPUTERS
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 and more efficient
and reliable devices. Read about each generation and the developments that led to
the current devices that we use today.
Follow the steps below to make working with multiple sheet a piece of cake and you
will be on your way to becoming a power user!
•
Hold down theCTRL key as you click each tab top select multiple worksheets.
•
To select a contiguous group of worksheets, click the first one in the group and then
hold down theShift key and click the last one in the group.
•
To select all the worksheets in the current workbook, right-click any worksheet tab and
choose Select All Sheets from the shortcut menu.
•
To quickly make any sheet active, click its index tab; to remove a sheet from a
selected group of sheets, hold downCTRL and click its tab.
•
To remove the multiple selection and resume working with a single sheet, click any
unselected sheet. If you have selected every sheet in the workbook, right-click any
worksheet tab and choose Ungroup Sheets.
•
If you have selected more than one sheet, you see the word Group in brackets in the
title boar, and any data you enter appears in the corresponding cells on each
worksheet in the group. So, if you have grouped Sheet1, Sheet2 and Sheet3, entering
text in cellA1 on Sheet1 also enters the same text in
the corresponding cells on Sheet2 and Sheet3.
•
Any choices you make such as applying a number format, affect all the grouped
worksheets identically. If you are building a workbook with identically formatted
sheets, you can use these
techniques to quickly enter category headings, etc. along the top of each sheet.
You cannot use the Clipboard to enter data into multiple sheets concurrently. When
you paste data, it only appears in the active sheet and not in any other sheets you
have selected.
STRUCTURES
Arrays are used to store large set of data and manipulate them but the disadvantage
is that all the elements stored in an array are to be of the same data type. If we need
to use a collection of different data type items it is not possible using an array. When
we require using a collection of different data items of different data types we can use
a structure. Structure is a method of packing data of different types. A structure is a
convenient method of handling a group of related data items of different data types.
These above listed function broadly fall into two categories, the one which deal with a
single character and the second which deal with a string of characters.
Explanations :
getch() : This function will read a single character the instant it is typed by
programmer without waiting for the Enter Key to be hit. The typed character is not
echoed on screen.
getche() : This function will also read a single character the instant it is typed by
programmer without waiting for the Enter key to be hit, just like getch() function. The
additional character 'e' in function getch() echoes the character on screen that you
typed. This is a point of differences between getch() & getche().
getchar() : It works similar to that of getch() and also echoes the character you typed
on the screen but it also requires enter key to be hit immediately after the character
that you typed. It is a macro.
fgetchar() : It will echo the character on screen and it requires hit of Enter key
immediately following the character. The only difference between getchar() and
fgetchar() is that the former is a macro and latter is function.
(Note : putch(), putchar() and fputchar() can output only one character at a time on
screen.)
gets() : It gets a string from the keyboard and it is necessary on programmers part to
terminates that string with an Enter key. That's why spaces and tabs are acceptable as
a part of the input string if any gets() is used to read only one string at a time.
puts() : It outputs a string to the screen puts() can outputs only one string at a time.
That means that, for example, we can store 5 values of type int in an array without
having to declare 5 different variables, each one with a different identifier. Instead of
that, using an array we can store 5 different values of the same type, int for example,
with a unique identifier.
For example, an array to contain 5 integer values of type int called billy could be
represented like this:
where each blank panel represents an element of the array, that in this case are
integer values of type int. These elements are numbered from 0 to 4 since in arrays
the first index is always 0, independently of its length.
Therefore, in order to declare an array called billy as the one shown in the above
diagram it is as simple as:
int billy
[5];
NOTE: The elements field within brackets [] which represents the number of elements
the array is going to hold, must be a constant value, since arrays are blocks of non-
dynamic memory whose size must be determined before execution. In order to create
arrays with a variable length dynamic memory is needed, which is explained later in
these tutorials.
Initializing arrays.
When declaring a regular array of local scope (within a function, for example), if we do
not specify otherwise, its elements will not be initialized to any value by default, so
their content will be undetermined until we store some value in them. The elements of
global and static arrays, on the other hand, are automatically initialized with their
default values, which for all fundamental types this means they are filled with zeros.
In both cases, local and global, when we declare an array, we have the possibility to
assign initial values to each one of its elements by enclosing the values in braces { }.
For example:
The amount of values between braces { } must not be larger than the number of
elements that we declare for the array between square brackets [ ]. For example, in
the example of array billy we have declared that it has 5 elements and in the list of
initial values within braces { } we have specified 5 values, one for each element.
When an initialization of values is provided for an array, C++ allows the possibility of
leaving the square brackets empty [ ]. In this case, the compiler will assume a size for
the array that matches the number of values included between braces { }:
int billy [] = { 16, 2, 77, 40,
12071 };
After this declaration, array billy would be 5 ints long, since we have provided 5
initialization values.
In any point of a program in which an array is visible, we can access the value of any
of its elements individually as if it was a normal variable, thus being able to both read
and modify its value. The format is as simple as:
name[index]
Following the previous examples in which billy had 5 elements and each of those
elements was of type int, the name which we can use to refer to each element is the
following:
For example, to store the value 75 in the third element of billy, we could write the
following statement:
billy[2] =
75;
and, for example, to pass the value of the third element of billy to a variable called a,
we could write:
a=
billy[2];
Therefore, the expression billy[2] is for all purposes like a variable of type int.
Notice that the third element of billy is specified billy[2], since the first one is billy[0],
the second one is billy[1], and therefore, the third one is billy[2]. By this same reason,
its last element is billy[4]. Therefore, if we write billy[5], we would be accessing the
sixth element of billy and therefore exceeding the size of the array.
In C++ it is syntactically correct to exceed the valid range of indices for an array. This
can create problems, since accessing out-of-range elements do not cause compilation
errors but can cause runtime errors. The reason why this is allowed will be seen
further ahead when we begin to use pointers.
At this point it is important to be able to clearly distinguish between the two uses that
brackets [ ] have related to arrays. They perform two different tasks: one is to specify
the size of arrays when they are declared; and the second one is to specify indices for
concrete array elements. Do not confuse these two possible uses of brackets[ ] with
arrays.
If you read carefully, you will see that a type specifier always precedes a variable or
array declaration, while it never precedes an access.
1 billy[0] = a;
2 billy[a] = 75;
3 b = billy [a+2];
billy[billy[a]] = billy[2]
4
+ 5;
jimmy represents a bidimensional array of 3 per 5 elements of type int. The way to
declare this array in C++ would be:
and, for example, the way to reference the second element vertically and fourth
horizontally in an expression would be:
jimmy[1]
[3]
Multidimensional arrays are not limited to two indices (i.e., two dimensions). They can
contain as many indices as needed. But be careful! The amount of memory needed for
an array rapidly increases with each dimension. For example:
declares an array with a char element for each second in a century, that is more than
3 billion chars. So this declaration would consume more than 3 gigabytes of memory!
Multidimensional arrays are just an abstraction for programmers, since we can obtain
the same results with a simple array just by putting a factor between its indices:
#define WIDTH 5
#define HEIGHT 3
#define WIDTH 5
#define HEIGHT 3
int jimmy [HEIGHT]
[WIDTH];
int jimmy [HEIGHT * WIDTH];
int n,m;
int n,m;
int main ()
int main ()
{
{
for (n=0;n<HEIGHT;n+
for (n=0;n<HEIGHT;n++)
+)
for (m=0;m<WIDTH;m++)
for
{
(m=0;m<WIDTH;m++)
jimmy[n*WIDTH+m]=(n+1)*
{
(m+1);
jimmy[n]
}
[m]=(n+1)*(m+1);
return 0;
}
}
return 0;
}
MAIL MERGE
In any working environment, there are situations when a similar type of letter or
document is to be sent to many persons who reside at different locations. The letters
may contain the address of each recipient, in addition to the standard information
contained in the letter. One way of doing this is to print the letters by changing the
address each time in the document after printing such letter. But this would mean lot
of effort and time and also results in bad organisation.
Such problems are taken care of by the Mail Merge facility. In word processing, Mail
Merge is the process of transferring selected information from one document to
another document.
Data for all the individuals, for whom the letters are to be generated also called data
source
Mail Merge option of Word reads this data and physically merges it with Main
document to generate letters for all the persons or for all records in the data file
PDLC includes various set of procedures and activitiesthat are isolated and sequenced
for learning purposesbut in real life they overlap and are highly interrelated
Phase 4 represents the time when the solution to the problem, the programs or
system, is constructed.
Phase 5 is a critical time but can be minimised if the previous steps are correct.
Phase 6, the maintenance phase, is the time when the solution is in active use. It may
undergo enhancements or it may have bugs fixed during its lifetime.
There is a strong connection between phases 2 and 3 since the process of designing a
solution to a problem is an iterative process and often involves a great deal of
discovery. For example as you refine an algorithm you might discover that there are
variables and/or processes that weren't obvious during phase 2. This is to be expected,
after all you are just learning about this kind of thing, but you can expect to meet this
kind of discovery right throughout your life as a program designer.
New - Opens a new document. If you use the keyboard combination indic
the right a blank document opens immediately. Selecting the New menu
with your cursor gives the opportunity to open a large number of types of
documents.
Open - Opens a previously saved document.
Close - Closes the active document but does not quit the
application.
Save - Saves the active document with its current file name,
location and format.
Save As - Saves by opening a window which gives the opportunity
to change the file name, location or format.
Page Setup - Sets margins, paper size, orientation and other layout
options.
Print Preview - Shows how the file will look when you print it.
Print - Prints the active file, also gives the opportunity to change
print options
Edit menu
View menu
Insert menu
Format menu
Tools menu
Window menu
To use one of these combinations Hold the Ctrl or Alt key down and strike the letter
key
Ctrl+N Ctrl+X Cut- Removes the selection
Open a new word document from the active document
quickly. and places it on the
clipboard.
Ctrl+O Opens a previously Ctrl+C Copies the selection to the
saved document. clipboard
Ctrl+P Prints the active file, also Ctrl+F Find - Searches for
gives the opportunity to specified text in the active
change print options document
When working with a stream - oriented data file, the first step to establish a buffer
area, where information is temporarily stored while being transferred between
computers memory and the data file. The buffer area is established by writing
Where, FILE is a special structure type that establishes the buffer area and pointer
variable indicates the beginning of buffer area. The FILE is defined in a, file "stdio.h".
A data file must then be opened before it can be created and processed. The library
function 'fopen' is used to open a file. The syntax of fopen is
where, filename is name of datafile which you wish to open and mode indicates the
mode in which this file will get open up. The modes in which the user can open a file
are :
Modes Meaning
The fopen function returns a pointer to the beginning of buffer area associated with
the file. A NULL value is returned if the file cannot be opened, for ex., when an existing
data file cannot be found.
A data file opened using fopen must be closed at the end of the program. A library
function fclose is used for this purpose.
The syntax for fclose is :
fclose (pointervar);
Some applications involved the use of data files to store block of data, where each
block consist of a fixed number of continuous bytes. Each block will generally
represent a complex data structure such as a structure or a array. For such
application, it may be desirable to read the entire block from the data file or write the
entire block to the data file, rather than reading and writing a individual component.
The library functions fread and fwrite are used for this purpose. These function are
often referred to as unformatted read & write functions. Similarly, data file of this type
are referred to as unformatted data file.
The binary numeral system, or base-2 number system, represents numeric values
using two symbols, 0 and 1. More specifically, the usual base-2system is a positional
notation with a radix of 2. Owing to its straightforward implementation in digital
electronic circuitry using logic gates, the binary system is used internally by all
modern computers.
Bits
The concept of a bit can be understood as a value of
either 1 or 0, on or off, yes or no, true or false, or encoded by a switch or toggle of
some kind. A single bit must represent one of twostates:
Bytes
A byte is often a computer's smallest addressable memory unit. In most computers
this is an ordered sequence of eight bits or binary digits that can represent one of 256
possible values. Most recent computers process information in 8-bit units, or some
other multiple thereof (such as 16, 32, or 64 bits) at a time. A group of 8 bits is now
widely used as a fundamental unit, and is generally called a 'byte' (or
sometimes octet).
[edit]Nibbles
A unit of four bits, or half an octet, is often called a nibble (or nybble). It can encode 16
different values, such as the numbers 0 to 15. Any arbitrary sequence of bits could be
used in principle, but in practice the most common scheme is:
This order (rather than gray code) is used because it is a positional notation, like
the decimal notation that humans are more used to. For example, given the decimal
number:
7531
is commonly interpreted as:
Java
C
Python
Scheme
Prolog
C++
C#
Java script
Lisp
Ruby
The "machine language" and "assembly language" for each CPU architecture are the
lowest-level programming languages.
The "Forth language" and the "C programming language" are perhaps the most
popular non-CPU-specific low-level programming languages. They were once
considered high-level programming languages, and certainly they are at a higher level
than assembly language, but now they are considered low-level programming
languages when compared to the much higher-level languages available today
(Python, Java, C++, etc).
Low-level programming languages provide little or no abstraction from the CPU's
instruction set architecture; typically they interact with the hardware directly.
This section demonstrates the use of fseek() function in C. This function sets the file
position indicator for the stream pointed to by stream or you can say it seeks a
specified place within a file and modify it.
Its syntax is: fseek(FILE *stream, long int offset, int whence)
Ftell function
<cstdio>
A compiler, in general, reads higher level language computer code and converts it to
either p-code or native machine code. An interpreter runs directly from p-code or an
interpreted code such as Basic or Lisp. Typically, compled code runs much faster, is
more compact and has already found all of the syntax errors and many of the illegal
reference errors. Interpreted code only finds such errors after the application attempts
to interpret the affected code. Interpreted code is often good for simple applications
that will only be used once or at most a couple times, or maybe even for prototyping.
Compiled code is better for serious applications. A compiler first takes in the entire
program, checks for errors, compiles it and then executes it. Whereas, an interpreter
does this line by line, so it takes one line, checks it for errors and then executes it.
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.
Low-level languages have the advantage that they can be written to take
advantage of any peculiarities in the architecture of the central processing unit
(CPU) which is the "brain" of any computer. Thus, a program written in a low-level
language can be extremely efficient, making optimum use of both computer
memory and processing time. However, to write a low-level program takes a
substantial amount of time, as well as a clear understanding of the inner workings
of the processor itself. Therefore, low-level programming is typically used only for
very small programs, or for segments of code that are highly critical and must run
as efficiently as possible.
The very lowest possible level at which you can program a computer is in
its own native machine code, consisting of strings of 1's and 0's and stored
as binary numbers. The main problems with using machine code directly are
that it is very easy to make a mistake, and very hard to find it once you
realize the mistake has been made.
Assembly Language
Compiler Language
Typically, the compiled machine code is less efficient than the code
produced when using assembly language. This means that it runs a bit more
slowly and uses a bit more memory than the equivalent assembled program.
To offset this drawback, however, we also have the fact that it takes much
less time to develop a compiler-language program, so it can be ready to go
sooner than the assembly-language program.
Interpreter Language
On the down side, this arrangement requires that both the interpreter and
the user's program reside in memory at the same time. In addition, because
the interpreter has to scan the user's program one line at a time and execute
internal portions of itself in response, execution of an interpreted program is
much slower than for a compiled program.