Você está na página 1de 32

CONTROL UNIT

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

The arithmetic-logic unit (ALU) performs all arithmetic operations (addition,


subtraction, multiplication , and division) and logic operations. Logic
operations test various conditions encountered during processing and allow for
different actions to betaken based on the results. The data required to perform the
arithmetic and logical functions are inputs from the designated CPU registers and
operands. The ALU relies on basic items to perform its operations . These
include number systems, data routing circuits (adders/sub tracters), timing,
instructions, operands, and registers. Figure 1-2 shows are presentative block
diagram of an ALU of a micro computer. PRIMARY STORAGE (MAIN
MEMORY)The primary storage section (also called internal storage, main storage,
main memory, or just memory)serves four purposes:. To hold data transferred from
an I/O device to the input storage area, where it remains until the computer is ready
to process it. This is indicated by the solid arrow on figure 1-1.. To hold both the
data being processed and the intermediate results of the arithmetic- logic
operations . This is a working storage area within the storage section. It is
sometimes referred to as a scratch pad memory.. To hold the processing results
in an output storage area for transfer to an I/O device.

Figure 1-2.—Representative block diagram of an ALU.

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 programming, a variable is a value that can change, depending on conditions or on


information passed to the program. Typically, a program consists of instruction s that
tell the computer what to do and data that the program uses when it is running. The
data consists of constants or fixed values that never change and variable values
(which are usually initialized to "0" or some default value because the actual values
will be supplied by a program's user). Usually, both constants and variables are
defined as certain data type s. Each data type prescribes and limits the form of the
data. Examples of data types include: an integer expressed as a decimal number, or a
string of text characters, usually limited in length.

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

"Less code,more work" shows the performance/standard of the program.

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

In C language, a pointer is a variable that points to or references a memory location in


which data is stored. Each memory cell in the computer has an address which can be
used to access its location. A pointer variable points to a memory location. By making
use of pointer, we can access and change the contents of the memory location.
Pointer declaration:
A pointer variable contains the memory location of another variable. You begin the
declaration of a pointer by specifying the type of data stored in the location identified
by the pointer. The asterisk tells the compiler that you are creating a pointer variable.
Finally you give the name of the pointer variable. The pointer declaration syntax is as
shown below.
type * variable name
Example:
int *ptr;
float *string;
Pointers and function:
The pointer are very much used in a function declaration. Sometimes only with a
pointer a complex function can be easily represented and success. The usage of the
pointers in a function definition may be classified into two groups.
1. Call by reference
2. Call by value.

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.

This will not change the value of actual parameters.


/* 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;
}

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.

/* example of call by reference*?

/* 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{

unsigned int house_nu


mber;

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;

FILE HANDLEING FUNCTION IN C

In any programming language it is vital to learn file handling techniques. Many


applications will at some point involve accessing folders and files on the hard drive. In
C, a stream is associated with a file. Special functions have been designed for handling
file operations. Some of them will be discussed in this chapter. The header file stdio.h
is required for using these functions.

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:

File Mode Description

r Open a text file for reading

Create a text file for writing, if it exists, it is


w
overwritten.

Open a text file and append text to the end of the


a
file.

rb Open a binary file for reading

Create a binary file for writing, if it exists, it is


wb
overwritten.

Open a binary file and append data to the end of the


ab
file.

fclose()

The fclose() function is used for closing opened files. The only argument it accepts is
the file pointer.

If a program terminates, it automatically closes all opened files. But it is a good


programming habit to close any file once it is no longer needed. This helps in better
utilization of system resources, and is very useful when you are working on numerous
files simultaneously. Some operating systems place a limit on the number of files that
can be open at any given point in time.
fscanf() and fprintf()

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);
}

getc() and putc()

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");
}
}

Binary stream input and output

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.

The function prototype of fread() and fwrite() is as below :

size_t fread(void *ptr, size_t sz, size_t n, FILE *fp)


size_t fwrite(const void *ptr, size_t sz, size_t n, File *fp);

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.

First Generation (1940-1956) Vacuum Tubes


The first computers used vacuum tubes for circuitry and magnetic drums for memory,
and were often enormous, taking up entire rooms. They were very expensive to
operate and in addition to using a great deal of electricity, generated a lot of heat,
which was often the cause of malfunctions.
First generation computers relied on machine language, the lowest-level programming
language understood by computers, to perform operations, and they could only solve
one problem at a time. Input was based on punched cards and paper tape, and output
was displayed on printouts.
The UNIVAC and ENIAC computers are examples of first-generation computing devices.
The UNIVAC was the first commercial computer delivered to a business client, the U.S.
Census Bureau in 1951.

Second Generation (1956-1963) Transistors


Transistors replaced vacuum tubes and ushered in the second generation of
computers. The transistor was invented in 1947 but did not see widespread use in
computers until the late 1950s. The transistor was far superior to the vacuum tube,
allowing computers to become smaller, faster, cheaper, more energy-efficient and
more reliable than their first-generation predecessors. Though the transistor still
generated a great deal of heat that subjected the computer to damage, it was a vast
improvement over the vacuum tube. Second-generation computers still relied on
punched cards for input and printouts for output.
Second-generation computers moved from cryptic binary machine language to
symbolic, or assembly, languages, which allowed programmers to specify instructions
in words. High-level programming languages were also being developed at this time,
such as early versions of COBOL and FORTRAN. These were also the first computers
that stored their instructions in their memory, which moved from a magnetic drum to
magnetic core technology.
The first computers of this generation were developed for the atomic energy industry.
Third Generation (1964-1971) Integrated Circuits
The development of the integrated circuit was the hallmark of the third generation of
computers. Transistors were miniaturized and placed on silicon chips,
called semiconductors, which drastically increased the speed and efficiency of
computers.
Instead of punched cards and printouts, users interacted with third generation
computers through keyboards and monitorsand interfaced with an operating system,
which allowed the device to run many different applications at one time with a central
program that monitored the memory. Computers for the first time became accessible
to a mass audience because they were smaller and cheaper than their predecessors.

Fourth Generation (1971-Present) Microprocessors


The microprocessor brought the fourth generation of computers, as thousands of
integrated circuits were built onto a single silicon chip. What in the first generation
filled an entire room could now fit in the palm of the hand. The Intel 4004 chip,
developed in 1971, located all the components of the computer—from the central
processing unit and memory to input/output controls—on a single chip.
In 1981 IBM introduced its first computer for the home user, and in
1984 Apple introduced the Macintosh. Microprocessors also moved out of the realm of
desktop computers and into many areas of life as more and more everyday products
began to use microprocessors.
As these small computers became more powerful, they could be linked together to
form networks, which eventually led to the development of the Internet. Fourth
generation computers also saw the development of GUIs,
the mouse and handhelddevices.

Fifth Generation (Present and Beyond) Artificial Intelligence


Fifth generation computing devices, based on artificial intelligence, 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.

WORKING WITH MULTIPLS SHEETS AND PRINTIR WORKSHEETS

Working with Multiple Worksheets in MS Excel 2007


Working with multiply sheets concurrently is how MS Excel power users create and
format a complex workbook with the least amount of effort expended.

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.

Unformatted console I/O functions.

The functions under this category are :


getch() putch() gets()
getche() putchar() puts()
getchar() fputchar()
fgetchar()

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.

putch() : It writes a character to the screen.

putchar() : It writes a character to the screen and is a macro.

fputchar() : It writes a character to the screen (function version).

(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.

Arrays and multidimensional arrays


Arrays
An array is a series of elements of the same type placed in contiguous memory
locations that can be individually referenced by adding an index to a unique identifier.

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.

Like a regular variable, an array must be declared before it is used. A typical


declaration for an array in C++ is:

type name [elements];


where type is a valid type (like int, float...), name is a valid identifier and
the elements field (which is always enclosed in square brackets []), specifies how
many of these elements the array has to contain.

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:

int billy [5] = { 16, 2, 77, 40,


12071 };

This declaration would have created an array like this:

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.

Accessing the values of an array.

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.

1 int billy[5]; // declaration of a new array


2 billy[2] = 75; // access to an element of
the array.

If you read carefully, you will see that a type specifier always precedes a variable or
array declaration, while it never precedes an access.

Some other valid operations with arrays:

1 billy[0] = a;
2 billy[a] = 75;
3 b = billy [a+2];
billy[billy[a]] = billy[2]
4
+ 5;

1 // arrays example 12206


2 #include <iostream>
3 using namespace std;
4 int billy [] = {16, 2, 77, 40, 12071};
5 int n, result=0;
6
7 int main ()
8{
for ( n=0 ; n<5 ; n++ )
9 {
10 result += billy[n];
11 }
12 cout << result;
13 return 0;
14 }
15
16
Multidimensional arrays

Multidimensional arrays can be described as "arrays of arrays". For example, a


bidimensional array can be imagined as a bidimensional table made of elements, all of
them of a same uniform data type.

jimmy represents a bidimensional array of 3 per 5 elements of type int. The way to
declare this array in C++ would be:

int jimmy [3]


[5];

and, for example, the way to reference the second element vertically and fourth
horizontally in an expression would be:

jimmy[1]
[3]

(remember that array indices always begin by zero).

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:

char century [100][365][24][60]


[60];

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:

1 int jimmy [3][5]; // is


2 equivalent to
int jimmy [15]; // (3 * 5 =
15)
With the only difference that with multidimensional arrays the compiler remembers
the depth of each imaginary dimension for us. Take as example these two pieces of
code, with both exactly the same result. One uses a bidimensional array and the other
one uses a simple array:

multidimensional array pseudo-multidimensional array

#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.

13.4 CONCEPT OF MAIL MERGING AND ITS COMPONENTS


• Mail Merge is the facility which requires the following three information
• General body of the letter called main document
• Header Row, the record structure or the name of the fields, which will identify
the data

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

PROGRAM DEVELOPMENT LIFE CYCLE

Program Development Life Cycle


The process of developing a software, according to the desired needs of a user, by
following a basic set of interrelated procedures is known as Program Development Life
Cycle.

PDLC includes various set of procedures and activitiesthat are isolated and sequenced
for learning purposesbut in real life they overlap and are highly interrelated

Tasks of Program Development


The basic set of procedures that are followed by various organisations in their program
development methods are as follows:
1.Problem Definition
2.Program Design
3.Coding
4.Debugging
5.Testing
6.Documentation
7.Maintenance
8.Extension and Redesign
A program may result from some problem, in this case problem means some task
requiring a solution, or from a bright idea, or because it is a project which has been set
for student. No matter what their first causes computer programs, aka software, and
software systems, collections of softwares, have quite well-defined life cycles. The
need for a program is recognised, the requirements are analysed, a possible solution is
designed, the prototype is built and tested, and finally the program is put into
use. Figure 1 shows the typical life-cycle for
a computer program.

During phase one the emphasis is on fact-


gathering and determining where the
boundaries of the problem are.

Phase two involves the steps of identifying


the variables and processes which make up
the problem.

Phase 3 is where you will use the tools and


techniques that you learn in this module.
During this phase the strategies which will
solve the problem are developed.

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.

Using Microsoft Word's Menu bar


File menu

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

Exit - Closes Microsoft Word.

Edit menu

View menu

Insert menu

Format menu
Tools menu

Spelling and Grammar - Choose either


sub-menu and the same window opens.
Questioned spelling is in red, grammar
in green.
Language/Thesaurus - Have you used the
word "like" too many times? Highlight the
word, select Thesaurus and get
suggestions like similar and analogous.
Word Count - Need to know how many
words are in your document? Select Word
Count and find out how many pages,
words, characters, paragraphs, and lines.
Auto Summarize - Exactly what it sounds
like, Word summarizes the document,
reducing the length of the document,
keeping the meaning.
Auto Correct - Word will automatically
correct some things. If this feature is
irritating to you, come here to change
what is corrected.
Customize- Opens the same window that
you get by going to the View menu and
selecting Toolbar/Customize.
Options - Modify Word settings here.
Modify print, editing, spelling and other
options from this sub-menu.

Window menu

New Window - This opens another window with


a copy of the active document.
Arrange All - Displays all open files in the
window. This makes dragging and dropping
from one document to another much easier.
Split - Splits the active window into panes.
Open Document List - There is no need to drag
windows to the side so you can see other
documents open in Word. Come to the bottom
of this window for a listing of all open
documents. The active document has a check
mark beside it.
Help menu

Microsoft Word Help - Open Word's Assistant


and get a search box to type in. Word displays
possible matches for you to read about.
Contents and Index - See an index of all topics
available in Word's Help documentation.
Microsoft on the Web - That's right! It is
exactly what it sounds like. Select a link and a
Microsoft help page is opened in your browser.
If you are not online, Word will make the
connection and then display the page.
About Microsoft Word - Not sure which version
of Word you working with. Check here for
version information and for the produce ID
number.

Commonly used keyboard combinations

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+W Ctrl+V Paste - Inserts the contents


Closes the active window, of the clipboard at the
but does not Exit Word. insertion point (cursor) or
whatever is selected.
Ctrl+S Saves the active document Ctrl+A Selects all text and
with its current file name, graphics in the active
location and format. window.

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

Alt+F4 Ctrl+B Bold - Formats selected


Exit - Closes Microsoft Word. text; make text bold, or
remove bold formatting
Ctrl+Z Undo the last action. This Ctrl+I Italic - Formats selected
selection can be repeated text; make text italic or
several times. remove italic

Ctrl+Y Redo - After an action has Ctrl+U Underline - Formats


selected text; make text
been undone, it can be
underlined or remove
reinstated in the document.
underline

Less commonly used keyboard combinations


Increase selected text Apply superscript
two points formatting
Decrease selected Apply subscript
text two points formatting
Increase selected text
Copy formats
one point
Decrease selected
Paste formats
text one point
Change case of the
Single space lines
letters
Underline words but
Set 1.5 line spacing
not spaces
Double underline text Double space lines
Delete one word to the
Center a paragraph
left
Delete one word to the
Justify a paragraph
right
Right align a
Left align a paragraph
paragraph
Indent a paragraph
Insert a line break
from the left
Create a hanging Reduce a hanging
indent indent
If text is already selected and you want to extend the selection area
Extend selection one Extend selection one
character to the left character to the right
Extend selection to Extend selection to the
the end of a word beginning of a word
If you want to move the cursor
One character to the One character to the
right left
One word to the right One word to the left

OPENING AND CLOSING OF DATA FILE IN C


Many applications require that information be written or read from an auxiliary storage
device. Such information is stored on the device in the form of a data file. Thus, a data
file allows us to store information permanently and to access and alter that
information whenever necessary. There are two types of data files, one is stream-
oriented (or standard) data files and second is system-oriented (or low-level) data files.

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

FILE * Pointer var;

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

pintervar = fopen (filename, mode)

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

• "r" Open an existing file for reading only.


• "w" Open a new file for writing. If already exist then create new one by deleting
old one.
• "a" Open an existing for appending.
• ( To append means add at the end).
• "r + " Open an existing file both for reading and writing.
• "w + " Open a new file both for reading and writing.
• "a + " Open an existing file both for reading and appending.

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.

In syntax of each of these function requires four arguments:

1) a pointer to a data block,


2) the size of data block
3) the number of data blocks being transferred and
4) the pointer variable attached to the file.

The syntax for fwrite is :

fwrite(ptr, sizeof (block), no of data blocks, pointerver)


Ex. fwrite(&bank, sizeof (record), 1, fs);

COMPUTER NUMBER SYSTEM

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:

one-digit binary value: decimal value:


----------------------- --------------
0 0
1 1 two distinct values

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:

0000 = decimal 00 1000 = decimal 08


0001 = decimal 01 1001 = decimal 09
0010 = decimal 02 1010 = decimal 10
0011 = decimal 03 1011 = decimal 11
0100 = decimal 04 1100 = decimal 12
0101 = decimal 05 1101 = decimal 13
0110 = decimal 06 1110 = decimal 14
0111 = decimal 07 1111 = decimal 15

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:

(7 × 1000) + (5 × 100) + (3 × 10) + (1 × 1)

HIGH LEVEL LANGUAGES

 Java
 C
 Python
 Scheme
 Prolog
 C++
 C#
 Java script
 Lisp
 Ruby

LOW LEVEL LANGUAGES

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.

C file fseek() function

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)

The value of whence must be one of the constants SEEK_SET, SEEK_CUR,


or SEEK_END, to indicate whether the offset is relative to the beginning of the file, the
current file position, or the end of the file, respectively.Now,we will explain you with an
example.
In the following code, the function fopen(file, "w") open a file and allow to perform
write operations into the file. The fputs()function writes the string "Hello World" into
the file. Then we have used fseek( f , 6 , SEEK_SET ) function which sets the file
position indicator to 6 and the fputs() function write the string "India" in place of
"World".

Ftell function

<cstdio>

long int ftell ( FILE * stream );

Get current position in stream

Returns the current value of the position indicator of the stream.


For binary streams, the value returned corresponds to the number of bytes from the
beginning of the file.
For text streams, the value is not guaranteed to be the exact number of bytes from
the beginning of the file,

FLOW CHART SYMBOLS

Basic Flowchart Symbols


The Process Symbol represents any process, function, or
action and is the most frequently used symbol in
flowcharting.
The Document Symbol is used to represent any type of
hard copy input or output (i.e. reports).

Offpage Connector Symbols are used to indicate the


flowchart continues on another page. Often, the page
number is placed in the shape for easy reference.

The Input/Output Symbol represents data that is available


for input or resulting from processing (i.e. customer
database records).

Comment Symbols are used when additional explanation


or comment is required. This symbol is usually connected
to the symbol it is explaining by a dashed line.

The Decision Symbol is a junction where a decision must


be made. A single entry may have any number of
alternative solutions, but only one can be chosen.

The Connector Symbol represents the exit to, or entry


from, another part of the same flowchart. It is usually
used to break a flow line that will be continued
elsewhere. It's a good idea to reference page numbers for
easy location of connectors.

COMPILER AND INTERPRETER

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.

A compiler translates the entire program before execution


An interpreter translates one line, executes that line and then•
translates the next line
A compiler creates a list of errors after compilation•
An interpreter stops after the first error•
A compiler produces an independent executable file•
An interpreted program needs the interpreter each time it is run•
A compiled program is translated once•
An interpreted program is translated each time it is run•

DIFFERENT LANGUAGES OF PROGRAMMING LANGUAGES

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.

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.

High-level languages permit faster development of large programs. The final


program as executed by the computer is not as efficient, but the savings in
programmer time generally far outweigh the inefficiencies of the finished product.
This is because the cost of writing a program is nearly constant for each line of
code, regardless of the language. Thus, a high-level language where each line of
code translates to 10 machine instructions costs only one tenth as much in
program development as a low-level language where each line of code represents
only a single machine instruction.

In addition to the distinction between high-level and low-level languages, there is


a further distinction between compiler languages and interpreter languages. Let's
take a look at the various levels.
Absolute Machine Code

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

Assembly language is nothing more than a symbolic representation of


machine code, which also allows symbolic designation of memory locations.
Thus, an instruction to add the contents of a memory location to an internal
CPU register called the accumulator might be add a number instead of a
string of binary digits (bits).

No matter how close assembly language is to machine code, the computer


still cannot understand it. The assembly-language program must be
translated into machine code by a separate program called an assembler.
The assembler program recognizes the character strings that make up the
symbolic names of the various machine operations, and substitutes the
required machine code for each instruction. At the same time, it also
calculates the required address in memory for each symbolic name of a
memory location, and substitutes those addresses for the names. The final
result is a machine-language program that can run on its own at any time;
the assembler and the assembly-language program are no longer needed. To
help distinguish between the "before" and "after" versions of the program,
the original assembly-language program is also known as the source code,
while the final machine-language program is designated the object code.

If an assembly-language program needs to be changed or corrected, it is


necessary to make the changes to the source code and then re-assemble it
to create a new object program.

Compiler Language

Compiler languages are the high-level equivalent of assembly language.


Each instruction in the compiler language can correspond to many machine
instructions. Once the program has been written, it is translated to the
equivalent machine code by a program called a compiler. Once the program
has been compiled, the resulting machine code is saved separately, and can
be run on its own at any time.

As with assembly-language programs, updating or correcting a compiled


program requires that the original (source) program be modified
appropriately and then recompiled to form a new machine-language (object)
program.

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

An interpreter language, like a compiler language, is considered to be high


level. However, it operates in a totally different manner from a compiler
language. Rather, the interpreter program resides in memory, and directly
executes the high-level program without preliminary translation to machine
code.

This use of an interpreter program to directly execute the user's program


has both advantages and disadvantages. The primary advantage is that you
can run the program to test its operation, make a few changes, and run it
again directly. There is no need to recompile because no new machine code
is ever produced. This can enormously speed up the development and
testing process.

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.

Você também pode gostar