Sei sulla pagina 1di 30

COMPUTING AND INFORMATICS

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

Additional Course Material


Computer Basics Number System & Boolean Algebra
JK FLIP FLOP
As discussed earlier, in SR flip flop, the input combination S = R =1 is not allowed because its output is uncertain. This uncertainty may cause problems in a digital system. So, we need a one bit memory cell which has its outputs well defined for all possible input combinations. One such device is JK flip flop with inputs J and K. Also, let this flip flop have the same truth table as the SR flip flop except for the condition when J = K = 1. Since Q n +1 = Qn ,1,0 are already occurring in the truth table of the SR flip flop, let Q n +1 = Q n for the new condition (J = K = 1). Following table gives the combined truth table of SR/JK flip flops.
Combined truth table of SR/JK flip flops

J 0 0 0 0 1 1 1 1

K 0 0 1 1 0 0 1 1

Qn 0 1 0 1 0 1 0 1

Qn+1 0 1 0 0 1 1 1 0

S 0 1/0 0 0 1 1/0 1 0

R 0/1 0 0/1 1 0 0 0 1

Comment Inactive state Qn+1 = Qn Reset state Qn+1 = 0 Set state Qn+1 = 1 Toggle state Qn+1 = Qn

The K- maps with S and R as outputs, and taking J, K and Qn as inputs are shown below.

S = J.Qn
JK Qn 0 1 00 0 x 01 0 0 11 1 0 10 1 x

R = K.Q n
POST BOX NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

TOTAL PAGES:

AMIE(I) JK Qn 0 1

STUDY CIRCLE(REGD.)

A Focused Approach

00 x 0

01 x 1

11 0 1

10 0 0

Thus we have a simple way of designing a JK flip flop from the SR flip flop. The circuit corresponding to K maps given earlier is drawn below.

This circuit can be simplified to following circuit.

Truth table of above JK flip flop is given below: J 0 0 1 1 K 0 1 0 1 Q n+1 Qn 0 1


Qn

Race Around Condition


The solution that we found in the JK flip flop, for the condition when both the inputs of the flip flop are high, is not perfect. For the level triggered JK flip flop of above figure, consider the case when J = K = 1, Qn = 0 and a clock pulse occurs. After a propagation delay of t(<<tp, the pulse width) equal to the delay time of two NAND gates, the output will toggle to Q n = 1. Since this is feedback to the inputs, the output can toggle back to Qn =0 after another delay of t, if the clock is still high.
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

Thus, as long as the clock pulse is present, the output will toggle at every t seconds. This is called race around condition. Removing race around condition Making propagation delay t > tp Passing outputs Qn and Qn through delay lines before feeding them back to input Use a JK master slave flip flop

JK MASTER SLAVE FLIP FLOP


This flip flop is made of two SR flip flops. The output of the first, called the master flip flop, is given to the inputs of the second, called the slave flip flop. The output of the slave is feedback to the inputs of the master. The master is triggered by a positive clock pulse and the slave is triggered by a negative clock pulse, obtained by inverting the clock pulse applied to the master. The circuit of MS flip flop is shown below.

JK master-slave flip flop

When the clock is HIGH(CK = 1, Pr = 1, Cr = 1), the master is enables, while the slave is disabled as CK = 0 ). So, the master functions like a JK flip flop and its output appears at the input (S,R) of the slave. Since CK is LOW, the slave is inactive. Thus Q remains unchanged for the duration of the clock pulse tp. When the clock goes LOW, the slave functions like an SR flip flop and its output changes to QM, which also appears at the input of the master. Since the clock is LOW, the master is inactive so that QM( and so S and R) remains unchanged as long as the clock remains LOW. Thus, when the clock is HIGH, QM changes according to JK flip flop logic and it is transferred to Q when the clock goes LOW(negative edge transition). This eliminates the race around condition as the output remains constant for the duration of one clock pulse. The truth table of this flip flop is shown below.
Truth table of MS JK flip flop

Pr 0 0

Cr 0 1

CK x x

J x x

K x x

Qn+1 ? 1

States Not desired Preset 3

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

AMIE(I) 1 1 1 1 1 0 1 1 1 1 x x x 0 0 1 1 x 0 1 0 1 0 Qn 0 1 Qn

STUDY CIRCLE(REGD.)

A Focused Approach

Clear Inactive Zero One Toggle


Truth table of D flip flop

D FLIP FLOP
In a D flip flop the output follows the input whenever the flip flop is triggered. This can be achieved by means of a JK/SR flip flop. A D flip using JK/SR flip flop along with its truth table is shown below. D 0 1 Qn+1 0 1

D flip flop from JK flip flop

D flip flop from SR flip flop

Here the output follows the input, when the flip flop is triggered. If the flip flop is edge triggered the output is the same as the input, but is delayed by one clock pulse. Owing to this property, the D flip flop is used as a delay device. Its function is illustrated by following waveform.

T FLIP FLOP
A T flip flop can be realized by JK flip flop. T flip flop using JK flip flop along with truth table is given below.

T flip flop Truth table of T flip flop

Qn+1 4

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

AMIE(I) 0 1 0 1 0 1 Qn
Qn

STUDY CIRCLE(REGD.)

A Focused Approach

T flip flops are widely used as toggle switches.

Informatics
FILE TRANSFER PROTOCOL (FTP)
This is the language used for file transfer from computer to computer across the WWW. An anonymous FTP is a file transfer between locations that does not require users to identify themselves with a password or log-in. An anonymous FTP is not secure, because it can be accessed by any other user of the WWW. File Transfer Protocol. The protocol used on the Internet for exchanging files. FTP uses the Internet's TCP/ P protocols to enable data transfer. FTP is most commonly I used to download a file from a server using the Internet or to upload a file to a server (eg, uploading a Web page file to a server)

NETWORK PROTOCOLS
In the field of telecommunications, a communic ations protocol is the set of standard rules for data representation, signaling, authentication, and error detection required to send information over a communications channel. An example of a simple communications protocol adapted to voice communication is the case of a radio dispatcher talking to mobile stations. The communication protocols for digital computer network communication have many features intended to ensure reliable interchange of data over an imperfect communication channel. Communication protocol is basically following certain rules so that the system works properly.

Network protocol design principles


Systems engineering principles have been applied to create a set of common network protocol design principles. These principles include effectiveness, reliability, and resiliency. Effectiveness. Needs to be specified in such a way, that engineers, designers, and in some cases software developers can implement and/or use it. In human-machine systems, its design needs to facilitate routine usage by humans. Protocol layering accomplishes these objectives by dividing the protocol design into a number of smaller parts, each of which performs closely related sub-tasks, and interacts with other layers of the protocol only in a small number of well-defined ways. Protocol layering allows the parts of a protocol to be designed and tested without a combinatorial explosion of cases, keeping each design relatively simple. The implementation of a sub-task on one layer can make assumptions about the behavior and services offered by the layers beneath it. Thus, layering enables a "mix-and-match" of protocols that permit familiar protocols to be adapted to unusual circumstances.
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

For an example that involves computing, consider an email protocol like the Simple Mail Transfer Protocol (SMTP). An SMTP client can send messages to any server that conforms to SMTP's specification. Actual applications can be (for example) an aircraft with an SMTP server receiving messages from a ground controller over a radio-based internet link. Any SMTP client can correctly interact with any SMTP server, because they both conform to the same protocol specification, RFC2821. This paragraph informally provides some examples of layers, some required functionalities, and some protocols that implement them, all from the realm of computing protocols. At the lowest level, bits are encoded in electrical, light or radio signals by the Physical layer. Some examples include RS-232, SONET, and WiFi. A somewhat higher Data link layer such as the point-to-point protocol (PPP) may detect errors and configure the transmission system. An even higher protocol may perform network functions. One very common protocol is the Internet protocol (IP), which implements addressing for large set of protocols. A common associated protocol is the Transmission control protocol (TCP) which implements error detection and correction (by retransmission). TCP and IP are often paired, giving rise to the familiar acronym TCP/IP. A layer in charge of presentation might describe how to encode text (ie: ASCII, or Unicode). An application protocol like SMTP, may (among other things) describe how to inquire about electronic mail messages.

These different tasks show why there's a need for a software architecture or reference model that systematically places each task into context. The reference model usually used for protocol layering is the OSI seven layer model, which can be applied to any protocol, not just the OSI protocols of the International Organization for Standardization (ISO). In particular, the Internet Protocol can be analysed using the OSI model.

Reliability
Assuring reliability of data transmission involves error detection and correction, or some means of requesting retransmission. It is a truism that communication media are always faulty. The conventional measure of quality is the number of failed bits per bits transmitted. This has the wonderful feature of being a dimensionless figure of merit that can be compared across any speed or type of communication media. In telephony, links with bit error rates (BER) of 10-4 or more are regarded as faulty (they interfere with telephone conversations), while links with a BER of 10-5 or more should be dealt with by routine maintenance (they can be heard). Data transmission requires bit error rates below 10-12. Computer operations are so frequent that larger error rates would affect operations of customers like banks and stock exchanges. P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com 6

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

Since most transmissions use networks with telephonic error rates, the errors caused by these networks must be detected and then corrected . Communications systems detect errors by transmitting a summary of the data with the data. In TCP (the internet's Transmission Control Protocol), the sum of the data bytes of packet is sent in each packet's header. Simple arithmetic sums do not detect out-of-order data, or cancelling errors. A bit-wise binary polynomial, a cyclic redundancy check, can detect these errors and more, but is slightly more expensive to calculate. Communication systems correct errors by selectively resending bad parts of a message. For example, in TCP when a checksum is bad, the packet is discarded. When a packet is lost, the receiver acknowledges all of the packets up to, but not including the failed packet. Eventually, the sender sees that too much time has elapsed without an acknowledgement, so it resends all of the packets that have not been acknowledged. At the same time, the sender backs off its rate of sending, in case the packet loss was caused by saturation of the path between sender and receiver. (Note: this is an over-simplification: see TCP and congestion collapse for more detail) In general, the performance of TCP is severely degraded in conditions of high packet loss (more than 0.1%), due to the need to resend packets repeatedly. For this reason, TCP/IP connections are typically either run on highly reliable fiber networks, or over a lower-level protocol with added error-detection and correction features (such as modem links with ARQ). These connections typically have uncorrected bit error rates of 10-9 to 10-12, ensuring high TCP/IP performance.

Resiliency
Resiliency addresses a form of network failure known as topological failure in which a communications link is cut, or degrades below usable quality. Most modern communication protocols periodically send messages to test a link. In phones, a framing bit is sent every 24 bits on T1 lines. In phone systems, when "sync is lost", fail-safe mechanisms reroute the signals around the failing equipment. In packet switched networks, the equivalent functions are performed using router update messages to detect loss of connectivity.

Standards organisations
Most recent protocols are assigned by the IETF for Internet communications, and the IEEE, or the ISO organizations for other types. The ITU-T handles telecommunications protocols and formats for the public switched telephone network (PSTN). The ITU-R handles protocols and formats for radio communications. As the PSTN. radio systems, and Internet converge, the different sets of standards are also being driven towards technological convergence.

Protocol families
A number of major protocol stacks or families exist, including the following: Open standards:
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

AMIE(I) Internet protocol suite Open Systems Interconnect (OSI)

STUDY CIRCLE(REGD.)

A Focused Approach

Proprietary standards: AppleTalk DECnet IPX/SPX SMB Systems Network Architecture (SNA) Distributed Systems Architecture (DSA)

ELECTRONIC DATA INTERCHANGE


Electronic Data Interchange (EDI) is the computer-to-computer exchange of structured information, by agreed message standards, from one computer application to another by electronic means and with a minimum of human intervention. In common usage, EDI is understood to mean specific interchange methods agreed upon by national or international standards bodies for the transfer of business transaction data, with one typical application being the automated purchase of goods and services. Despite being relatively unheralded, in this era of technologies such as XMLservices, the Internet and the World Wide Web, EDI is still the data format used by the vast majority of electronic commerce transactions in the world.

Standards
In 2002, the IETF published RFC 3335, offering a standardized, secure method of transferring EDI data via e-mail. On July 12th, 2005, an IETF working group ratified RFC4130 for MIME-based HTTP EDIINT transfers, and is preparing similar documents for FTP transfers. EDI documents contain the same data that would normally be found in a paper document used for the same organizational function. For example an EDI 940 ship-from-warehouse order is used by a manufacturer to tell a warehouse to ship product to a retailer. It typically has a ship to address, bill to address, a list of product numbers (usually a UPC code) and quantities. It may have other information if the parties agree to include it. However, EDI is not confined to just business data related to trade but encompasses all fields such as medicine (patient records, laboratory results..), transport (container and modal information...), engineering and construction, etc. There are two major sets of EDI standards. UN/EDIFACT is the only international standard (in fact, a United Nations recommendation) and is predominant in all areas outside of North America. ANSI ASC X12 (X12)is popular in North America and used worldwide.

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

These standards prescribe the formats, character sets, and data elements used in the exchange of documents and forms, such as purchase orders (called "ORDERS" in UN/EDIFACT and an "850" in X12) and invoices. The standard says which pieces of information are mandatory for a particular document, which pieces are optional and give the rules for the structure of the document. The standards are like building codes. Just as two kitchens can be built "to code" but look completely different, two EDI documents can follow the same standard and contain different sets of information. For example a food company may indicate a particular product expiration date while a clothing manufacturer would choose to send color and size information. Organizations that send or receive documents from each other are referred to as "trading partners" in EDI terminology. The trading partners agree on the specific information to be transmitted and how it should be used. This is done in human readable specifications (also called specs or spec sheets). While the standards are analogous to building codes the specifications are analogous to blue prints. (The specification may also be called a mapping but the term mapping is typically reserved for specific machine readable instructions given to the translation software.) Larger companies have existing specification sheets and are usually unwilling to negotiate. Often in a large company these sheets will be written to be used by different branches or divisions and therefore will contain information not needed for a particular exchange. Service providers, such as GXS, provide global platforms to connect and integrate "trading partners" around-the-world. They provide integration platforms, such as GXS Trading Grid, that make the exchange of EDI (or XML) documents transparent and easy between diverse constituents.

CLIENT SERVER TECHNOLOGY


Client/server technology is the computer architecture used in almost all automated library systems now being offered to libraries. The simple definition is: Client/server is a computer architecture that divides functions into client (requestor) and server (provider) subsystems, with standard communication methods (such as TCP/IP and z39.50) to facilitate the sharing of information between them. A network architecture in which each computer or process on the network is either a client or a server. Servers are powerful computers or processes dedic ated to managing disk drives (file servers), printers (print servers), or network traffic (network servers ). Clients are PCs or workstations on which users run applications. Clients rely on servers for resources, such as files, devices, and even processing power.

Advantages of Client Server Technology


This type of technology enhances performance, where the server can execute some of the processes almost on behalf of the client. The server generally will have more resources at its disposal than the client does, for example, more memory and perhaps more hard disk space. Therefore it makes sense that the server does some of the required processing along with the
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

client, and thereby there are now two processors dealing with a part of that application - we'll come to come examples shortly. The next reason why client server technology is exceptionally well supported in the Unix/Linux environment is because of scalability . scalability is a crucial factor because as our networks grow in size, increasing the number of available work-stations, we will need some means of scaling our architecture to handle an increased volume of traffic, perhaps an increased number of clients. So from a scalability perspective, if we put 10 clients on a network and we put 1000 clients on a network, there will be a significant performance difference. Client server technology allows us to scale these networks up to relatively large client networking farms. The idea behind client server is that the shared responsibility can be shuffled around, for example, we could choose to run certain applications on specific clients and other applications on other clients. Interoperability is a key factor of why client server technology is so good. An example of the good use of interoperability is that you may have had a DEC server, a Dec VAX for example, running X 11, the X Windows system. On the client side you have a Unix machine and so the X-server, because it was a standard protocol, could offer it 's services to the Unix workstation.

Characteris tics Of A Client/Server Architecture


Among the characteristics of a client/server architecture are the following: The client and server can be distinguished from one another by the differences in tasks they perform The client and server usually operate on different computer platforms Either the client or server may be upgraded without affecting the other. Clients may connect to one or more servers; servers may connect to multiple clients concurrently Clients always initiate the dialogue by requesting a service.

In client/server the PC-based client communicates with the server as a computer. In client/server the client controls part of the activity. A client PC almost always does the following in a client/server environment: screen handling, menu or command interpretation, data entry, help processing, and error recovery. An example of one client communicating with several different servers is a PC-based client which can access a library's own automated library system, a CD-ROM server, the automated library system of another library, or a remote online reference service. While a client usually is configured on a PC and a server on a supermicro, mini, or a mainframe computer; a single machine can act as both client and server on a network. For example, two automated library systems in different libraries that are linked for resource
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

10

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

sharing are functioning as clients when requesting information, and as servers when providing it.

DATABASE MANAGEMENT SYSTEM (DBMS)


A database management system (DBMS) is a computer program (or more typically, a suite of them) designed to manage a database (a large set of structured data), and run operations on the data requested by numerous clients. Typical examples of DBMS use include accounting, human resources and customer support systems. Originally found only in large organizations with the computer hardware needed to support large data sets, DBMSs have more recently emerged as a fairly standard part of any company back office. The following are examples of database applications: computerized library systems automated teller machines flight reservation systems computerized parts inventory systems

DBMS's are found at the heart of most database applications. Sometimes DBMSs are built around a private multitasking kernel wih built-in networking support although nowadays t these functions are left to the operating system. A database management system (DBMS) is a system, usually automated and computerized, for the management of any collection of compatible, and ideally normalized, data. A database application is computer software written to manage the data of a particular application or problem. From a technical standpoint, DBMSs can differ widely. The terms relational, network, flat, and hierarchical all refer to the way a DBMS organizes information internally. The internal organization can affect how quickly and flexibly you can extract information. Requests for information from a database are made in the form of a query, which is a stylized question. For example, the query SELECT ALL WHERE NAME = "SMITH" AND AGE > 35 requests all records in which the NAME field is SMITH and the AGE field is greater The set of rules for constructing queries is known as a query language. Different support different query languages, although there is a semi-standardized query called SQL (structured query language). Sophisticated languages for managing systems are called fourth -generation languages, or 4GLs for short. than 35. DBMSs language database

The information from a database can be presented in a variety of formats. Most DBMSs include a report writer program that enables you to output data in the form of a report. Many DBMSs also include a graphics component that enables you to output information in the form of graphs and charts. P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com 11

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

Features of DBMS
A typical DBMS has the following features: Provides a way to structure data as records, tables, or objects Accepts data input from operators and stores that data for later retrieval Provides query languages for searching, sorting, reporting, and other "decision support" activities that help users correlate and make sense of collected data Provides multi-user access to data, along with security features that prevent some users from viewing and/or changing certain types of information Provides data integrity features that prevent more than one user from accessing and changing the same information simultaneously Provides a data dictionary (metadata) that describes the structure of the database, related files, and record information

Most DBMS systems are client/server based and operate over networks. The DBMS is an engine that typically runs on a powerful server or cluster of servers, in a SAN (storage area network) environment or mainframe with a high-performance channel to a large data store. The DBMS accepts requests from clients that may require sorting and extracting data. Once the server has processed the request, it returns the information to the client. There are a variety of back-end database systems, clients, and methods of access. Database middleware products are designed to provide a middle layer of software that hides the differences among databases. ODBC (Open Database Connectivity), originally designed by Microsoft, has been one of the most popular middleware products. The common language for accessing most database systems is SQL (Structured Query Language). Z39.50 is an open ANSI standard that allows database searching and information retrieval among networked systems. Metadata is information that describes data in a database. A raw data file would appear as a mass of letters, numbers, and symbols; but by knowing the format and structure of how that data is stored, you can display the data as records, fields, attributes, and elements with specific rules and properties (i.e., some fields are locked or the data is displayed a certain way). A metadata file provides this knowledge. Recall the Mars spacecraft that burned up in Mars orbit. The company that built the spacecraft was working with acceleration data in English units of pounds of force. NASA entered the data into a computer that assumed metric units called Newton. This was a tragic metadata error, in which the description of the data was misinterpreted. Most databases are operational databases, meaning that data going into the database is used in real time to support the ongoing activities of a business. A point-of-sale business accounting system is an example. As items are sold, the inventory database is updated and the inventory information is made available to the sales staff. The invoicing, order entry, and related systems are also updated.
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

12

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

Data analysts use OLAP (online analytical processing) systems to analyze database information in order to find trends or make business decisions. A data warehouse is a largescale OLAP and/or data mining system that is specifically designed to extract, summarize, combine, clean up, and process information from a number of data sources-such as the operational databases, legacy (historical) databases, and online subscription databases-for the purpose of analysis. Metadata is especially important in this environment.

C Programming
WORKING WITH ARRAYS
In a computer program we use data for processing sometimes we require a large amount of data for processing. Then it is a little bit difficult to declare so many variable in a program for example: storage of 100 number require declaration for 100 integer variables. One solution of such problem is the use of loop. Suppose loop start from 1 and continue to 100. Only one variable is used in this case for loop. But the problem arises due to variable nature. Whenever a new value is given to the variable the previous value is removed from the memory. After the complete execution of loop in the variable hold only the last value. so it is not possible to see all 100 number stored by loop in the same variable. The array is the useful data type for this purpose. The array is group of various data items of same type sharing same name and present in continuous memory locations. The array can hold all the values for reuse because array contains many variables of same name and same data type. The complete set of values is referred to as an array and the individual value as array element. The array can be of any primary data type as integer character or float. The array of character is called string and of float and integer as array. The use of array for storing large amount of data one of type makes the program easy and deficient and also solves the problem of many variable declarations. We can use the values stored as array-element again and again for different manipulations till the completion of programs. The arrays are of following their types based on the dimensions for data storing: (i) (ii) (iii) One dimensional arrays Two dimensional arrays Multi dimensional arrays

One-dimensional Arrays
The list of data items have only variable name but differentiated by a subscripts number because we can not have multiple variable of same name in a c-program. Single subscripts number differentiates the subscript number acts as the identification number for multiple data items and so the one dimensional array variable are called as single subscripts variable. The subscript number of array-data-items is started from zero and x and be a positive integer
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

13

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

number. For example when we have can integer array named X for 10 integer variable these variable are named as - X [0], X [1]X [9]. Declaration of Array. Array is also a variable. So it is to be declared in the program before its use. Every array has a data type and number of that array for its declaration. The general format for array decoration is as follows. datatype arrayname [arraysize]; The data refers to the data type required for array such as char, int or float etc. the array name is the variable name to be given to all data items of the array. The array size indicates the number of data items required for the array. This size is to be mentioned within brackets []. All the data items of array are declared continuously in memory location horizontal or vertically. For example: int num[10] In this declaration an array of integer type is declared with 10 data items having their name as num. Their subscript number starts from 0 and ranges upto 9. This array can store maximum 10 integer constants in the variable named num [0], num [1], num [2]num[9]. The item of array occupies the space in memory as the data type of array needs. In the above num is declared as int type. We can declare the of any other data type also likechar name [25]; float rate [12]; Initialization of Array. The array elements can be initialized by constant data values in a C program, if required, there several formats for assigning the initial data values to an array. For example : int num[5]={2, 4, 6, 8, 10}; int num [ ]= {2, 4, 6, 8, 10}; Both the initialization states that integer array num is declared and some data values are put in these variables using list of values, the number of values must be equal to the array size specified. But we can skip the array size specification because initialization at the time of declaration specify the array size. If we do not store any data value in the array elements by initialization, then these array elements are assumed to contain the garbage data value. Here, we have used two types of array initialization. We see that the size of array is optional if we initialize the array with declaration. The another method of array initialization is the subscript method and involves the assignment of values to the array elements individually as shown belowInt num[5];
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

14

AMIE(I) Num[0] = 2; Num[1]=4; Num[2]= 6; Num[3]= 8; Num[4]=10;

STUDY CIRCLE(REGD.)

A Focused Approach

Data Input and Data-Output with Arrays . In an array, the data-input is performed by scanf() function and data-output is produced by print() function similar to other variables. Let us take an example to describe data-input and output with array. Suppose we want to store 5 integer number by using array and display them as output after storage. The following example program ode will describe this problem. Example Store 5 integer numbers in array and show them as output. Solution /* Input-Output with Array */ #include<stdio.h> #include<conioh.> main() { int x[5]; printf(\n Enter five numbers:); scanf(%d%d%d%d%d, &x[0], &x[1], &x[2], &x[3], &x [4]); printf(\n the numbers stored in Array :\n); printf(\n%d\n%d\n%d\n%d\n%\n%d, x[0], x[1], x[2], x[3], x[4]); getch(); } Output: Enter five numbers : 12 13 14 15 16 The numbers stored in Array : 12 13 14 15
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

15

AMIE(I) 16 Example Print sum of 10 input numbers. Solution /* Sum of any 10 numbers */ #include<stdio.h> #include<conio.h> main() { int arr[10], i, sum; clrscr(); sum=0; printf(\n Enter 10 numbers :\n); for(i=0; i<=9; i++); scanf(%d, &arr[[i]); for(i=0; i<=9; i++) sum=sum+x[i]; printf(\n Sum = %d, sum); getch(); } Output: Enter 10 numbers : 2 4 6 8 1 3 5 7 9

STUDY CIRCLE(REGD.)

A Focused Approach

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

16

AMIE(I) 4 Sum = 49

STUDY CIRCLE(REGD.)

A Focused Approach

Searching Within Array. Searching means find a specific datavalue within the array elements. Several searching methods are provided by C-language like linear search, binary search. Linear search allows to search an elements in linearly that means starting from zero to the last array element. But this type of search takes a large amount of time. Binary search is useful for saving because maximum number of time taken is lesser than linear search.

Example Input n number in an array and search a number using linear search method . Solution /* Linear search */ #include <stdio.h> #include<conio.h> main() { int a[20], n, num, i, flag; clrscr(); flag=0; start : printf(\enter the size required for array:); scan f (%,&n); if (n>20) { printf(\n size required for array size ); printf(\n enter the size from 1 to 20 ! ); go to start; } printf(\n enter %d number for array \n ,n); for (i=0; i<=n-1; i++) scanf(%d, &a[i]); print f( \n enter the number to search : );
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

17

AMIE(I) scanf(%d,& num); printf(\n now searching starts ); for(i=0; i<=n-1; i++); { if(a[i]==num) { printf(\n%d is found at %d position !,num, i+1); flag=1; break; } } if(f==0) printf(\n% d is not in entire array !); getch(); } Output: Enter the size required for array Size required is out of array size. Enter the size required for array Enter 5 number for array 15 25 30 35 Enter the number to search Now searching starts 25 is found at 3 position ! : 25 : 5 : 35

STUDY CIRCLE(REGD.)

A Focused Approach

In this program, we have used goto statement for bound-checking the array size during the input. Now the numbers entered in this program will not exceed the size of 20 numbers. The flag is a variable used to evaluate true or false. Firstly, its value is taken as zero. When the search is successful the value of flag variable is turned to one. This value of flag variable is evaluated for unsuccessful or successful search. The another type of search is binary search which requires an already stored list of numbers. The technique used for binary search differs from linear search because in this method search P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com 18

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

starts from middle array element not from the first array element. If the search-element is found at middle position in array then the search process is stopped, otherwise the search continues to the left or right of middle element for lesser or greater value element than middle element respectively. Example Program for binary search in an array /* Binary search */ #include <stdio.h> #include <conio.h> main() { int arr[2], n, i, beg, end, mid, num; clrscr(); start; printf(\n enter array size required : m); scanf(%d.&n); if (n>20) { printf(\n enter %d number in ascending order ,n); printf(\n); for(I=0; i<=1; i++) scanf(%d, &arr[i]); prinf(\n enter number to search in array : ); scanf(%d, & num); beg =0 end =n - 1 mid=(beg + end)/2; { while(num<arr[mid] && beg <=end) { if (num<arr[mid]} end=mid - 1;
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

19

AMIE(I) else beg=mid + 1; mid=(beg+end)/2; } printf(\n %d is found at %d! num, mid+1); else printf(\n%d is not found in entire array ! num); getch(); } Output: Enter array size required : 5

STUDY CIRCLE(REGD.)

A Focused Approach

Enter 5 numbers in ascending order 12 15 27 35 42 Enter number to search in array :15 15 is found at 2 ! In this program, the search of a number is controlled by a loop. The loop continues till the search-number is not found at mid position or the array element terminated. The number to be searched is given as 15. The search starts from middle array element which is 27. The search is unsuccessful. Now the search number (15) is smaller than middle number (27). So search is continued to the left of middle array element. Now new mid element is 15 and the search element is also 15, so the search is successful. This process continues further is the search becomes unsuccessful. Sorting the Array. Sorting is the process to organize the data either in ascending order or descending order. The array can hold many data items of similar type at a time so we can arrange these data items either in ascending order or descending order like a sorted list. There are several sorting processes developed to sort a list of detail-items like selection sort, bubble sort etc. we will discuss the process of selection sort here for sorting a list of numbers. Selection Sort Process. The selection sort process u the technology to select the ses minimum number from a list and place to the beginning of list ascending or descending order sorting respectively. We can describe the actual process taken place in selection sort ascending order by following example :
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

20

AMIE(I) Let us take an array of 10 numbers as follows : int x[10] 22 56 33 80 78 46 25

STUDY CIRCLE(REGD.)

A Focused Approach

65

35

12

0 int x 22

1 56

2 33

3 80

4 78

5 46

6 25

7 65

8 35

9 12

After Step 1

12

56

33

80

78

46

25

65

35

22

After Step 2

12

22

33

80

78

46

25

65

35

56

After Step 3

12

22

33

80

78

46

25

65

35

56

After Step 4

12

22

25

33

78

46

80

65

35

56

After Step 5

12

22

25

33

35

46

80

65

78

56

After Step 6

12

22

25

33

35

46

80

65

78

56

After Step 7

12

22

25

33

35

46

56

65

78

80

After Step 8

12

22

25

33

35

46

56

65

78

80

After Step 9

12

22

25

33

35

46

56

65

78

80

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

21

AMIE(I) After Step 10 12 22 25 33 35 46 56

STUDY CIRCLE(REGD.)

A Focused Approach

65

78

80

In the selection sort process for ascending order sorting, the step-1 shows the selection of minimum number (12) from entire array and its replacement with the zero subscript array element (22). In step-2, the minimum number is selected out from the array except zero subscript element and its replacement is performed with subscript one array element x[1]. This process continues till the complete sorting of array. The minimum numbers are push down side to the array. Example Sort the list of number in ascending order by using selection sort method. Solution /* Selection sort process */ # include <stdio. h> # include <conio. h> main() { int x[20], n, min, p, temp; clrscr(); start: printf(\n Enter Array Size Required:); if (n>20) { printf(\n Out of Range. \n Enter from 1 to 20 ! \n ); goto start; } printf(\ Enter %d Number to sort :\n); for(i=0; i<=n-1; i++) scanf( %.&x[i]); printf(\n Now sort process starts \n); for(i=0; i<=1; i++) { pos=i;
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

22

AMIE(I) min=x[i]; for(p=i+1;p<=n-1; p++) { if(xp[p]) { min=x[p]; pos=p; } } temp=x[i]; x[i]=x[pos];p x[pos]=temp; } printf(\n Sorted Array in Ascending Order : \n); for(I=0; i<=n-1; i++); printf(\n%d,x[i]); getch(); } Output: Enter array size required: 10 Enter10 numbers to sort : 22 56 33 80 78 46 25 65 35 12 Now sort process starts-

STUDY CIRCLE(REGD.)

A Focused Approach

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

23

AMIE(I) Sorted Array in Ascending Order : 12 22 25 33 35 46 56 65 78 80

STUDY CIRCLE(REGD.)

A Focused Approach

Programming in C++
Example Write a C++ program to take a valu e from the user and print the square of it, unless it is more than 120. The message I cannot square numbers" should appear if the user types too large a number. Solution // progif.cpp // Prints the square of the input value if the input value is less than 180 #include <iostream.h> fit main(} { int num, square; cout << "\n\n"; cout << "What number do you want to see the square of? "; cin >>num; if(num< 120) { square = num * num; cout << The square of <<num<<is<<square; }
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

24

AMIE(I) if (num>=120) { cout << \n*** Square is not allowed for; cout << numbers over 120***; cout <<\nRun this program again and try; cout <<a smaller value; } cout << \n Thank you for requesting squares; return 0; } Example Write a C++ program to generate a Fibonacci serie s upto n. Solution // Generate Fibonacci series upto n # include <iostream.h> # include <conio.h> int main( ) { int n, i, a, b, c; cout <<"Enter how many terms \n"; cin >> n; a = 0; a = 1; cout <<"Required series is \n"; cout << "\n" << a << "\n << b; for (i = 2; i <= n; i++) { c = a + b; cout <<" << c; \n" a = b; b = c;

STUDY CIRCLE(REGD.)

A Focused Approach

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

25

AMIE(I) } getch( ); return 0; } Output : Enter how many terms 8 Required series is 0 1 1 2 3 5 8 13 Example

STUDY CIRCLE(REGD.)

A Focused Approach

Write a C++ program to find factorial of a given number using do while. Solution // Find factorial of given number. # include <iostream.h> int main( ) { int n, fact = 1, i = 1; cout << "Enter a number" << endl; cin >> n; do { fact = fact * i; i++; }
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

26

AMIE(I) while (i < = n); cout << "Factorial =" << fact; } Output : Enter a number 3 Factorial = 6 Example

STUDY CIRCLE(REGD.)

A Focused Approach

Write a C++ program to find square root of numbers. The process stops when number 7777 is entered. Solution # include <iostream.h> # include <math.h> int main( ) { int i, n, neg = 0; float r; cout << "Enter 7777 to stop \n"; for (i = 1; i < = 100; i++) { cout << "\n Enter number" ; cin >> n; if (n = = 7777) break; if (n < 0) { cout << "Number is negative \n"; neg ++; continue; } r = sqrt (n); cout << "\n square root = " << r;
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

27

AMIE(I) } cout << "\n Total negative number = " << neg; return 0; } Output : Enter 7777 to stop Enter number 25 Square root = 5.0 Enter number 14 Number is negative Enter number 80 Square root = 8.9442 Enter number 7777 Total negative number = 1

STUDY CIRCLE(REGD.)

A Focused Approach

OBJECT ORIENTED PROGRAMMING


Object Oriented Programming is an approach that provides a way of modularization of programs by creating partitioned memory area for both data and functions that can be used as templates for creating copies of such modules. The fundamental concept behind object oriented programming is to combine into a single unit both data and functions that operate on the data. Such a unit is called an Object. An Object is a self contained unit or modules of data and code. All data and procedures related to the object are defined within it. Therefore, procedures are tied to the data. A message identifying a method to execute is passed to the object. The advantages of OOP fall into two broad categories increased programming productivity and decreased costs. Some classes and objects may be reused in other applications. Re-used code would have already been tested, so it should need little testing when used in a new program.

OOP Terminology and Characteristics


There are following basic concepts underlying OOP. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism
P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

28

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

Objects and Classes. Class describes the data and its behaviour or functionality. Objects are said to be members of classes. For example, Fruit is a class and apple is an object. The basic features of Fruit are common to all fruits. Therefore apple which is an object of class Fruit inherits these properties. The apple can then be assigned individual characteristics like colour, size, etc. A class is a key concept of C++. A class, when declared in a C++ program, does not occupy space in memory. On the other hand, an object is a physical identifiable identity with some characteristics. An object is a type of data which is self-contained unit containing data, c odes and the member functions which operate on data. The object may be a place, person or any other thing. Each object have a different identity. For example, two students can be treated as similar objects, since their function is same, i.e., learning, but one may be science student and the other an art student. Class is a user defined data type. Classes provide data hiding, guaranteed initialization of data, implicit type conversion for user defined types, user controlled memory management and a mechanism for overloaded operators. Relation between Class and Object We know that a class can have number of objects each comprising data and function of that class. The data of an object can be accessed only by the functions associated with that object. However, functions of one object can access the function of other object. Consider the following statement : int num1, num2, num3; num1, num2, num3 are three variables of type int. Similarly, we can define many objects of the same class. Inheritance . Inheritance is the capability to define a new class in terms of an existing (base) class. The new class is known as derived class. The principle here is that each subclass shares common characteristics with the class from which it has been derived. In addition to the characteristics shared with other members of the class, each subclass has its own particular characteristics. The concept of inheritance provide an important extension to the idea of reusability. Once a class has been written, created and debugged, it can be distributed to other programmers for use in their own programs. A programmer can take an existing class and without modifying it, add additional features and capabilities to it. This is done by deriving a new class from the existing one. The new class will inherit the capabilities of the old one, but it is free to add new features to its own. An already existing class can therefore be reused to define a new class, reducing programming effort. Data members and member functions of the base class can be inherited by the derived class. Private member of the base class can not be inherited. Polymorphism. The polymorphism is an important concept of object oriented programming (OOP). It is a Greek term, means the ability to take more than one form. It refers to the fact that a single operation can have different behaviour in different objects. In other words, P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com 29

AMIE(I)

STUDY CIRCLE(REGD.)

A Focused Approach

different object react differently to the same message. For example, consider the operation of addition for two numbers, addition should generate the sum. In a programming language that support OOP, we should be able to express the operation of addition by a single operator, say, +. We can use the expression x + y to denote the sum of x and y for many different types of x and y, i.e., for integers, floating point numbers and complex numbers. We can also define the + operation for two string to mean the concatenation of the string. Polymorphism plays an important role in allowing objects having different internal structure to share the same external interface. Therefore, a general class of operations may be accessed in the same manner even though specific actions associated with each operation may differ.

Benefits Of OOP
The main advantages of object oriented programming are : Simplicity : Software object model real-world objects, so the complexity is reduced and the program structure is very clear. It is possible to make minor changes in the data representation or the procedures in an object oriented program. Changes inside a class do not affect any other part of the program, since the only public interface that the external world has to a class is through the use of methods. The principle of data hiding helps the programmer to build secure programs that can not be invoked by code in other parts of the program. Object oriented system can be easily upgraded from small to large systems. Message passing techniques for communications between objects makes the interface descriptions with external systems much simpler. Adding new features or responding to changing operating environments can be solved by introducing few new objects and modifying some existing ones. Objects can be reused in different programs.

P.B. NO.77, 2 ND FLOOR, SULTAN TOWERS, ROORKEE 247667 UTTARANCHAL PH: (01332) 266328 Email : pcourses@hotmail.com

30

Potrebbero piacerti anche