I ns t i t ut eo fMa na g e me nt & Te c hni c a lSt udi e s
MATHEMATI CALFOUNDATI ONOFCS 500
Ma s t e ri nComput e rAppl i c a t i on www. i mt s i ns t i t ut e . c om
IMTS (ISO 9001-2008 Internationally Certified)
MATHEMATICAL FOUNDATION OF CS
MATHEMATICAL FOUNDATION OF CS
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
UNIT-I: 01-31 Introduction to Computers: Introduction-Types of computersCharacteristics of Computers. Five generations of Modern Computers: First Generation-Second Generation, Third Generation, Fourth Generation and Fifth Generation computers. Classification of Digital Computers-Workstation Portable Computers-Minicomputers-Mainframes-Super computers-Net Computers. Programming Languages: Introduction-Machine Language-Assembly Language –High level Languages. Input Devices: Introduction Keyboard –Mouse-Types of mice-Connections-Mouse Pad- Trackball-Joystick –Digitizing tablet –Scanners – Digital camera. Magnetic Ink Character Recognition (MICR) –Optical Character Recognition (OMR)-Bar Code Reader-Speech Input Devices –Touch Screen – Touch Pad –Light Pen. Output Devices: Introduction-Monitor Classification of Monitors- Based on Color-Characteristics of a Monitor –Printer Daisy Wheel Printer –Dot Matrix Printer –Inkjet –Laser Printer –LCD&LED Printer –Line Printer –Thermal Printer –Plotter –Sound Cards & Speakers Auxiliary Storage Devices: Magnetic Tape –Hard Disk –Floppy Disk-CD-Rom.
UNIT-II: 32-56 Flow Charts: Symbols –A Simplified Model of a Computers More flow Charting examples. Fortran programming preliminaries: Higher –level languages for Computers –The FORTRAN Language-Characters used in FORTRAM.FORTRAN CONSTANTS and Variables: FORTRAN Constants – FORTRAN Variable name –Type declaration for integers and reals. Arithmetic Expressions: Arithmetic Statement-Defining variables –Some problems due to rounding of Examples of use of functions –Programme preparation preliminaries. Input –Output Statements: List directed input statements. Control Statements :Relational Operators –Logical IF Statement –Statements Lables-GOTO Statement – nested logical IF statement - The arithmetic IF Statement. The DO Statement - The DO Statement – Rules to followed in utilizing DO loops – The REPEAT WHILE Structure .subscribted Variable :Use of multiple subscript subscript Expression - DIMENSION Statement -DO type notation for input/output statements – summary of subscript rules. UNIT-III:
57-73
FUNCTIONS AND SUBROUTINERS: Introduction - Statement functions of subprograms – Syntax rules for subprograms – subroutines - The COMMON declaration – Labelled COMMON –Placement of array - Use of procedure names as arguments .Processing Files in FORTRAN : Creating a sequential file –Searching a sequential file – Updating a sequential file-Merging two sequential files-Direct access files. FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
UNIT-IV:
74-103
FoxPro overview and sample session –ACCEPT.INPT –ACTIVATE / DEFINE MENU .DEFINE PAD – ACTIVATE /DEFINE POPUP ,DEFINE BAR ,BAR() – ACTIVATE /DEFINE WINDOW ,ACTIVATE /DEFINE WINDOW ,ACTIVATE SCREEN –APPEND CALCULATE –CALL , LOAD , RELEASE MODULE - DATE(),TIME(),SET CLOCK – DELETE , RECALL, PACK – DIMENSION – DIR –DISPLAY ,LIST,CLEAR – DO –DO CASE, OTHERWISE , ENDCASE – DO WHILE ,EXIT, LOOP ,ENDCO,EOF (). UNIT-V:
104-144
Edit – find – seek – seek ( ) for ,end for - go – go to – go bottom –go top – skip -if – else - end if – index –reindex insert – join - locate , continue – modify command – modify memo, close memo, mem Lines ( ) mline () – modify structure replace – run say , say get , say picture - -clear gets, read – scan , end San – scroll –set Commands -sort store .release ,save restore - sum – suspend ,resume – text , end text – total – udata – use –wait
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
UNIT-I INTRODUCTION TO COMPUTERS
INTRODUCTION
A computer is a programmable machine. The two principal characteristics of a computer are :
It responds to a specific set of instructions in a well-defined manner.
It can execute a prerecorded list of instructions (a program)
Modern computers are electronic and digital. The actual machinery – wires, transistors, and circuits – is called hardware; the instructions and data are called software. All general – purpose computers require the following hardware components:
Central processing unit (CPU) The “heart” of the computer, the component that actually executes instructions.
Memory Enables a computer to store, at least temporarily, data and programs.
Input device Usually a keyboard or mouse, the input device is the conduit through which data and instructions enter a computer.
Output device A display screen, printer, or other such devices that lets you see what the computer has accomplished.
Mass storage device Allows a computer to permanently retain large amounts of data. Common mass storage devices include disk drives and tape drives.
In addition to these components, many others make it possible for the basic components of a computer to work together efficiently. For example, every computer requires a bus that transmits data from one part of the computer to another.
TYPES OF COMPUTERS Computers can be classified by their size and power as follows:
Personal computer A small, single – user computer based on a microprocessor. In addition to the microprocessor, a personal computer has a keyboard for entering data, a monitor for displaying information, and a storage device for saving data.
Workstation A powerful, single-user computer. A workstation is like a personal computer, but it has a more powerful microprocessor and a higher-quality monitor.
Minicomputer A multi-user computer capable of supporting 10 to hundreds of users simultaneously.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
1
MATHEMATICAL FOUNDATION OF CS
Mainframe A powerful multi-user computer capable of supporting many hundreds of users simultaneously.
Supercomputer An extremely fast computer that can perform hundreds of millions of instructions per second.
CHARACTERISTICS OF COMPUTERS All computers have certain common characteristics irrespective of their type and size. Word Length A digital computer operates on binary digits – 0 and 1. It can understand information only in terms of 0s and 1s. A binary digit is called a bit. A group of 8 bits is called a byte. The number of bits that a computer can process at a time in parallel is called its word length. Commonly used word lengths are 8, 16, 32 or 64 bits. Word length is the measure of the computing power of a computer. Speed
Computers can calculate at very high speeds. A microcomputer, for example, can execute millions of instructions per second over and over again without any mistake. As the power of the computer increases, the speed also increases. For example, supercomputers can operate at speeds measured in nanoseconds and even in picoseconds – one thousand to one million times faster than microcomputers. Storage
Computers have their main memory and auxiliary memory systems. A computer can store a large amount of data. With more and more auxiliary storage devices, which are capable of storing huge amounts of data, the storage capacity of a computer is virtually unlimited. The factor that makes computer storage unique is not that it can store vast amount of data, but the fact that it can retrieve the information that the user wants in a few seconds.
Accuracy
The accuracy of a computer system is very high. Errors in hardware can occur, but error detecting and correcting techniques will prevent false results. In most cases, the errors are due to the human factor rather than the technological flaws. For example, if a program is wrongly coded, if the data is corrupted, or if the program logic is flawed, then irrespective on which computer you run it, you will always get wrong results. Another area where mistakes can creep in is during data entry. People often make mistakes when data is keyed-in and the computer accepts whatever
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
2
MATHEMATICAL FOUNDATION OF CS that is keyed-in. So if a wrong input is given, the output also will be wrong – GIGO (Garbage In Garbage Out). Versatility
Computers are very versatile machines. They can perform activities ranging from simple calculations to performing complex CAD modeling and simulation to navigating missiles and satellites. In other words, they are capable of performing almost any task, provided the task can be reduced to a series of logical steps. Computers can communicate with other computers and can receive and send data in various forms like text, sound, video, graphics, etc. This ability of computer to communicate to one another has led to the development of computer networks, Internet, WWW and so on. Automation
The level of automation achieved in a computer is phenomenal. It is not a simple calculator where you have to punch in the numbers and press the ‘equal to’ sign to get the result. Once a task is initiated, computers can proceed on its own till its completion. Computers can be programmed to perform a series of complex tasks involving multiple programs. Computers will perform these things flawlessly. They will execute the programs in the correct sequence, they will switch on/off the machines at the appropriate time, they will monitor the operational parameters, they will send warning signals or take corrective actions if the parameters exceed the control level, and so on. Computers are capable of theses levels of automation, provided they are programmed correctly. Diligence
Diligence means being constant and earnest in effort and application. Human beings suffer fro weakness like tiredness, lack of concentration, etc. Humans have feelings, they become sad, depressed, bored, and negligent and it will reflect on the work they do. Moreover, human beings cannot perform the same or similar tasks over and over again with the same precision, accuracy and enthusiasm as the first time. After some time, people will become bored and tedium will set in. This will affect the performance. Being a machine, a computer does not have any of these human weaknesses. They won’t get tired or bored. They will not go into depression or loose concentration. They will perform the tasks that are given to them, irrespective of whether it is interesting, creative, monotonous or boring, irrespective of whether it is the first time or the millionth time, with exactly the same accuracy and speed.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
3
MATHEMATICAL FOUNDATION OF CS FIVE GENERATIONS OF MODERN COMPUTERS The computers are classified into different generations – from first generation to fifth generation computers. The classification and the time period is given bellow: 1. First Generation (1945-1956) 2. Second Generation (1956-1963) 3. Third Generation (1964-1971) 4. Fourth Generation (1971 – Present) 5. Fifth Generation (Present and Beyond) FIRST GENERATION (1945-1956)
John Presper Eckert (1919-1995) and John W.Mauchly(1907-1980), built the first digital computer using parts called vacuum tubes. They named their new invention ENIAC. Consisting of 18,000 vacuum tubes, 70,000 resistors and 5 million soldered joints.
Von Neumann designed the Electronic Discrete Variable Automatic Computer (EDVAC) in 1947 with a memory to hold both a stored program as well as data. This “stored memory” technique as well as the “conditional control transfer”, that allowed the computer to be stopped at any point and then resumed, allowed for greater versatility in computer programming. The key element to the Von Neumann architecture was the central processing unit, which allowed all computer functions to be coordinated through a single source. In 1951, UNIVSC I (Universal Automatic Computer), built by Remington Rand, became one of the first commercially available computer. SECOND GENERATION COMPUTERS (1956-1963) Second – generation computers replaced machine language with assembly language, allowing abbreviated programming codes to replace long, difficult binary codes. There were a number of commercially successful second-generation computers used in businesses, universities, and government. These second-generation computers were also of solid state design, and contained transistors in place of vacuum tubes.
It was the stored program and programming language that gave computers the flexibility to finally be cost effective and productive for business use. The stored program concept meant that instructions to run a computer for a specific function (known as a program) were held inside the computer’s memory, and could quickly be replaced by a different set of instructions for a different function. A computer could print customer invoices and minutes later design products or calculate pay cheques.
More sophisticated high-level languages such as COBOL (Common
Business-Oriented Language) and FORTRAN (Formula Translator) came into common use
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
4
MATHEMATICAL FOUNDATION OF CS
5
during this time, and have expanded to the current day. These languages replaced cryptic binary machine code with words, sentences, and mathematical formulae, making it much easier to program a computer. New types of careers (programmer, analyst, and computer system expert) and the entire software industry began with second generation computers.
Paralleling the
development of second-generation system was the creation of a new industry, built around the idea of integrating transistors and other components into circuits that could be placed on small chips of silicon. THIRD GENERATION COMPUTERS (1964-1971) Though transistors were clearly an improvement over the vacuum tube, they still generated a great deal of heat, which damaged the computer’s sensitive internal parts. The quartz rock eliminated this problem. The IC combined three electronic components onto a small silicon disc, which was made from quartz. Scientists later managed to fit even more components on a single chip, called a semiconductor. Third generation development included the use of an operating system that allowed machines to run many different programs at once with a central program that monitored and coordinated the computer’s memory. FOURTH GENERATION COMPUTERS ( 1971-PRESENT) After the integrated circuits, the only place to go was down – in size, that is. Large – scale integration (LSI) could fit hundreds of components onto one chip. Very large scale integration (VLSI) squeezed hundreds of thousands of components onto a chip. Ultra – large scale integration (ULSI) increased that number into the millions. The ability to fit so much onto an area about half the size of one-rupee coin helped diminish the size and price of computers. It also increased their power, efficiency and reliability. One microprocessor could be manufactured and then programmed to meet any number of demands. Soon everyday household items such as microwave ovens, television sets and automobiles incorporated microprocessors. There minicomputers came complete with user-friendly software packages that offered even non-technical users an array of applications, most popularly word processing and spreadsheet programs.
FIFTH GENRATION (PRESENT AND BEYOND) Many advances in the science of computer design and technology are coming together to enable the creation of fifth-generation computers. Another advance is superconductor technology, which allows the flow of electricity with little or no resistance, greatly improving the speed of information flow. Computers today have some attributes of fifth generation computers. For example, expert systems assist doctors in making diagnoses by applying the problem-solving steps a doctor might use in assessing a patient’s needs.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
6
th
Schematic diagram of a 5 generation computer
Fifth generation computers aim to be able to solve highly complex problems, ones, which require reasoning, intelligence and expertise when solved by people. They are intended to be able to cope with large subsets of natural languages, and draw on very large knowledge basis. Fifth generation computers are being designed to be used by people who are not necessarily computer experts. In order to achieve these very ambitious aims, fifth generation computers will not have a single processor, or a small number of tightly coupled processors as computers do today. As said before they are being designed to contain a large number of processors, grouped into three major subsystems: a knowledge base system, an inference mechanism and an intelligent user interface. The knowledge base system has a very large store of knowledge with a set of processors, which access and update it. It is likely that knowledge bases will evolve from current work in relational databases. Operations on knowledge bases require the manipulation of large numbers of individual elements: this manipulation will be done in parallel by the arrays of knowledge processing elements .The inference mechanism draws reasoned conclusions from the knowledge base. Much of its processing will be drawing logical inferences of the : If <condition> then <action>
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS variety. Accordingly, the processing power of fifth generation computers is expressed in logical inferences per second (lips). The target is in the range 50 to 1000 million lips (compared with a current performance of 10 to 100 thousand lips). Most of this improved performance is planned to be achieved via highly parallel architectures, such as the data-flow and graph reduction architectures. The intelligent user interface is the point of contact between a fifth generation computer and its user. Many of these will be based on communication in a large subset of a natural language. Others will make extensive use of advanced graphics, including image processing. The intention is to build a user interface, which is close to the natural way of thinking of the user, rather than close to the way of working of the computer.
CLASSIFICATION OF DIGITAL COMPUTER SYSTEMS INTRODUCTION Computer systems are classified as Microcomputers, Minicomputers, Mainframes and Supercomputers.
MICROCOMPUTERS The most familiar kind of computer is the microcomputer. In the past, microcomputers have been considered to be of two types – Personal Computers and Workstations. Personal Computers (PCs) PCs were desktop or portable machines .These machines ran comparatively easy – to – use applications software such as the word processors, spreadsheets, etc. They were usually easier to use and more affordable than workstations. However, they had less sophisticated video display screens, operating systems and networking capabilities. They did not have the processing power that workstations did. Examples of personal computers are Acer’s Aspire, Compaq Presario, etc. Workstations Workstations expensive, powerful machines used by engineers, scientists, and other professionals who processed a lot of data. Workstations use high-resolution colour graphics and operating systems such as UNIX that permitted multitasking. Workstations also use powerful networking links to other computers. The most significant distinguishing factor, however, is the powerful processor, which could churn out results much faster than the PCs. The more powerful workstations are called supermicros. Examples of well-known workstations are those made by Sun, Apollo, Hewlett-Packard, NeXT and IBM. PCs are now as powerful as many of those used in workstations. More powerful microprocessors and increased graphics and communications capabilities now let end users run software that previously ran only on more powerful machines.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
7
MATHEMATICAL FOUNDATION OF CS
8
Portable Computers Personal computing market is seeing the miniaturization phenomena. Computers are becoming smaller yet more powerful. There are three categories of portable computers: Laptops or Notebook PCs, Subnotebooks and Personal Digital Assistants. Laptops / Notebooks : Laptops may be either AC-powered, battery-powered, or both. These computers are ideal for users who have to work away from their offices .The user of these computers might be an executive on the move, a student, a journalist, a salesperson, etc. Subnotebooks: Subnotebooks are for frequent flyers and life–on-the-road professionals. Subnotebook users give up a full display screen and keyboard in exchange for less weight. These computers fit easily into any briefcase. They typically have an external floppy disk drive and monochrome monitor, although of late colour models are available. An example of a colour sub notebooks is Toshiba Protégé. Personal Digital Assistants (PDAs) PDAs are much smaller than the sub notebooks. They combine pen input, writing recognition, personal organization tools, and communication capabilities in a very small package. Typical users are executives, businessmen, etc. who use these machines for their day-today activities – scheduling, organization, etc. An example PDA is Apple’s Newton. MINICOMPUTERS Minicomputers, also known as mid range computers. They were used
to control
machines in a manufacturing unit. They are widely used as general – purpose computers. The more powerful minicomputer models are called superminis. The increasing power of microcomputer gives minutes. One of the popular minicomputer systems is the VAX made by Digital Equipment Corporation. Minicomputers work well in what are known as Distributed Data Processing (DDP). That is, a company’s processing power is decentralized, or distributed across different computers. An example of such a computer architecture is the Client/Server model, in which end users can process at their own microcomputers. End users can also access and share the resources of the server, which usually is a minicomputer. For example, an executive could use the server to search the company’s centralized database and retrieve selected data. He / she could then use a spreadsheet on his/her microcomputer to analyze the data. MAINFRAMES Mainframe computers can process several million – program instructions per second. Large organizations rely on these room-size systems to handle large programs with lots of data. Mainframes are mainly used by insurance companies, banks, airline and railway reservation systems, etc. An advanced mainframe made by IBM is S/390. SUPERCOMPUTERS
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
9
Supercomputers are the fastest calculating devices. A desktop microcomputer processes data and instructions in millionths of a second, or microseconds. A supercomputer, by contrast, can operate at speeds measured in nanoseconds and even in picoseconds. One thousand to one million times as fast as microcomputers. Most supercomputers are used by government agencies. These machines are for applications requiring very large programs and huge amounts of data that must be processed quickly. Examples of such task are weather forecasting, oil exploration, weapons research, and large-scale simulation. The chief difference between a supercomputer and a mainframe is that a supercomputer channels all its power into executing a few programs as fast as possible, whereas a mainframe uses its power to execute many programs concurrently. Supercomputers use a technology called massively parallel processing. These supercomputers consist of thousands of integrated microprocessors. One massively parallel computer built by Intel Corporation is capable of performing 8.6 billion mathematical calculations per second. NETWORK COMPUTERS Network computers are computers with minimal memory, disk storage and processor power designed to connect to a network, especially the Internet.Network computers is that many users who are connected to a network. Network computers designed to connect to the internet are sometimes called internet boxes, Net PCs and Internet appliances.
ANATOMY OF A DIGITAL COMPUTER
FUNCTIONS AND COMPONENTS OF A COMPUTER To function properly, the computer needs both hardware and software. consists of the mechanical and electronic devices.
Hardware
The software consists of programs, the
operating systems and the data that reside in the memory and storage devices. A computer does mainly the following four functions:
Receive input – Accept information from outside through various input devices like the keyboard, mouse, etc.
Process information – perform arithmetic or logical operations on the information.
Produce output – Communicate information to the outside world through output devices like monitor, printer, etc.
Store information – Store the information in storage devices like hard disk, floppy disks, etc.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
10
Computer hardware falls into two categories: processing hardware, which consists of the central processing unit (CPU), and the peripheral devices. CENTRAL PROCESSING UNIT (CPU) The part of the computer that executes program instructions is known as the processor or central processing unit (CPU). The CPU has two parts – the control unit and the arithmetic – logic unit (ALU). Control unit The control unit tells the rest of the computer system how to carry out a program’s instructions. It directs the movement of electronic signals between memory – which temporarily holds data, instructions and processed information – and the ALU. It also directs these control signals between the CPU and input/ output devices. Arithmetic – Logic Unit (ALU) Arithmetic Logic Unit, usually called the ALU, performs two types of operations – arithmetic and logical.
Arithmetic operations are the fundamental mathematical operations
consisting of addition, subtraction, multiplication and division.
Logical operations consist of
comparisons. That is, two pieces of data are compared to see whether one is equal to., less than, or greater than the other. MEMORY Memory – also known as the primary storage or main memory – is a part of the microcomputer that holds data for processing, instructions for processing the data (the program) and information. Part of the contents of the memory is held only temporarily, that is, it is stored
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
11
only as long as the microcomputer is turned on. When you turn the machine off, the contents are lost.
The capacity of the memory to hold data and program instructions varies in different
computers hold approximately 6,40,000 characters of data or instructions only.
But modern
microcomputers can hold millions, even billions of characters in their memory. REGISTERS Computers also have several additional storage locations called registers. These appear in the control unit and ALU and make processing more efficient. Registers areas hold data and instructions temporarily during processing. They are parts of the control unit and ALU rather than the memory. ADDRESSES To locate the characters of data or instructions in the main memory, the computer stores them in locations known as addresses. A unique number designates each address. Addresses can be compared to post office mailboxes.
Their numbers stay the same, but contents
continuously change.
HOW THE CPU AND MEMORY WORK The various steps involved for multiplying two numbers is explained below: 1. The control unit recognizes that the programs has been loaded into memory. It begins to execute the first step in the program. st
2. The program tells the user, “Enter 1 Number.” 3. The user types the number 10 on the keyboard. An electronic signal is sent to the CPU. 4. The control unit recognizes this signal and routes the signal to an address in memory – address 7. 5. After completing the above instruction, the next instruction tells user, “Enter 2
nd
Number.”
6. The user types the number 4 on the keyboard. An electronic signal is sent to the CPU. 7. The control unit recognizes this signal and routes it to memory address 8. st
8. The next program instruction is executed – “Multiply 1 and 2
nd
Numbers.”
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS 9. To execute this instruction, the control unit informs the ALU that two numbers are coming and the ALU is to multiply them. The control unit next sends to the ALU a copy of the contents of address 7(10) and address 8 (4). 10. ALU performs the multiplication: 10 X 4 = 40. 11. The control unit sends a copy of the multiplied result (40) back to memory, to address 9.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
12
MATHEMATICAL FOUNDATION OF CS
13
12. The next program instruction is executed: “Print the Result.’ 13. To execute this instruction, the control unit sends the contents of the address 9(40) to the monitor. 14. Monitor displays the value 40. 15. Final instruction is executed: “End.” The program is complete.
INPUT DEVICES INTRODUCTION An input device is any machine that feeds data into a computer.
For example, a
keyboard is an input device, whereas a display monitor is an output device. Input devices other than the keyboard are sometimes called alternate input devices. Mice, trackballs, and light pens are all alternate input devices. KEYBOARD Keyboard is an input device consisting of a set typewriter-like keys that enable you to enter data into a computer. Computer keyboards are similar to electric-typewriter keyboards but contain additional keys. The keys on computer keyboards are often classified as follows:
Alphanumeric keys – letters and numbers
Punctuation keys – comma, period, semicolon, and so on.
Special keys – function keys, control keys, arrow keys, caps Lock key, and so on.
There are actually three different PC keyboards: the original PC keyboard, with 84 keys; the AT keyboard, also with 84 keys; and the enhanced keyboard, with 101 keys. In addition to these keys, IBM keyboards contain the following keys: Page UP, Page Down, Home, End, Insert, Pause, Num Lock, Scroll Lock, Break, Caps Lock, Print Screen. MOUSE Mouse is a device that controls the movement of the cursor or pointer on a display screen. A mouse is a small object you can roll along a hard, flat surface. As you move the mouse, the pointer on the display screen moves in the same direction. Mice contain at least one button and sometimes as many as three, which have different functions depending on what program is running. In particular, the mouse is important for graphical user interfaces because you can simply point to options and objects and click a mouse button. Such applications are often called pointand – click programs. The mouse is also useful for graphics programs that allow you to draw pictures by using the mouse like a pen, pencil, or paintbrush. Types of Mice There are three basic of Mice.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
14
Mechanical Has a rubber or metal ball on its underside that can roll in all directions. Mechanical sensors within the mouse detect the direction the ball is rolling and move the screen pointer accordingly. Optomechanical
Same as a mechanical mouse, but uses optical sensors to detect
motion of the ball. Optical Uses a laser to detect the mouse’s movement. You must move the mouse along a special mat with a grid so that the optical mechanism has a frame of reference. Optical mice have no mechanical moving parts.
They respond more quickly and precisely than
mechanical and optomechanical mice, but they are also more expensive. Connections Mice connect to PCs in one of three ways:
Serial mice connect directly to an RS-232C serial port or a PS/2 port. This is the simplest type of connection.
Bus mice connect to the bus through an interface card.
This is somewhat more
complicated because you need to configure and install an expansion board.
Cordless mice aren’t physically connected at all. Instead they rely on infrared or radio waves to communicate with the computer.
Mouse pad Mouse pad is a pad over which you can move a mouse. TRACKBALL Trackball is another pointing device. Essentially, a trackball is a mouse lying on its back. To move the pointer, you rotate the ball with your thumb, your fingers, or the palm of your hand. There are usually one to three buttons next to the ball, which you use just like mouse buttons. The advantage of trackballs over mice is that the trackball is stationary so it does not require much space to use it. In addition, you can place a trackball on any type of surface, including your lap. For both these reasons, trackballs are popular pointing devices for portable computers. JOYSTICK A lever that moves in all directions and controls the movement of a pointer or some other display symbols. A joystick is similar to a mouse, except that with a mouse cursor stops moving as soon as you stop moving the mouse. With a joystick, the pointer continues moving in the direction the joystick is pointing. To stop the pointer, you must return the joystick to its upright position. Joystick are used mostly for computer games, but they are also used occasionally for CAD/CAM systems and other applications.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
15
DIGITIZING TABLET This is an input device that enables You to enter drawings and sketches into a computer. A digitizing tablet consist of an electronic tablet and a cursor or pen. A cursor (also called a puck) is similar to a mouse, except that it has window with crosshairs for pinpoint placement and it can have as any as 16 buttons A pen (also called a stylus) which looks like a simple ballpoint pen but uses an electronic head instead of ink.
The tablet contains
electronic that enable it to detect movement of the cursor or pen and translate the movements into digital signals that it sends to the computer. Digitizing tablet are also called digitizers, graphics tablets, touch tablets, or simply tablets. SCANNERS Scanner is an input device that can read text or illustrations printed on paper and translate the information into a form that the computer can use. A scanner works by digitizing an image – dividing it into a grid of boxes and representing each box with either a zero or a one, depending on whether the box is filled in. The resulting matrix of bits, called a bit map, can then be stored in a file, displayed on a screen, and manipulated by programs. Optical scanners do not distinguish text from illustrations; they represent all images as bit maps. Therefore, you cannot directly edit text that has been scanned. To edit text read by an optical scanner, you need an optical character recognition (OCR) system to translate the image into ASCII characters. Most optical scanners sold today come with OCR packages. Scanners differ from one another in the following respects: Scanning technology
Most scanners use charge – coupled device
(CCD) arrays,
which consists of tightly packed rows of light receptors that can detect variations in light intensity and frequency.
The quality of the CCD array is probably the single most important factor
affecting the quality of the scanner. Industry – strength drum scanners use a different technology that relies on a photomultiplier tube (PMT) but this type of scanner is much more expensive than the more common CCD – based scanners. Resolution The denser the bit map, the higher the resolution.
Typically, scanners
support resolutions from 72 to 600 dots per inch (dpi). Bit depth
The number of bits used to represent each pixel. The greater the bit depth,
the more colors or grayscales can be represented. For example, a 24-bit color scanner can th
represent 2 to the 24 power (16.7 million) colors. Note, however, that a large color range is useless if the CCD arrays are capable of detecting only a small number of distinct colors. Size and shape Some scanners are small hand-held devices that you move across the paper. These hand- held scanners are often called half-page scanners ,which are adequate for small pictures and photos, but they are difficult to use if you need to scan an entire page of text or graphics. Larger scanners include machines into which you can feed sheets of paper. These are called sheet-fed scanners. Sheet-fed scanners are excellent for loose sheets of paper, but they
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS are unable to handle bound documents.
16
A second type of large scanner, called a flatbed
scanner, is like a photocopy machine. It consist of a board on which you lay books, magazines, and other documents that you want to scan. DIGITAL CAMERA Images can be input into a computer using a digital camera. These images can then be manipulated in many ways using the various imaging tools available. The digital camera takes a still photograph, stores it, and then sends it as digital input into the computer. The images are then stored as digital files. MAGNETIC INK CHARACTER RECOGNITION (MICR) Magnetic Ink Character Recognition (MICR) allows the computer to recognize characters printed using magnetic ink. MICR is a direct-entry method used in banks. This technology is used to automatically read those frustrating – looking numbers on the bottom of the cheque. A special –purpose machine known as a reader/sorter reads characters made of ink containing magnetized particles. A related technology is the magnetic strip, used on the back of credit cards and bank debit cards, that allows readers such as Automated Teller Machines (ATMs) to read account information and facilitate monetary transactions.
Another example of magnetic strip
technology is in ID cards, which can be used for a variety of functions from attendance monitoring to restricting access to specific locations. OPTICAL CHARACTER RECOGNITION (OCR) Often abbreviated OCR, optical character recognition refers to the branch of computer science that involves reading text from paper and translating the images into a form that the computer can manipulate (for example, into ASCII codes). An OCR system enables you to take a book or a magazine article and feed it directly into an electronic computer file. All OCR systems include an optical scanner for reading text, and sophisticated software for analyzing images. Most OCR systems use a combination of hardware (specialized circuit boards) and software to recognize characters, although some inexpensive systems do it entirely through software. Advanced OCR systems can read text in a large variety of fonts, but they still have difficulty with handwritten text. OPTICAL MARK RECOGNITIO0N (OMR) Optical Mark Recognition (OMR) also called mark sensing is a technology where an OMR device senses the presence or absence of a mark, such as a pencil mark. OMR is used in tests such as aptitude tests. BAR CODE READER You are probably familiar with the bar code readers in supermarkets, bookshops, etc. Bar code readers are photoelectric scanners that read the bar codes, or vertical zebra striped marks, printed on product containers. Supermarkets use a bar code system called the Universal Product Code (UPC). The bar code identifies the product to the supermarket’s computer, which
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
17
has a description and the latest price of the product. The computer automatically tells the POS (Point Of Sales) terminal what the price is. SPEECH INPUT DEVICES Speech or voice input devices convert a person’s speech into digital form. These input devices, when combined with appropriate software, form voice recognition systems.
These
systems enable users to operate microcomputers using voice commands. Some of these systems must be ‘trained ’ to the particular user’s voice. This is done by his/her spoken words to patterns previously stored in the computer. More advanced systems that can recognize the same word spoken by many different people have been developed. However, until recently the list of words has been limited. A newly developed voice recognition system like IBM Voice Type identifies more than 30,000 words and adapts to individual voices. There are even systems that will translate from one language to another, such as from English Japanese. There are two types of voice recognition systems:
Continuous Speech
Discrete – Word
Continuous Speech Continuous speech recognition systems are used to control a microcomputer’s operations and to issue commands to special application programs. For example, rather than using the keyword to save a spreadsheet file, the user could simply say “Save the file”. Two popular systems are Apple Computer’s Plain Talk and IBM’s continuous speech series. Discrete – word A common activity in business is preparing memos and other written documents. Discrete – word recognition systems allow users to dictate directly into a microcomputer using a microphone. The microcomputer stores the memo in a word processing file where it can be revised later or directly printed out. IBM Voice Type Simply Speaking is an example. TOUCH SCREEN Touch screen is a type of display screen that has a touch-sensitive transparent panel covering the screen. Instead of using a pointing device such as a mouse or light pen, you can use your finger to point directly to objects on the screen. Although touch screens provide a natural interface for computer novices,
they are
unsatisfactory for most applications because the finger is such a relatively large object. It is impossible to point accurately to small areas of the screen. In addition, most users find touchscreens tiring to the arms after long use. TOUCH PAD A small, touch – sensitive pad used as a pointing device on some portable computers. By moving a finger or other object along the pad, you can move the pointer on the display screen.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
18
LIGHT PEN Light pen is an device that utilizes a light – sensitive detector select objects on a display screen. A light pen is similar to a mouse, expect that with a light pen you can move the pointer and select objects on the display screen by directly pointing to the objects with the pen. OUTPUT DEVICES INTRODUCTION Output is anything that comes out of a computer. An output device is any machine capable of representing information from a computer. Output devices include display screens, loudspeakers, printers, plotters, etc.
MONITOR Monitor is another term for the display screen. The term monitor, however, usually refers to the entire box, whereas display screen can mean just the screen. CLASSIFICATION OF MONITORS – BASED ON COLOUR There are many ways to classify monitors.
The most basic is in terms of colour
capabilities, which separates monitors into three classes. Monochrome Monochrome monitors actually display two colours, one for the background and one for the foreground. The colours can be black and white, green and black, or amber and black. and white, green and black, or amber and black. Gray – scale A gray – scale monitor is a special type of monochrome monitor capable of displaying different shades of gray. Colour Colour monitors can display anywhere from 256 to over 1 million different colours. Colour monitors are sometimes called RGB monitors because they accept three separate signals – red, green, and blue.
All colour computer monitors are RGB monitors. An RGB monitor
consists of a vacuum tube with three electron guns – one each for red , green, and blue at one end and the screen at the other end. The three electron guns fire electrons at the screen, which contains a phosphorous coating. When the electron beams excite the phosphors, they glow. Depending on which beam excites them, they glow red, green, or blue. Ideally, the three beams should converge for each point on the screen so that each pixel is a combination of the three colours. Colour and gray – scaling monitors are often classified by the number of bits they use to represent each pixel. For example, an 8- bit monitor each pixel with 8 bits. The more bits per pixel, the more colours and shades of gray the monitor can display.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
19
CLASSIFICATION MONITORS â&#x20AC;&#x201C; BASED ON SIGNALS: Another common way of classifying is in terms of the type of signal they accept; analog or digital. Digital Monitor A digital monitor accepts digital signals rather than analog signals. All monitors (except flat- panel displays) use CRT technology, which is essentially analog. The term digital, therefore, refers only to the type of input received from the video adapter. A digital monitor then translates the digital signals into analog signals that control the actual display. Although digital monitors are fast and produce clear images, they cannot display variable colours continuously.
Consequently, only low-quality video standards such as MDA
(Monochrome Display Adepter), CGA (Colour/Graphics Adapter), and EGA (Enhanced Graphics Adapter), specify digital signals. VGA (Video Graphics Array) and SVGA (Super VGA), on the other hand, require an analog monitor. Some monitors are capable of accepting either analog or digital signals. Analog Monitor This is the traditional type of colour display screen that has been used for years in televisions. In reality, all monitors based on CRT technology (that is, all monitors except flatpanel displays) are analog. Some monitors, however, are called digital monitors because they accept digital signals from the video adapter.
EGA monitors, for example, must be digital
because the EGA standard specifies digital signals. Digital monitors must nevertheless translate the signals into an analog form before displaying images. Some monitors can accept both digital and analog signals. Some monitors have fixed frequency, which means that they accept input at only one frequency. Another type of monitor, called a multiscanning monitor, automatically adjusts to the frequency of the signals being sent to it. This means that it can accept input from different types of video adapters. Like fixed â&#x20AC;&#x201C; frequency monitors, multiscanning monitors accept TTL, analog, or both types of input. CHARACTERISTICS OF A MONITOR: Size The most important aspect of a monitor is its screen size. Like televisions, screen sizes are measured in diagonal inches, the distance from one corner to the opposite corner diagonally. A
typical size for small VGA monitors is 14 inches.
Monitors that are 16 or more inches
diagonally are often called full- page monitors. In addition to their size, monitors can be either portrait (height greater than width)
or landscape (width greater than height). Larger landscape
monitors can display two full pages, side by side. Resolution The resolution of a monitor indicates how densely the for Picture Element.
pixels are packed. Pixel is short
A pixel is a single point in a graphic image. Graphics monitors display
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
20
pictures by dividing the display screen into thousands (or millions) of pixels, arranged in rows and columns. The number of bits used to represent each pixel determines how many colours or shades of gray can be displayed. For example an 8- bit colour monitor uses 8 bits for each pixel, th
making it possible to display 2 to the 8 power (256) different colours or shades of gray. On colour monitors, each pixel is actually composed of three dots – a red, a blue, and a green one. The quality of a display monitor largely depends on its resolution, how many pixels it can display, and how many bits are used to represent each pixel. VGA monitors display 640 by 480, or about 300,000 pixels.
In contrast, SVGA monitors display 1,024 by 768, or nearly
800,000 pixels. Most modern monitors can display 1024 by 768 pixels, the SVGA standard. Some high – end models can display 1280 by 1024, or even 1600 by 1200. Bandwidth The amount of data that can be transmitted in a fixed amount of time. For digital devices, the bandwidth is usually expressed in bits or bytes per second (bps). For analog devices, the bandwidth is expressed in cycles per second, or Hertz (Hz).
Refresh Rate Display monitors must be refreshed many times per second. The refresh rate determines hoe many times per second the screen is to be refreshed (redrawn). The refresh rate for a monitor is measured in hertz (Hz) and is also called the vertical frequency or vertical refresh rate. The old standard for monitor refresh rates was 60 Hz, but a new standard developed by VESA sets the refresh rate at 75Hz for VGA and SVGA monitors. The faster the refresh rate, the less the monitor flickers. Interlaced or Non – interlaced Interlacing is a display technique that enables a monitor to provide more resolution in expensively. With interlacing monitors, the electron guns draw only half the horizontal lines with each pass (for example, all odd lines on one pass and all even lines on the next pass). Because an interlacing monitor refreshes only half the lines at one time, it can display twice as many lines per refresh cycle, giving it greater resolution. Another way of looking at it is that interlacing provides the same resolution as non-interlacing, but less expensively.
A shortcoming of
interlacing is that the reaction time is slower, so programs that depend on quick refresh rates (animation and video, for example), may experience flickering or streaking. Given two monitors that offer the same resolution, the non – interlacing one will generally be better. Dot – pitch A measurement that indicates the vertical distance between each pixel on a display screen.
Measured in millimeters, the dot pitch is one of the principal characteristics that
determine the quality of display monitors.
The dot pitch of colour monitors for personal
computers ranges from about 0.15 mm 0.30mm. Another term for dot pitch is phosphor pitch.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS Convergence Convergence refers to how sharply an individual colour pixel on a monitor appears. Each pixel is composed of three dots â&#x20AC;&#x201C; a red, blue, and green one. If the dots are badly misconverged, the pixel will appear blurry. All monitors have some convergence errors, but they differ in degree. VIDEO STANDARDS There are a variety of video standards that define resolution and colours for displays. Support for a graphics standard is determined by both the monitor and the video adapter. The monitor must be able to show the resolution and colours defined by the standard, and the video adapter must be capable of transmitting the appropriate signals to the monitor. Listed here, in approximate order of increasing power and sophistication, are the more popular video standards for PCs. Note that many of these numbers represent only the minimums specified in the standards. Many suppliers of video adapters provide greater resolution and more colours. For more information, refer to the entries for the specific graphics systems given in table 9.1.
VGA Abbreviation of video graphics array, a graphics display system for PCs developed by IBM. VGA has become one of the de facto standards for PCs. In text mode, VGA systems provide a resolution of 720 by 400 pixels. In graphics mode, the resolution is either 640 by 480 (with 16 colours) or 320 by 200 (with 256 colours). The total palette of colours is 262,144.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
21
MATHEMATICAL FOUNDATION OF CS
22
SVGA Short for Super VGA, a set of graphics standards designed to offered greater resolution than VGA. There are several varieties of SVGA, each providing a different resolution:
800 by 600 pixels
1024 by 768 pixels
1280 by 1024 pixels
1600 by 1200 pixels
All SVGA standards support a palette of 16 million colours, but the number of colours that can be displayed simultaneously is limited by the amount of video memory installed in a system. 8514/A A high – resolution video standard for PCs developed by IBM in 1987. It was designed to extend the capabilities of VGA. The 8514/A standard provides a resolution of 1,024 by 768 pixels, which gives it about 2.5 times the pixels of VGA (640 by 480). Like VGA, 8514/A provides a palette of 262,000 colours, of which 256 can be displayed at one time.
On
monochrome displays, 8514/A provides 64 shades of gray. XGA Short for extended graphics array, a high – resolution graphics standard introduced by IBM in 1990. XGA was designed to replace the order 8514/A video standard. It provides the same resolutions (640 by 480 or 1024 by 768 pixels), but supports more simultaneous colours (65 thousand compared to 8514/A’s 256 colours). In addition, XGA allows monitors to be non – interlaced.
TI 34010 TI 34010 is a video standard from Texas Instruments that supports a resolution of 1,024 by 768. TI 34010 conforms to TI’s Graphics Architecture (TIGA ). Unlike IBM’s 8514/A, which supports the same resolution. TI 34010 is non – interlaced.
PRINTER Printer is a device that prints text or illustrations on paper and in many cases on transparencies and other media. There are many different types of printers. In terms of the technology utilized, printers fall into the following categories. Daisy – wheel Printer Daisy – wheel printers are a type of printer that produces letter- quality type. A daisy – wheel printer works on the same principles as a ball – head typewriter. The daisy wheel is a disk made of plastic or metal on which characters stand out in relief along the outer edge. To print a character, the printer rotates the disk until the desired letter is facing
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
23
the paper. Then a hammer strikes the disk, forcing the character to hit an ink ribbon, leaving an impression of the character on the paper.
You can change the daisy wheel to print
different fonts. Daisy – wheel printers cannot print graphics, and in general they are noisy and slow, printing from 10 t about 75 characters per second. Dot – matrix Printer Dot – matrix printers create characters by striking pins against an ink ribbon. Each pin makes a dot, and combinations of dots form characters and illustrations.
Dot-
matrix printers are inexpensive and relatively fast, but they do not produce high – quality output. Dot – matrix printers vary in two important characteristics:
Speed – Given in characters per second (cps), the speed can vary from about 50 to over 500 cps.
Print quality – Determined by the number of pins (the mechanisms that , print the dots), it can vary from 9 to 24. The best dot– matrix printers (24 pins) can produce near letter- quality type, although you can still see a difference if you look closely.
Ink – jet Printer Ink – jet printers work by sparing ionized ink at a sheet of paper. Magnetized plates in the ink’s path direct the ink onto the paper in the paper in the desired shapes. Ink – jet printers are capable of producing high quality print approaching that produced by laser printers. A typical ink- jet printer provides a resolution of 300 dots per inch. The price of ink – jet printers is lower than that of laser printers. However, they are also considerably slower. Another drawback of ink – jet printers is that they require a special type of ink that is apt to smudge on inexpensive copier paper. Laser Printer Laser printer utilizes a laser b4eam to produce an image on a drum. The light of the laser alters the electrical charge on the drum wherever it hits. The drum is then rolled through a reservoir of toner, which is picked up by the charged portions of the drum. Finally, the toner is transferred to the paper through a combination of heat and pressure. Because an entire page is transmitted to a drum before the toner is applied. Laser printers are sometimes called page printers. There are two other types of page printers that fall under the category of laser printers even though they do not use lasers at all. One uses an array of LEDs to expose the drum, and the other uses LCDs. Once the drum is charged, however, they both operate like a real laser printer. One of the chief characteristics of laser printers is their resolution – how many dots per inch (dpi) they lay down. The available resolutions range from 300 dpi at the low end to 1,200 dpi at the
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS high end. By comparison, offset printing usually prints at 1,200 or 2,400 dpi. Some laser printers achieve higher resolutions with special techniques known generally as resolution enhancement. In addition to the standard monochrome laser printer, which uses a single toner, there also exist colour laser printers that use four toners to print in full colour. Colour laser printers tend to be about five to ten times as expensive as their monochrome siblings. Laser printers produce very high – quality print and are capable of printing an almost unlimited variety of fonts. Most laser printers come with a basic set of fonts, called internal or resident fonts, but you can add additional fonts in one of two ways:
Font cartridges – Laser printers have slots in which you can insert font cartridges, ROM boards on which fonts have been recorded. The advantage of font cartridges is that they use none of the printer’s memory.
Soft fonts – All laser printers come with a certain amount of RAM memory, and you can usually increase the amount of memory by adding memory boards in the printer’s expansion slots. You can then copy fonts from a disk to the printer’s RAM. This is called downloading fonts. A font that has been downloaded is often referred to as a soft font, to distinguish it from the hard fonts available on font cartridges. The more RAM a printer has, more fonts that can be downloaded at one time.
LCD & LED Printers Similar to a laser printer but uses liquid crystals or light – emitting diodes rather than a laser to produce an image on the drum. Line Printer Line printers are high speed printers capable of printing an entire line at one time. A fast line printer can print as many as 3,000 lines per minute. The disadvantages of line printers are that they can print only one font, they cannot print graphics, the print quality is low, and they are very noisy. Thermal printer Thermal printers are printers that produce images by pushing electrically heated pins against special heat- sensitive paper. Thermal printers are inexpensive and are used in most calculators and many fax machines. They produce low- quality print, and the paper tends to curl and fades after a few weeks or months. Printers are also classified according to the following characteristics:
Quality of type – Type output produced by printers is said to be either letter quality (as good as a typewriter), near letter quality, or draft quality. Only daisy - wheel, ink – jet, and laser printers produce letter- quality type. Some dot –matrix printers claim letter – quality print, but if you look closely, you can see the difference.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
24
MATHEMATICAL FOUNDATION OF CS
Speed – Measured in characters per second (cps) or pages per minute (ppm), the speed of printers varies widely. Daisy – wheel printers tend to be the slowest, printing about 30 cps. Line printers are fastest (up to 3,000 lines per minute). Dot – matrix printers can print up to 500 cps, and laser printers range from about 4 to 20 text pages per minute.
Impact or non – impact – Impact printers include all printers that work by striking an ink ribbon. Daisy – wheel, dot – matrix, and line printers are impact printers. Non – impact printers include laser printers and ink – jet printers. The important difference between impact and non – impact printers is that impact printers are much noisier but are useful for making multiple copies like carbon copies.
Graphics – Some printers (daisy – wheel and line printers) can print only text. Other printers can print both text and graphics.
Fonts – Some printers, notably dot –matrix printers, are limited to one or a few fonts. In contrast, laser and ink – jet printers are capable of printing an almost unlimited variety of fonts. Daisy – wheel printers can also print different fonts, but you need to change the daisy wheel, making it difficult to mix fonts in the same document.
PLOTTER Plotter is a device that draws pictures on paper based on commands from a computer. Plotters differ from printers in that they draw lines using a pen. As a result, they can produce continuous lines, whereas printers can only simulate lines by printing a closely spaced series of dots. Multicolour plotters use different – coloured pens to draw different colours. In general, poltters are considerably more expensive than printers. They are used in engineering applications where precision is mandatory. SOUND CARDS & SPEAKERS An expansion board that enables a computer to manipulate and output sounds. Sound cards are necessary for nearly all CD-ROMs and have become commonplace on modern personal computers.
Sound cards enable the computer to output sound through speakers
connected to the board, to record sound input from a microphone connected to the computer, and ,manipulate sound stored on a disk. Nearly all sound cards support MIDI, a standard for representing music electronically. In addition, most sound cards are Sound Blaster – compatible, which means that they can process commands written for a Sound Blaster care, the de facto standard for PC sound. Sound cards use two basic methods to translate digital data into analog sounds:
FM (Frequency Modulation) Synthesis mimics different musical instruments according to built – in formulas.
Wavetable Synthesis relies on recordings of actual instruments to produce sound. Wavetable synthesis produce more accurate sound, but is also more expensive.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
25
MATHEMATICAL FOUNDATION OF CS
26
3D Audio 3D audio is a technique for giving more depth to traditional stereo sound. Typically, 3D sound, or 3D audio, is produced by placing a device in a room with stereo speakers. The device dynamically analyzes the sound coming from the speakers and sends feedback to the sound system so that it can readjust the sound to give the impression that the speakers are further apart. 3D audio devices are particularly popular for improving computer audio where speakers tend to be small and close together. There are a number of 3D audio devices that attach to a computer’s sound card. AUXILIARY STORAGE DEVICES INTRODUCTION Auxiliary storage also known as auxiliary memory or secondary storage, is the memory that supplements the main storage. This is a long – term, non – volatile memory. The term non – volatile means it stores and retains the programs and data even after the computer is switched off. Unlike RAM which looses the contents when the computer is turned off, and ROM, to which it is not possible to add anything new, auxiliary storage devices allows the computer to record information semi – permanently, so it can be read later by the same computer or by another computer. Auxiliary storage devices are also useful in transferring data or programs from one computer to another. They also function as back – up devices which allows to back – up the valuable information that you are working on.
So even if by some accident your computer
crashes and the data in it is unrecoverable, you can restore it from your back – ups. The most common types of auxiliary storage devices are magnetic disks, floppy disks, hard disks, etc. There are two types of auxiliary storage devices. This classification is based on the type of data access: sequential and random. Based on the type of access they are called sequential – access media and random – media. In the case of sequential – access media, the data stored in the media can only be read in sequence and to get to a particular point on the media you have to go through all the preceding points. Magnetic tapes are examples of sequential access media. In contrast, disks are random access also called direct access media because a disk drive can access any point at random without passing through intervening points.
Other examples of direct
access media are
magnetic disks, optical disks, zip disks etc. MAGNETIC TAPE Magnetic tape is a magnetically coated strip of plastic on which data can be encoded. Tapes for computers are similar to the tapes used to store music. Some personal computers, in fact, enable you to use normal cassette tapes. Storing data on tapes is considerably cheaper than storing data on disks. Tapes also have large storage capacities, ranging from a few hundred kilobytes to several gigabytes.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
27
Accessing data on tapes, however, is much slower than accessing data on disks. Tapes are sequential access media, which means that to get to a particular point on the tape, the tape must go through all the preceding points. In contrast, disks are random access media because a disk drive can access any point at random without passing through intervening points. Because tapes are so slow, they are generally used only for long – term storage and backup. Data to be used regularly is almost always kept on a disk. Tapes are also used for transporting large amounts of data. Tapes come in a variety of sizes and formats (see table 10.1). Tapes are sometimes called streamers or streaming tapes. Type
Capacity
Description Half – inch tapes come both as 9 track reels and as
Half – inch
60 MB – 400 MB
cartridges. These tapes are relatively cheap, but require expensive tape drives. Quarter – inch cartridges (QIC tapes) are relatively inexpensive and support fast
Quarter – inch
40 MB – 5 GB
data transfer rates. QIC mini cartridges are even less expensive, but their data capacities are smaller and their transfer rates are slower. 8-mm helical – scan cartridges use the same technology as VCR tapes and have the
8-mm Helical – scan
1GB – 5GB
greatest capacity. But they require expensive tape drivers and have relatively slow data transfer rates. DAT (Digital Audio Tape) cartridges have the greatest
4-mm DAT
2GB-24G B
capacity but they require expensive tape drivers and have relatively slow data transfer rates.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
28
Helical – scan Cartridge A type of magnetic tape that uses the same technology as VCR tapes. The term helical scan usually refers to 8-mm tapes, although 4-mm tapes (called DAt tapes ) uses the same technology. The 8-mm helical – scan tapes have data capacities from 2.5GB to 5GB. DAT
Cartridge DAT (Digital Audio Tape) is a type of magnetic tape that uses an ingenious scheme
called helical scan to record data. A DAT cartridge is slightly larger than a credit card and contains a magnetic tape, that can hold from 2 to 24 gigabytes of data. It can support data transfer rates of about 2 MBps (Million bytes per second). Like other types of tapes, DATs are sequential – access media. The most common format for DAT cartridge is DDS (digital data storage) which is the industry standard for digital audio tape (DAT) formats. The latest format, DDS-3, specifies tapes that can hold 24 GB (the equivalent of over 40 CD-ROMs) and support data transfer rates of 2 MBps. WINCHESTER DISK The term Winchester comes from an early type of disk drive developed by IBM that stored 30 MB and had a 30– millisecond access time; so its inventors named it a Winchester in honor of the 30-caliber rifle of the same name. Although modern disk drives are faster and hold more data, the basic technology is the same, so Winchester has become synonymous with hard disk. HARD DISK Hard disk is a magnetic disk on which you can store computer data. The hard is used to distinguish it from a soft, or floppy, disk. Hard disks hold more data and are faster than floppy disks. A hard disk, for example, can store anywhere from 10 megabytes to several gigabytes, whereas most floppies have a maximum storage capacity of 1.4 megabytes. A single hard disk usually consists of several platters.
Each platter requires two
read/write heads, one for each side. All the read/write heads are attached to a single access arm so that they cannot move independently. Each platter has the same number of tracks, and a track location that cuts across all platters is called a cylinder. For example, a typical 84 megabyte hard disk for a PC might have two platters (four sides) and 1,053 cylinders In general, hard disks are less portable than floppies, although it is possible to buy removable hard disks. There are two types of removable hard disks : disk packs and removable cartridges.. FLOPPY DISK Floppy disk is a soft magnetic disk. It is called floppy because it flops if you wave it (at least, the 5
1/4
– inch variety does). Unlike most hard disks, floppy disks (often called floppies or
diskettes) are portable, because you can remove them from a disk drive. Disk drives for floppy
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS disks are called floppy drives. Floppy disks are slower to access than hard disks and have less storage capacity, but they are less expensive and are portable. Floppies come in two basic sizes:
5
1/4
– inch – The common size for PCs made before 1987. This type of floppy is
generally capable of storing between 100K and 1.2 MB (megabytes) of data. The most common sizes are 360 K and 1.2MB.
3
1/2_
inch – Floppy is something of a misnomer for these disks, as they are
encased in a rigid envelope. Despite their small size, microfloppies have a larger storage capacity than their cousins – from 40K to 1.4MB of data. The most common sizes for PCs are 720K (double - density) and 1.44MB (high- density). Macintoshes support disks of 400K, 800K, and 1.2MB. ZIP DISK These are high – capacity floppy disk drives developed by the Iomega Corporation. Zip disks are slightly larger than the conventional floppy disks, and are about twice as thick. They can hold 100MB of data. Because they’re relatively inexpensive and durable, they have become a popular media for backing up hard disks and for transporting large files. JAZ DISK These are removable disk drivers developed by the Iomega Corporation. The Jaz drive has a 12-ms average seek time and a transfer rate 5.5 Mbps .The removable cartridges hold 1GB of data. The fast rates and large storage capacity make it a viable alternative for backup storage as well as everyday use.
SUPER DISK This is a new disk storage technology developed by the Imation Corporation that supports very high-density diskettes. SuperDisk diskettes are etched with a servo pattern at the factory. This pattern is then read by the SuperDisk drive to precisely slign the read/write head. The result is that a SuperDisk diskette can have 2,490 tacks, as opposed to the 135 tacks that conventional 3.5 – inch 1.44 MB diskettes use. This density translates into 120MB capacity per diskette. OPTICAL DISK Optical Disks are a storage medium from which data is read and to which it is written by lasers.
Optical disks can store much more data – up to 6 gigabytes (6 billion bytes)- than
magnetic media, such as floppies and hard disks. There are three basic of optical disks:
CD-ROM - Like audio CDs, CD-ROMs come with data already encoded onto them. The data is permanent and can be read any number of times, but CD-ROMs cannot be modified.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
29
MATHEMATICAL FOUNDATION OF CS
30
WORM – This term stands for write – once, read many. With a WORM disk drive, you can write data onto a WORM disk, but only once. After that, the WORM disk behaves just like a CD-ROM.
Erasable - Optical disks that can be erased and loaded with new data, just like magnetic disks. These are often referred to as EO (erasable optical) disks.
CD – ROM CD – ROM, which is pronounced as ‘see – dee - rom’, is the abbreviation of Compact Disc – Read – Only Memory. CD – ROM is a type of optical disk capable of storing large amounts of data - up to 1GB, although the most common size is 630 MB (megabytes). A single CD – Rom has the storage capacity of 700 floppy disks, enough memory to store about 300,000 text pages. CD – ROMs are recorded by the vendor, and once recorded, they cannot be erased and filled with new data. To read a CD, you need a CD – ROM player. Also called a CD – ROM drive, a CD – ROM player is a device that can read information from a CD – ROM. There are a number of features that distinguish CD – ROM players, the most important of which is probably their speed. CD– Rom players are generally classified as single – speed or some multiple of single – speed. For example, a 4X player access data at four times the speed of a single – speed player. Within these groups, however, there is some variation. Also, you need to be aware of whether the CD – ROM uses the CLV (Constant Linear Velocity) or CAV (Constant Angular Velocity) technology. Two more precise measurements are the drives seek time and data transfer rate. The seek time, also called the access time, measures how long, on average; it takes the drive to access a particular piece of information. The data transfer rate measures how much data can be read and sent to the computer in a second. Most CD –ROMs connect via a SCSI bus. Other CD – ROMs connect to an IDE or enhanced IDE interface, which is the one used by the hard disk drive.
CD – ROMs are
particularly well suited to information that requires large storage capacity. This includes color graphics, sound, and especially video. CD – R Drive CD – R drive which is short for Compact Disk – Recordable drive, is a type of disk drive that can create CD- ROMs and audio CDs. This allows the users to “master” a CD – Rom or audio CD for publishing. Until recently, CD – R drives were quite expensive, but prices have dropped dramatically. A feature of many CD – R drives, called multisession recording, enables you to keep adding data to a CD – ROM over time. This is extremely important if you want to use the CD – R drive to create backup CD – ROMs.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS To create CD – ROMs and audio CDs, you’ll need not only a CD – R drive, but also a CD – R software package .Often, it is the software package, not the drive itself that determines how easy or difficult it is to create CD – ROMs. CD – R drives can also read CD – ROMs and play audio CDs. CD – RW Disks CD – RW disk is short for CD Rewritable disk and this is a new type of CD disk that enables you to write onto it in multiple sessions. One of the problems with CD – R disks is that you can only write to them once. With CD – RW drives and disks, you can treat the optical disk just like a floppy or hard disk, writing data onto it multiple times. The first CD – RW drives became available in mid – 1997. They can read CD– ROMs and can write onto today’s CD – R disks, but they cannot write on CD – ROMs. Many experts believe that they’ll be a popular storage medium.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
31
MATHEMATICAL FOUNDATION OF CS
UNIT â&#x20AC;&#x201C; II FLOW CHARTS Definition:A flow chart is a pictorial form of a sequence conditions are to be tested and calculations performed for solving the problem.
Decision table:Decision table is a table representation of conditions to be tested and actions to be performed for a successful solution to a problem.
FLOWCHART SYMBOLS: (1) Input output statements: Parallelograms are used to represent the input and output symbols.
(2) Processing operation symbol: Rectangles are used to indicate any processing operation such as storage and arithmetic calculations.
(3) Test condition symbol: Diamond shaped boxes are used to indicate the conditions are checked that is question and answer type [true or false]. (4) Start and end symbol: The rounded rectangles are used to indicate the start and end of the procedure.
(5) Connector symbols: A circle is used to join the different parts of flow charts. This is called connector. Whenever we use the connector, we will give the same identifying letter or digit inside both of the circles. (6) Direction symbol: The arrows are indicate the direction to be followed in a flowchart. Every line in a flow chart have an arrow on it.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
32
MATHEMATICAL FOUNDATION OF CS
A simplified model of a computer:The simplified model of a computer used to understand how procedures are executed by a computer.
MEMORY PART: In this part, the part of a memory is reserved to store the flowchart .The rest of the memory consists of a number of boxes for storing data. The each box may be assigned a name. The data in a box may be accessed by the referring the name. When a data stored in a box, the old content of the box will be destroyed.
OBEDIENT SERVANT: This part is used to reading the flowchart and faithfully carrying out the instructions in the program.
INPUT AND OUTPUT UNIT: The units which are used to read the data is input unit. The units which are use do print the results are called output unit. PROCESING UNIT: This unit is used to calculate the arithmetic calculations and logical operations.
EXAMPLE OF USING MODEL: The flowcharts are stored in the main memory boxes. It require to solve the problem is kept ready at the input unit. The diagram shows the data stored in the memory. The obedient servant starts the blocks to ready for the instructions .The read values are stored in the storage box one by one in different names.
FORTRAN PROGRAM IN PRELIMINARIES
HIGHER LEVEL LANGUAGES FOR COMPUTERS:-
(1)
Machine language instructions: A computer can interpret and execute a set of coded instructions called machine
language instructions. A set of three instructions to add the numbers and store the number means we need operation code and operand (memory location) .
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
33
MATHEMATICAL FOUNDATION OF CS
34
(2) High level languages: The instructions in the high level languages are not coded numbers. They are ordinary English statements. It is easy to learn and use.
Compiler or language processor: All high level programs are translated into machine language. This translating program is called compiler or a language processor. The resulting program is called the object program. The original program written in the high level languages is called source program.The translators are different leading to different machine language equivalents of source program.
Machine independent language: A high level language can be designed, it can be used by that model only (manufacturing model). Such a language is also known as machine independent language.
Syntax rules:A high level machine independent language has to be translated by a computer program, to define the rules for waiting instructions in that language. These are the syntax rules of language.
FORTRAN LANGUAGE
It is a high level language used to solve the numerical problems .FORTRAN stands for => FORmula TRANSlation .The FORTRAN introduced by John Backus in 1956-1957. The versions of FORTRAN are WATFOR and WATFIV. In 1977 and 1978 the ANSI standard released the standard version. Description of programming language: In alphabets learning ď&#x192; words ď&#x192; sentences. In programming languages, the syntactic definition on how to combine the characters to form the syntactic units. Characters used in FORTRAN: The following set is allowed. Characters are in the FORTRAN 77. (i)
Letters:
Capital
(upper
case)
letter
of
English:
A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z. (ii)
Decimal digits: 0,1,2,3,4,5,6,7,8,9
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS (iii)
35
Special characters: +, -, ., ), $, *, (, =, ’, ; and blank (1).
FORTRAN CONSTANTS AND VARIABLES
FORTRAN CONSTANTS: A number which does not change during the execution of the program is called a FORTRAN constant.
Classification:It has 2 types 1. Integer constants. 2. Real constants.
(i) Integer constants:Whole numbers out any fractional parts. Rules: (i)
An integer must have at least one digit and must be written without a decimal point. It will followed by + or – sign. There is no sign, it will assume to be positive. Example: Valid constants
Invalid constants
(i) 12345
(i) 11. (. not allowed)
(ii) -98
(ii) +-452 (2 sign not allowed) (iii) $125($ currency sign is not allowed)
The largest integer constant depends on the computer being used.
(ii) Real constant:It is also known as floating point constants. It contains the fractional part or the exponent form.
Rules: (i) In this fractional form, it contains the only one digit and written with the decimal point. It has also followed by + or – sign. No symbol means, it will automatically assumed by +.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
Example: Valid
Invalid
(i) 1.5
(i) 1- (decimal point miss)
(ii) -.5678
(ii) -1/2- (symbol / illegal)
(iii)-.001
(iii) 1,234- (comma not allowed)
The exponent notation for real constants provide the facility that indicating (i)
.58E7
(ii)
A constant in the exponent form consists of a mantissa and exponent. The mantissa
must have at least one digit and a decimal point. It is followed by the letter E and the exponent. The sign for exponent is optional. Example: Valid
Invalid
(i) 152.E08
(i) 125*E9 (* not allowed)
(ii) 15.2E9
(ii) 125,488 (, not allowed)
FORTRAN VARIABLES: A quantity which may during the program execution is called a variable. The â&#x20AC;&#x2DC;Name Tagâ&#x20AC;&#x2122; is used to store the variable name in the storage location. Classification:It has two types: (i)
Integer variable names.
(ii)
Real variable names.
(i) Integer variables: A number stored in a memory location with an integer variable is an integer variable name. Rules: (i) It is any combination of one to six letters or digits. The first character in the name must be one of the following letters. I, J, K, L, M and N. The name must not contain any character other than letters or digits. Valid
Invalid
(i) N
(i) COUNT (first letter invalid)
(ii) INDX2
(ii) Integer (more than 6 char)
(iii) MASS
(iii) ID-NO (- not allowed)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
36
MATHEMATICAL FOUNDATION OF CS
37
(ii) Real variables: A variable name stored in a location with real variable name with the fractional part. Rules: A FORTRAN read variable name is any combination of one to six letters or digits. The first character in the name must be one of the following letters. A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z. The name must not contain any character other than letters or digits. Valid
Invalid
(i) THETA
(i) MASS (first letter invalid)
(ii) PI
(ii) RS, NP (, not allowed)
(iii) DIG34
(iii) stop. (. not allowed)
TYPE DECLARTIONS FOR INTEGER AND REALS We should give the nature of the variable before it is used in the program. Example: REAL LIFE INTEGER STOP So in this we treated the LIFE as the REAL variable and the STOP as the integer variable. More than one variable can be declared REAL or INTEGER in the same declarations. The variable names are separated by commas and never end with the full stop or comma. Ex:
Invalid statements REAL, LIFE, TAG, (, not allowed after the real) INTEGER REGR. SUM (. not allowed)
ARITHMETIC EXPRESSIONS FORTRAN EXPRESSION: It is a series of variable names and constants, connected by arithmetic operations symbols and exponentiation.
Arithmetic operators and modes for expressions: The symbols used for the arithmetic operations are: FORTRAN
Arithmetic operation
(Operator symbols) +
Addition
-
Subtraction
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS *
38 Multiplication
/
Division
**
Exponential
Arithmetic expressions are formed either by combining integer variable and constants with arithmetic operators or combination of real and constants also. But combining the real and integer quantities in the same equation is not allowed. TYPE OF EXPRESSIONS:(i)
Integer expressions.
(ii)
Real expressions.
(i)
Integer expression: (a) A signed or unsigned integer variable name or an integer constant is an integer expression. Example: -K, -4, +4, 5 (b) An integer expression connected by an arithmetic operator to an unsigned integer variable name or unsigned integer constant is an integer expression. Example: -IA*IB+IC/J (c) An integer expression connected by an arithmetic operator is an integer expression. Example: ( IA+IB ) * ( IC/ID ) Invalid example: IA * -IB (only one operator is allowed between the variable name)
(ii)
Real expression:Rules: (a) A signed or unsigned real variable name or a real constant is a real expression. (ex) -4.5, -ABE (b)
A real expression connected by an arithmetic operator to an unsigned real variables name or unsigned real constants. Example: BA/CA, ATE ** BA
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
(c)
39
A real expression enclosed in parenthesis is a real expression. Example: ( BAT + 3.4 ) ( SUM * 5)
(d)
Two real expressions connected by an arithmetic operator is a real expression. Example: ABC * ALL + SUM, (AB * BC ) / ( DB * AM )
(e)
Two arithmetic operators should not occur in the succession in a real expression.
Valid only for real expression: A real expression may be exponential by an integer expression to form a real expression.
HIERARCHY OF OPERATION IN EXRESSION
Hierarchy or precedence of operation: The value of any expression is calculated by executing one arithmetic operation at a time. The order in which the arithmetic operations are executed in an expression is called the hierarchy. The order is I
** (exponentiation). It will be executed first.
II
* (multiplication), / (division). It has second precedence.
III
+ (addition), - (subtraction). It has last precedence.
Example: A ** B / C + D. B
It will be equivalent to A /C + D. B
B
So the exponentiation is calculated first (A ) then the division is second (A /C) and the last B
statement is addition (A /C+D) All the expressions are evaluated from left to right. Each & every hierarchy is started from left to right c for ex: division is over, then again it searches the left to right for addition.
Unary Minus: A negative sign appearing at the beginning of the arithmetic expression is called Unary Minus. Ex:
-4**2 = - (4**2) = -16.
Use of Paranthesis:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
40
Paranthesis are used if the order of operations done in the hierarchy rules & it will be executed. (a) When the expression has the single paranthesis, that will be evaluated first. Within the paranthesis, the order of rules will be applied. Ex: A*B / (C+D**F/G+H) +E. In this example, the paranthesis expression is evaluated first that is C+D**F/G+H.
Then only the other expressions are calculated. AB --------- + E C+D
F
--- + H G
e innermost paranthesis is evaluated first, then the second most & continue evaluating the rest of the applications. This expression also calculated as left to right order. Ex:
Invalid
(i) 1 / 1+x
.1 / .1+x
(ii) a+b/a-b
A+B -B
Valid
1. / (1+x)
(a+b) / (a-b)
-A
ARITHMETIC
STATEMENTS:
(a) The arithmetic statement has the following form Variable Name = Expression. Ex: TOT = (M1+M2+M3)/3 AVG = TOT/3. (b)
When the arithmetic statement is executed, the expression on the right of the equal sign is first evaluated & the number is stored obtained in the variable name appearing on the left of the equal sign.
(c)
The new value of expression is calculated, the old value stored in the variable name is replaced by new values.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS (d)
41
FORTRAN does not have the signal ().
Modes of Arithmetic Statements: A real variable may be sent equal to an Integer expression and vice-versa. Ex:
J=4, K=2; So
ABE=J/K
here
the
ABE=2.0
value
is
real
so
ABE=2.0.
But
J&K
are
integer (It cannot have fractional part). Defining Variables: A variable is said to be defined if a numerical value has been assigned to it. (Or) If a number has been stored in the storage location corresponding to its name. The variables may be defined by Input Statements Variables name = constant. Ex:
x=4.5, y=3
The value of x is stored in memory constantly, 4.5 & y=3 respectively. (a) The variables appearing on the right of the equal sign is an arithmetic statement are defined & the left side also defined.
Some Problems due to Rounding of Real Numbers: (a) The real numbers are stored in the computers memory with a finite number of mantissa & exponent digits. Computers have around 8 mantissa digit & exponent. Ex: 1.0/3.0 = .33333333 = .333 X= 1.0/3.0 Y=x+x+x Mixed Mode Expressions: In the mixed mode expression, the integers are converted to real before computing. So it is integer expression, it is computed using integer arithmetic I/2*2i+1 (I/2)*X** (2*I+1). (I/2) calculated integer arithmetic. Explicit Type Conversion: A programmer can intentionally change the mode of expressions in an arithmetic statement. (a) The explicit type conversion functions are: (1) FLOAT & IFIX. (i) FLOAT: We write the form. FLOAT (integer expression (or) variable name). Converted into real mode.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
42
(ii) IFIX: IFIX (real expression or variable name) It is converted into integer mode.
SPECIAL FUNCTIONS The simple arithmetic operations on variables. A number of functions are variables. The method of using a function is FUNCTION NAME (Variable name or expression) In this method, the argument of a function may be either in real mode or integer mode depending upon the function being evaluated.
The argument should be enclosed in
parenthesis. If a function has more than one argument the argument are separated by commas. Functions available in FORTRAN: FUNCTION
NAME
(i) Integer to real conversion
Float
(ii) Real to integer conversion
NINT INT
(iii) Absolute value
ABS IABS
(iv) Remainder
AMOD MOD
(v) Transfer of sign
SIGN ISIGN
(vi) Positive difference
DIM
(2 arguments) MATHEMATICAL FUNCTION (i) Exponential
EXP
(ii) Square root
SQRT
(iii) Sine
SIN
(iv) Cosine
COS
(v) Logarithm
ALOG
(vi) Arc Tangent
ATAN
While we use the functions means, we can note the following rules:
A function may be used in arithmetic expression in a way similar to a variable name.
A function may be used as the argument of a function. Ex: SIN (ABS(X))
The mode of function may be either real or integer.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
43
All function appearing in arithmetic expressions are evaluated first.
The angles in the degrees should be converted to radians before these functions are used.
The argument functions return only the principal value, namely a value of the function between ± π / 2.
Examples of use of functions: I. The rounding of a real number R to the nearest integer would be done by the function. Ex: 1.5 should be rounded as IFIX (ABS(R) + 0.5) II. Using the MOD function IABS (MOD (K, 10)) III. The mathematical expressions are converted into the FORTRAN expressions. 1. Log e√x/yz = ALOG (SQRT(X/(Y*Z))). 2
3
2. a cos x + b cos x + c cos x = a* cos (x) + b * cos (x) ** 2 + c cos (x) ** 3.
INPUT OUTPUT STATEMENTS Input statements: To solve a particular problem, it is necessary to transfer the required data from one of its input units to its memory. It is done by the input statements. The READ statement is used to give the input to the terminals. Output statements: After execution of program the results of the computations are to be transferred from the memory of the computer to one of the output units. This is done by the output statements. The PRINT statements are used to give the results on the paper. The input and output statements consists of 2 parts.
Executable part it is used to read into memory or read out of it.
Declarative part gives the information on exact form in which data will be typed or displayed.
List directed or format free: When the format is not specified in the input output statements is called the list directed or format free. 1) List directed input statements: The general form the input statements is READ *, list.
The read
statement causes data to be read from a video terminal and assigned to the variable named in the list.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS Ex: read * , A, B, C. In the READ statements more than one data are designed it will be defined by comma. The points should be remembered, a. No column should be left blank, when type in same order. b. Values (numerals) should be within the range. c.
The exponent should be followed by one number.
d. No value should be split between two lines. (2) List directed output statement: General form: PRINT * LIST. The values of the variables specified in the list to be printed on paper. Ex: PRINT *, X, Y, I. The values are printed in the same line. CONTROL STATEMENTS Normal flow statements: The statements are executed sequentially are written in the program. All the operation specified in the particular statement are executed, the statement appearing on the next line of the program is taken for the execution. This is called as Normal flow statements. Control statements: The normal flow of control will be changed to perform the alternate actions based on the result of testing conditions. There are several control operators available to control the operations.
Relational operations.
Logical IF statements
GOTO statements.
Nested IF statements.
Arithmetic IF statements.
Computed GOTO statements.
Relational operators: The operators used in the expression. An expression formed with relation operators is known as a logical expression. The operators used in the FORTRAN are as follows:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
44
MATHEMATICAL FOUNDATION OF CS MATHEMATICAL
S.NO
SYMBOL
45
MEANING
1.
>
Greater than
2.
≥
Greater than (or)
FORTRAN EQUIVALENT
equal to 3.
<
Less than
4.
≤
Less than (or) equal to
5.
=
Equal to
6.
≠
Not equal to
.GT
.GE .LT
.LE .EQ .NE
Example: A.GE.B (A+B/C) .GE. (C+D+7) Invalid example: i. 2.1 LT. B (Real compared with B) ii. A = C ( = Not valid symbol)
LOGICAL IF STATEMENT The various forms of logical IF statements are available. Form I: Syntax: IF ( e) THEN S1t S2t . . ELSE S1f S2f END IF S. Where e is a logical expression and S1t, S2t, S1f, S2f are FORTRAN statements. Example: IF (A.GT. B) THEN P = Q + 2.2
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS R=S+T ELSE P = Q – 2.2 R = S- T END IF X=W In this above example, (A.GT.B) is e, P = Q + 2.2, R = S + T are S 1t, S2t and P = Q – 2.2, R = S – T are the S1f, S2f statements and X = W is the S. Form II: In sometimes when the logical expression e is true, one would like to execute the true statement only. In that case we use this form. General form: IF (e) THEN S1t S2t . . Snt END IF Ex: IF (P.LT.Q) THEN R=S+T Q=A+B END IF In this form, we only execute the true statements only. Else part is not mentioned here. Form III: In some special cases, the one statement only executed after the THEN statement means, we use the general form, IF (e) THEN S1t END IF Ex: IF (A.GT.B) THEN R=S+T Form IV: In some special cases, we can use the IF statement very simple.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
46
MATHEMATICAL FOUNDATION OF CS General form: IF (e) THEN In this, we can mention the simple form used to declare the single statement in the one line. Ex: IF (A.GT.B) C = D Example: C *** program for largest of 3 numbers using IF, THEN, ELSE. READ *, A, B, C. IF (A.GT.B) THEN IF (A.GT.C) THEN PRINT *, A STOP ELSE PRINT *, C STOP END IF ELSE IF (B.GT.C) THEN PRINT *, B STOP ELSE PRINT *, C STOP END IF END IF END
STATEMENT LABELS Any statement in the FORTRAN may be labeled by a statement number. It is used to refer the statement. Rule 1: A statement number is any unsigned positive non-zero integer between 1 and 99999. A statement number may be written anywhere in the program columns 1 and 5. 1 41
5
7 SUM = SUM + X
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
47
MATHEMATICAL FOUNDATION OF CS Invalid:
15 * (* not valid)
0 ( 0 not valid)
-4 (no sign allowed)
Calc (non numeric not allowed)
2121356 (number more than 5 not allowed)
The same statement number is not allowed.
The statement numbers need not to be in the ascending order. It may be in any order. A statement to unconditionally branch to a labeled statement. This statement breaks the normal sequential execution of a program and branches to a statement with a specified label. Ex:
40 read *, ROLL NO
GOTO STATEMENTS The GOTO statement is used to achieve the unconditional transfer of control to the statement labeled. RULE: The GOTO statement is written in the form GOTO n, when n is the statement number of an executable FORTRAN statement blanks between the GOTO are the optional. The term executable statement in the above rule, a statement which lead to an action, such as arithmetic, assignment, I/O or branching. A non executable statement provides the information only for allocation of storage and input/output format etc. Ex: - Executable statements (i)
TYPE declaration
(ii) END, END IF, ELSE (iii) FORMAT Syntax: GOTO < Label number> Ex: GOTO GOTO 10 Invalid –GOTO: GOTO 0 (0 not allowed) GOTO, 25 (, not allowed) GOTO jump (character not allowed)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
48
MATHEMATICAL FOUNDATION OF CS
NESTED LOGICAL IF STATEMENTS The block of statements between an IF statement and the corresponding ENDIF statement is known as IF BLOCK. Within the IF block, we could use the other IF blocks are used mean, it is called as nested logical IF statement. Syntax: IF (e) THEN S1 ELSE IF (e) THEN S2 ELSE S3 END IF END IF
Ex: IF (A.GT.0) THEN P=1 ELSE IF (B.GT.0) THEN P=2 ELSE P=3 END IF END IF
ARITHMETIC IF STATEMENT The another type of IF statement is called arithmetic IF. In logical IF statement control is transferred based on a condition being true or false. In arithmetic IF statement control is transferred based on an arithmetic expression being negative, zero or positive. It was the first conditional statement in the first version. The general format: IF (a.e) n1, n2, n3 In this a.e is an arithmetic expression and n1 and n2 are the three statement numbers. If the arithmetic expression is negative, control is transferred to statement n 1. if the condition is zero the statement n2 is executed, the condition is positive the statement n3 will be executed.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
49
MATHEMATICAL FOUNDATION OF CS
50
Ex: IF (number, E2. 999) GOTO 50 …………. …………. 50 PRINT *, Number The continue statement is an executable statement which does nothing. It only asks the program to continue execution. Main use of this statement is as a delimiters of a group of statements. Valid
Invalid
IF (I-J) 10, 10, S
IF (A-B) 10, 15 (one statement missing)
COMPUTED GOTO STATEMENT The computed GOTO statement will transfer the control to any code depends upon label number. General form: GOTO (n1, n2…nm), i where n1, n2…..nm are the statement numbers and i is an integer expression. The parenthesis enclosing the statement numbers and the commas separating the statement numbers are required punctuations. The comma following the right parenthesis is optional. This command when executed causes transfer of control to the first statement linked within th
the parenthesis if the value of i is 1, m statement in the list if i equals m. If the value of i is exceeds the total number of statements and it is less than 1, then the control is transferred to the statement immediately following the computed GOTO statement. An unconditional GOTO statement is required to skip the other blocks and join a common point. Each block should start with a CONTINUE and terminate with an unconditional GOTO leading to a common exit point. Ex: IF (I.LT.1) GO TO 20. IF (I.GT.3) GO TO 20. GO TO (5, 10, 15), I. 5
CONTINUE ………………. …………….
10 CONTINUE …………………. ………………. 15 GO TO 50
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS CONTINUE ………….. …………… BLOCK 3. GO TO 20. 20 CONTINUE ……………… ………….. 50 CONTINUE …………........
Points to be checked when using control statements: Statement numbers must be unique. Statement numbers referred to in GOTO, IF and control GOTO must be present. A branching statement must branch to an executable statement. Branching statement should not transfer control inside an IF block. Nesting and logical IF statement needs special attention for carelessness errors. DO STATEMENT Whenever we need to repeat a set of statement we use the DO statement. General Form: DO n = m1, m2, m3. ………………….. n continue. Where n is the statement number, I is an integer variable name and m1, m2, m3 are integer expressions. Form II: DO ni = m1, m2. ……………….. n continue. In this form the m3 is assumed to be 1. The punctuations are required for the statements. The CONTINUE is the last statement. Valid: DO 25 I = 1, 10. DO 50 K =0, -5,-1. Invalid:
DO 30 I = 5.10 (. illegal)
DO 30 I = 20 (I =20 wrong)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
51
MATHEMATICAL FOUNDATION OF CS
DOMAIN or RANGE: The DO statement is a command to execute the set of statements, up to the statement numbered n. This set of statements is called the domain (or) range of DO statement. Ex: READ *, X, K. Y=1. SUM=1. DO 200 N=1, K. Y= Y*X. SUM=SUM+Y. 200 CONTINUE PRINT *, SUM. STOP END.
Rules to be followed in DO LOOP: Enclosed within a domain of a DO LOOP there may be other DO LOOP. A set of DO’s satisfy this rule is called nested DO’s. Nested DO LOOP:
DO 50 I=1, 10 …………….. DO 20 J = 1, 5 ………………. 20 CONTINUE ………….......... 50 CONTINUE Each and every nested DO LOOP statement have the inner DO LOOP, & it has its CONTNUE statement. But avoiding the deep loops. A transfer into the domain of a DO form outside is not permitted. Ex: IF (N.LE.9) GOTO 25 DO 20 I = 1, K 25 DIGIT = MOD (N) S = SUM 20 CONTINUE
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
52
MATHEMATICAL FOUNDATION OF CS The DO LOOP parameter i, m1, m2, & m3 should not be redefined by statements within the domain of the DO LOOP. Ex: DO 20 I = J, K, L K = K* N error (K – not be redefined) 20 CONTINUE The first statement in the domain of a DO must not be a non executable statement namely TYPE, DECLARATION, FORMAT & ETC. Ex:
DO 20 I = 1, K
Error
INTEGER. DIGIT. SUM N=N/5
20 CONTINUE A transfer statement within the domain of a DO LOOP should not lead back to the DO statement itself. Ex: 20 READ *, DATA Error
IF (DATA.NE.0) GOTO 20 Zero = Zero + 1
25 CONTINUE The terminal statement of a DO LOOP must be an executable statement, but must not lead to a transfer of control. The last statement should not be a GOTO, COMPUTED GOTO, an ARITHMETIC IF, STOP & another DO statement. Ex: DO 25 SERIAL = 1, N 20 READ *, DATA IF (DATA.NE.0) GOTO 25 ZERO = ZERO + 1 25 GOTO 20 PRINT *, ZERO STOP END
THE REPEAT WHILE STRUCTURE Control structure: The nature of flow of control in a program determines, what is known as the program’s control structure. It has encountered as 1. SEQUENTIAL STRUCTURE 2. SELECTION STRUCTURE
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
53
MATHEMATICAL FOUNDATION OF CS 3. REPETITIVE STRUCTURE
Sequential structure: In this structure in which statements are executed sequentially one after
another. Selection structure: In this structure, based on testing a condition, one of a set of alternative statements are executed. The IF and the COMPUTED GOTO statements are used in this structure.
Repetitive structure: In which a group of statement is repeated again and again based on the value of
a logical control variable, the DO statement creates a count controlled repetition structure. There are two other repetition structures that are important and useful in programming. The repeat while structure The repeat until structure (i) Repeat While structure: In this structure a group of statement is repeatedly executed as long as condition is true. The control leaves the loop as soon as the specified condition becomes false. The general form of Repeat while structure: DO ….. n WHILE <condition> ………. n continues. Ex:
DO 30 WHILE (n.NE.0) ……………… 30 CONTINUE.
(ii) Repeat until structure: In the repeat until structure a group of statement is repeated until a condition becomes true. The repeats until structure, the statements in the loop are executed at least once before the condition is tested. The general form: DO n UNTIL <CONDITION> ……………………. n continues. Ex: DO 10 UNTIL (A.GT.0) …………..
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
54
MATHEMATICAL FOUNDATION OF CS 10 CONTINUE.
SUBSCRIPTED VARIABLES In the variable we can store the only one value. Subscripted Variable or Array: It is a group of quantities by a single name. Each number in the group is referred to by its position in the group. For example we consider the group of number values assumed to SUM={2.8,3.5,4.2,5.2,6.2} If we went to refer the third number of the group means SUM(3). In this 3 is called the subscript is enclosed within the paranthesis. The general form of array element is referred by using the notation. SUM (I). Where the I may take the value of 1,2,39. So on depending on the component. Single subscript variable or one dimension array: In a single subscript variable, we can use the one value, that is referred as consecutive memory locations: Syntax: Variable name(Array INDEX). Ex: SUM(I), SUM(50), MARKS(50). In this example mark (50) assigns the 50 values to the mark component. So it will read the 50 different marks. We use the subscript means we use the dimension statement. Ex: DIMENSION MARKS (50). READ *, MARKS. The DIMENSION statement gives the information that marks has 50 components for which values are to be assigned.
(ii) Multiple subscripts: The two dimensional array also available in the FORTRAN. That is row & column rise the numbers are stored. The general element may be signified by using the notation A(I,J). Where I is the row subscript & J is the column subscript. The subscripted variable are declared in the type declared in the TYPE declaration. No separate dimension statement is given for that variable. For Ex: INTEGER MARKS DIMENSION MARKS (10,5)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
55
MATHEMATICAL FOUNDATION OF CS Subscript Expressions: The general form of subscript is (i, j, k) . Where V is variable name it may be integer or real. The i, j, k are subscripts. Rules: (i) A subscript can only be an integer constant an integer variable or an integer expression. It should be greater than one when evaluated. Ex: I -3, 4 * K+3, I * * 4. Invalid: 0, -4, I (K) A+B The <= 0 is not allowed in subscripts, so negative value & 0’s are rejected. (ii) The subscripted variable is an integer or real variable name followed by subscripts enclosed within paranthesis. The subscripted are separated by commas. Ex: A (I, K), J (A), MAT ()J +2, K-4). Invalid Example: AP (2.), IN (0), A (I = 2/4) . is not allowed 0 not allowed division is not allowed.
DIMENSION STATEMENT: When we are using the subscripted variables a DIMENSION statement is required to inform the compiler that a particular variable is a subscripted variable. The storage is allocated for that variable. The general Form of DIMENSION: DIMENSION v1 (n1), v2 (n2, n3) …… vm (nk, n, n6) Where v1, v2……. vm are variable names and n1, n2, n3…..nx are non zero unsigned positive integer constants. The DIMENSION statement may contain any number of variables. The variables are separated by commas. Ex: DIMENSION SAL (10, 20), NUM (5), COST (6, 10, 5) Invalid Examples: 1. DIMENSION A (5), B (10,10) (not allowed before variable name) 2. DIMENSION A (K), J (K, L) (K, L are not allowed). The DIMENSION statement provides information to compiler to reserve the memory location for the arrays. It is not executable statement. The REAL, INTEGER & DIMENSION must be placed at the beginning of the program. So it will placed before all executable statements.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
56
MATHEMATICAL FOUNDATION OF CS
UNIT III
FUNCTIONS AND SUBROUTINES INTRODUCTION: Functions and subroutines are program segments which have an independent existence. Motivation 1: Function program and subroutine programs may be developed separately and tested. They can be used by other programs. Ex: Built-in-Functions SIN, EXP. Programs for evaluating such functions have already been written, tested and incorporated in the FORTRAN processor by a professional programmer. Besides such predefined functions, we may write programs for functions which we need frequently. Which are not in the library. To write a good efficient program for this we use a “Private Library”. Motivation 2: Evaluate a FORTRAN user to use programs developed by others which satisfies his requirements. Ex: Well tested programs for common problems in matrix multiplication, algebraic equation solution, statistical computations etc. Two well known subroutines IMSI (International Mathematical and Statistical Library) NAG (Numerical Algorithm Group). Motivation 3:To enable breaking up a large computer programming job into a number of subtasks. Advantages of dividing into subtasks: More reliable. Easy understanding. Functions & subroutines classification: Predefined functions (built-in) Arithmetic statement functions External functions or function subprogram
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
57
MATHEMATICAL FOUNDATION OF CS Subroutine subprogram Pre-defined (built-in-functions): Pre-defined functions are nothing but a set of programs written and stored in the FORTRAN processor itself. Ex: SQTR, SIN, COS, MOD. Statement functions: A statement function is defined by a single arithmetic or logical statement at the beginning of a program. Ex: CUBSUM (X, Y) = X ** 3 + Y ** 3. External function or a function subprogram: Is defined by a group of statements. It is implicitly referenced by the appearance of its name in a program. Subroutine program: Independent group of statements. It is explicitly referenced by using statements known as ‘CALL’ statement in FORTRAN. Statement functions: Define a function by a single arithmetic or logical statement then a simple definition and use of the function is allowed in FORTRAN. Ex: A bank gives simple interest on all deposits at r percent per year. It is required to formulate a function to calculate interest. Interest function consists of three variables- rate, balance, and year of deposit. Define the functions as REAL INTRT INTRT (RATE, BALANCE, YEARS) = BALANCE * RATE / 100 * YEARS. RATE, BALANCE, YEAR are the dummy variable name. If the function is to be used one may write DEPOSIT = DEPOSIT + INTRT (A, B, C) A, B, C will taken as RATE, BALANCE, YEARS. In the statement function INTRT is called by the appearance of the function name. When the statement DEPOSIT is executed by the computer, it calls the actual function INTRT. Where the actual calculation is performed and value is return to calculate DEPOSIT. The function defines by one FORTRAN statement is called statement function or an internally defined functions.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
58
MATHEMATICAL FOUNDATION OF CS Name (a1, a2, a3……..an) = exp (a1, a2……………an……..a2) Where the right hand side is a valid FORTRAN expression with arguments a 1…..an. These are called ‘Parameters’. Function named listing same rules as those used to form variable name. The arguments may be non-subscripted variable name. Any numbers of arguments are allowed. A function will return a integer value if its name begins with I, J, K, L, M, N (unless it declares as REAL). Ex: C ****** Example program- statement function INTEGER TERM REAL INTRT INTRT (RATE, BALANCE, YEAR) = BALANCE *RATE / 100 * YEAR READ *, AMOUNT, TERM, R YRS = 1 DO 100 NOYRS = 1, TERM AMOUNT = AMOUNT + INTRT (R, AMOUNT, YRS) PRINT 50, NOYRS, AMOUNT 50
FORMAT (IX, ‘BALANCE AFTER’, I3, ‘YEARS = RS.’ F8.2)
100
CONTINUE STOP END
Input data: 100 5 10 Output: Balance after 1 year = Rs. 110-00 Balance after 2 years = Rs. 121-00 Balance after 3 years = Rs. 161-05 Function subprograms: C *** EXAMPLE PROGRAM – FUNCTION SUBPROGRAM READ *, A, B Z = (S (A) + S (B)) / S (A+B) PRINT *, Z STOP END
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
59
MATHEMATICAL FOUNDATION OF CS
C *** THE FUNCTION IS COMPUTED BELOW FUNCTION S(X) S=X IF (X.LT.-3.0) S = -3.0 IF (X.GT.3.0) S = 3.0 RETURN END FUNCTION S (X) inform the compiler that the program segment following it defines functions with an argument X The statement RETURN returns the control to the main program. S (A) informs the processor that a function with name S to be used with argument A. A is substituted for X and control is transferred to FUNCTION S (X). RETURN statement return the control to the main program. Then S (B) is evaluated finally S (A+B) is evaluated. These values are used compute Z. The values used for X is given by the program which calls the/uses the subprogram. The subprogram is called by the appearance of the function name S. SYNTAX RULES: The general form of a function subprogram. FUNCTION name (a1, a2 ….an) ………………………………….. ………………………………….. Name = expression (a1, a2 ……..aj) ……………………………………… RETURN ..................................................... …………………………………. Name = expression (a1, a2 ….. at) …………………………………… RETURN ………………………………...... END. The first statement in an function subprogram defines the name of the function and the list of dummy arguments. Function may also be declared. 1. REAL FUNCTION (OR) INTEGER FUNCTION (OR) LOGICAL FUNCTION
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
60
MATHEMATICAL FOUNDATION OF CS
61
One or more RETURN statements in the body of the subprogram signals the logical end of the subprograms. Returns the value of the function found at that stage to the program which called it. The last statement END specifies the physical end. Rules for defining functions: 1. The rule for writing a function name is the same as for variable names. 2. In the body of the subprogram the name of the function must appear at least once on the left hand side for an arithmetic statement. 3. The arguments used in defining a FUNCTION subprograms may only be real or integer or logical variables or array names:
Ex: DIMENSION – array
size declaration. 4. The FUNCTION subprogram must not be placed between two statements of the program calling it. It should be placed after the END statement. 5. If a type declaration is used in defining a function, then the function name should be declared as of same type in the calling (main) program. Rules for calling a function: 1.
The arguments in the calling FUNCTION must agree in numbers, order and mode with those in the FUNCTION statement in the subprogram.
2.
If a dummy argument is an array name the corresponding argument in the argument list of the FUNCTION must also be an array name with identical DIMENSION.
3.
The arguments in the calling program may be expression, subscripted variables, variable names or constants provided on condition (i) is satisfied.
LINKING of FUNCTION SUBPROGRAM The subprogram is called by the appearance of the function name. The values of arguments specified in the call are taken as values of the ‘dummy argument’. When the subprogram reaches the RETURN statement the value stored in name by the subprogram is accessed by the calling program. Variable names provide the connecting link between the calling program and called program are known as global variable. In the function subprogram have other variable which is used to make the computation of the value for name. These variables are private to the subprogram and are not accessible to the calling program. These variables are called as ‘LOCAL VARIABLE’. Thus a subprogram can be written separately and kept in a library for use by a class of users. With this facility a large programs may be divided into a number of subprograms and linked together.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
SUBROUTINES: Definition: A function subprogram returns a single value to the main program when it is called. If more than one value is to be returned to the main program then a subprogram called a SUBROUTINE. Where no value is to be returned to the main program but specific operations are performed (like arranging a list of numbers in ascending order) then also subroutines are used. Two Important Features in using SUBROUTINES: 1. The list of arguments on which the subroutine is to operate are to be transmitted to the subroutine from the calling program. 2. After the operations are performed the results are to be transmitted back to the calling program. This is achieved through the dummy arguments listed in the argument list of the subroutine. Subroutine may be return a value or may not return a value a special statement is required to call it. Syntax:
CALL NAME (LIST OF ARGUMENTS) Name of the subroutine may be any valid FORTRAN variables. The list of arguments must agree in numbers, order and mode with dummy arguments in subroutine definition. Ex: SUBROUTINES ROOTS (A, B, C, XREAL1, XREAL2, X1MAG1, X1MAG2) CALL ROOTS (P, Q, R, Y, Y1, Y2, Y3, Y4) A P; B Q; C R; XREAL1 Y1; XREAL2 Y2; X1MAG1 Y3; X1MAG2 Y4. Linking of subroutine: Example: (matrix transpose) C *** MATRIX TRANSPOSE SUBROUTINE TRANSPOSE (MATA, N) DIMENSION MATA (20, 20) NMINS1 = N – 1 DO 50 I = 1, NMINS1 IPLUS1 = I + 1 DO 25J = JPLUS1, N TEMP = MATA (I, J)
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
62
MATHEMATICAL FOUNDATION OF CS
63
MATA=(I,J) = MATA (J, I) MATA (I, J) = TEMP 25
CONTINUE
50
CONTINUE RETURN END
C *** MAIN PROGRAM DIMENSION MATSAM (20, 20) READ 25, ((MATSAM (I, J),) = 1, 5) I = 1, 5) CALL TRPOSE (MATSAM, 5) STOP END
THE COMMON DECLARATION: It was noted that variable are transmitted between a calling program used a subroutine through argument list. Another convenient method using which values may be transmitted between a calling program and subprogram this done using a declaration named COMMON. This declaration reserves a block of locations in memory called as COMMON BLOCK. Values of the variables are stored in this common block and it is accessed by the calling program and subroutine. Ex:
SUBROUTINE ROOTS COMMON A, B, C, XREAL1, XREAL2, X1MAG1, X1MAG2 . . . COMMON X, Y, Z, XR1, XR2, XI1, XI2 CALL ROOTS The processor will assign the first location in a “Common-block of storage” to A and X.
The next location is for X1MAG2 and XI2. No explicit mention of the variable name as argument in either he subroutine statement or in the CALL statement.
VARIABLE
COMON LOCATION
VARIABLE
A
1
X
B
2
Y
C
3
Z
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS Ex: C *** MAIN PROGRAM COMMON X, Y, SUMPROD READ *, X, Y CALL CALC PRINT *, SUM, PROD STOP END SUBROUTINE CALC COMMON A, B, PLUS, STAR PLUS = A + B STAR = A * C RETURN END In the above program, the two common statement causes the same memory location to be assigned to a variables X and A, Y and B, SUM and PLUS and STAR and PROD. CALC computes the values of PLUS and STAR but they printed using the names SUM and PROD. Labeled common: FORTRAN allows the user to make a ‘PRIVATE’ common area between two routines through a declaration called ‘Labeled’ common. Ex: C *** MAIN PROGRAM INTEGER DATA1 (200), FREQ (100) COMMON DATA1, NDT/AREA1/FREQ, INTERV CALL FRTBLE (MIN, MAX) ……… ……… END C *** SUBROUTINE1 SUBROUTINE FRTBLE (MIN, MAX) INTEGER DARRAY (200), FREQCY (100) COMMON DARRAY, NDA/AREA1/FREQCY, INTL CALL MINDAT (MIN) CALL MAXDAT (MAX) ……….. ……….. END
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
64
MATHEMATICAL FOUNDATION OF CS
65
C *** SUBROUTINE2 SUBROUTINE MAXDAT (MAXIMUM) DIMENSION INDAT (200) COMMON INDAT, NDATA ………. ………. END
ROUTINE
MAIN
FRTBLE
MINDAT
MAXDAT
DATA1
DARRAY
INPTDA
INDAT
NDT
NDA
NUMDAT
INDAT
LABELED
FREQ
FREQCY
COMMON PRCA1
INTERV
INTL
-
-
BLANK COMMON
DATA1, DARRAY, INPTDA, INDAT in a blank common occupy the same memory locations. The array FREQ, FREQCY are only common to MAIN and FRTBLE. But they are not accessible to subroutines MINDAT, MAXDAT. Placement of array elements in common: ARRAY: A group of variables stored in single consequence memory location called as array. Ex:
Consider the following statements, MAIN1 DIMENSION A (20) COMMON A ……………. ……………. SUBROUTINE A B C DIMENSION B (2, 20) COMMON B …………..... ……………. SUBROUTINE X Y Z DIMENSION (12, 2, 5) COMMON C
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
66
Which element of array A, B, C will occupy the 10th position in the storage area reserved for common block? A (1), B (1, 1), C (1, 1, 1) start at the same location. Similar A (20), B (2, 10), C th
(2, 2, 5) occupy the 20 location. Arrays are stored in memory where the first subscript varies fastest and the last subscript least. Maximum DIMENSION is obtained by a simple formula. Ex: Array (2, 2, 5) means L = 2, M = 2, N = 5 If we find the location A (2, 1, 4) i = 2; j = 1; k = 4 A (i, j, k) = i + L (j – 1) + LM (k – 1) A (2, 1, 4) = 2 + 2 (1 – 1) + 2 * 2 * (4 – 1) = 2 + 2 (0) + 4 * 3 = 2 + 0 + 12 = 14
FORMULA CALCULATE POSITION OF ARRAY ELEMENT IN COMMON.
ARRAY
MAXIMUM SIZE
LOCATION OF ARRAY ELEMENT
1
A (L)
A (i) = i
2
A (L,M)
A (i, j) = i + L (j-1)
3
A(L,M,N)
A (i, j, k) = i + L (j-1) + LM (k-1)
DIMENSION
PROCESSING FILES IN FORTRAN File: A collection of records is called a file.
NO
NAME
GROSSPAY
REDUCTONS
FIELDS
101
XXX
50
10
Record 1
102
YYY
100
80
Record 2
103
ZZZ
75
5
Record 3
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
67
Each column is represented as Fields. Collection of fields is represented as Records. Each row is represented as Records. Collection of records is represented as File. Records in a file can be arranged in two ways. 1. Sequential file. 2. Direct access file. Sequential file:
Records may be typed as a sequence of lines one after another from first to last.
The CPU will read these lines one after another from first to last.
A line in the middle cannot be read without reading the lines occurring earlier.
Direct access files:
In this arrangement a specified record can be directly retrieved without reading or passing through other records in a file.
Records may be stored in the magnetic disk as a direct access file.
In a sequential access records are arranged in any order (i.e.) either ascending or descending order.
Using the key filed we can easily retrieve the data (i.e.) using employee number we can retrieve the record.
The records in direct access are also known as “RANDOM ACCESS FILES”.
Comparison: Sequential file
Direct access file
Less compute storage
More storage
Less time to process
Faster access of files. (only few records)
Stored only on magnetic tape
Stored on both tape and magnetic disks
Creating a sequential file:
To create a sequential file on a magnetic device
Assume that data has been typed one record per line.
The file we will create will be sequential file on a magnetic disk with records arranged in ascending order of roll number.
The first statement needed to create a file is called ‘OPEN STATEMNET’.
Each input and output device in a computer is given a unique ‘unit number’.
Unit numbers 20 to 63 used to signify logical files on magnetic disk.
Unit number 10 to 18 used to signify magnetic tapes.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS
68
Other Details about OPEN STATEMENT: 1. The name of the files. Normally a file name at most six characters long followed (optionally) by a dot and three (or less) character extension which indicates the nature of the file. Ex:
Valid file names are: STUFIC.DAT, F23.X PAYFIL.MAS, XYZ
Mode of access namely sequential or random (default option- sequential). 2. Medium in which the file is stored. 3. Length of each record. 4. Protection code for file etc. Statement like:
OPEN (UNIT = 20, FILE = ‘STUFIL.DAT’) Which indicate that the file is to be created on disk and is to be given the name STUFIL.DAT The unit on which a sequential file is to be recorded should be brought to its starting point before information is written on it.
Statement like:
REWIND Unit identifier The statement will keep the logical unit 20 ready for recording at its starting point. First record is read from the input unit by the statement.
READ (*, 50) ROLL NO, NAME, MARKS
We have used a special statement to jump after detecting end of a file. READ (*, 50, END =
ROLL NO
NAME
MARK1
MARK2
MARK3
Columns
Columns
Columns
Columns
Columns
101)
1 to 6
7 to 31
32 to 34
35 to 37
38 to 40
NAME, MARKS. (It
means
ROLLNO,
read
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
a
MATHEMATICAL FOUNDATION OF CS record from the terminal using FORMAT 50 and if the end of record is reached jump to statement 101). The last statement – writes an end of file marker.
ENDFILE 20
After al processing to be done on the specified file is over it is closed by statement.
CLOSE (20) Example: C*****
EXAMPLE PROGRAM – SEQUENTIAL FILE DIMENSION MARKS (3). CHARACTER *5, NAME (5). INTEGER ROLLNO OPEN (UNIT = 20, FILE = ‘STUFIL.DAT’) REWIND 20 DO 100 I = 1, 999 ERAD (*, 50, END = 101) ROLLNO, NAME, MARKS
50
FORMAT (I6, 5A5, 313) WRITE (20, 50) ROLLNO, NAME, MARKS
100
CONTINUE
101
ENDFILE 20 REWIND 20 CLOSE (20).
Searching a Sequential File: In Fortran we have a option to retrieve a record with a specified key form a sequential file. Sequential file is arranged in ascending order in key field.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
69
MATHEMATICAL FOUNDATION OF CS Ex: C** EXAMPLE PROGRAM SEARCHING – SEQUENTIAL --------------------READ *, ROLSR, MAGFI1 OPEN (UNIT = MAGFI1, FILE =’ STUFIL.DAT’) REWIND MAGFI1 --------IF (ROLLNO.EQ.ROLSR) THEN PRINT *, ROLLNO, NAME, MARKS ELSEIF PRINT *, ‘RECORD NOT FOUND’ REWIND MAGFI1 CLOSE (MAGFI1) STOP END. READ the ‘ROLSR’ which is the unique key field for searching. Check if the master file ROLLNO is equal to ROLSR then PRINT ROLLNO, NAME, MARKS. Otherwise PRINT ‘RECORD NOT FOUND’ Close the given file and stop the program execution. Updating a Sequential File: Updating means making the changes in the already existed records. Ex: C** Updating Sequential File READ *, MAGFI1, MAGFI2 OPEN (UNIT = MAGFI1, FILE = ‘STUFIL.DAT’) OPEN (UNIT = MAGFI1, FILE = ‘NEWFIL.DAT’) REWIND MAGFI1 REWIND MAGFI2 DO 100 I = 1, 999 READ *, NEWROL, MARKS (4) ------IF (NEWROL.NE.ROLLNO) THEN PRINT *, ‘ERROR’
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
70
MATHEMATICAL FOUNDATION OF CS ELSE MARTOT = 0. DO 75 J=1, 4. MARTOT = MARTOT+MARK (J)
75 CONTINUE WRITE (MAGFI2, 80) ROLLNO, NAME, MARKS, MARTOT. 100 CONTINUE ENDFILE MAGFI2 REWIND MAGFI2. CLOSE (MAGFI1) CLOSE (MAGFI2) STOP END In the above program roll no, name, marks of a student are read from the terminal. The roll no is given in the master file is compared with the roll no we read. If they are equal then the total marks are computed. By using the write statement we write that record on the magnetic file unit. If the roll numbers do not match an error message is printed. Merging two sequential files: Merging means combination of files and produces the single output file. File 1 + File 2 = File 3 File 1 and File 2 are merged them self and produce a new file (file3). Ex: C *** MERGING TWO SEQUENTIAL FILE READ *, FILE1, FILE2, FILE3 OPEN (UNIT = FILE1, FILE = ‘STUSEC1.DAT’) OPEN (UNIT = FILE2, FILE = ‘STUSEC2.DAT’) OPEN (UNIT = FILE3, FILE = ‘STUFILE.DAT’) REWIND FILE1 REWIND FILE2 REWIND FILE3
READ (FILE1, 10) ROLNO1, NAME1, MARKS1) READ (FILE2, 10) ROLNO2, NAME2, MARKS2) ………….. ………….. IF (ROLNO1.LT.ROLNO2) THEN
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
71
MATHEMATICAL FOUNDATION OF CS WRITE (FILE3, 10) ROLNO1, NAME1, MARK1 ELSEIF (ROLNO1.EQ.ROLNO2) THEN PRINT *, ‘DUPLICATE RECORD NO’ ELSE WRITE (FILE3, 10) ROLNO2, NAME2, MARK2 END IF END FILE FILE1 END FILE FILE2 END FILE FILE3 The program opens two files FILE1-STUSEC1.DAT with fields ROLNO1, NAME1, MARK1. FILE2-STUSEC2.DAT with fields ROLNO2, NAME2, MARK2. One record each from the two files STUSEC1.DAT and STUSEC2.DAT are read and their keys (ROLNO1, ROLNO2) are COMPARED. The record with small key is written on output file. If the two keys happen to be equal then there is obviously an error message will be displayed on the screen. Finally when we open the merged file ‘STUFILE.DAT’ will contain all the details. Direct access file: Sequential files are commonly used in FORTRAN. Direct access files are easy to use. Records are retrieved by using the record key. Defining a direct access file: A file is specified as a direct access file in the OPEN statement. In a sequential file we specify the unit number and file name. But here we specify the ACCESS = ‘DIRECT’, DEVICE = ‘DISK’, FORM = ‘FORMATTED’. It also specify maximum number of character in the record by using LENGTH = ‘XX’. Ex: In a record ROLLNO – length (3) digits NAME
- length (24) character
MARKS – length (9) digits So length of the record is 36 OPEN (UNIT = 20, FILE = ‘STRAND.DAT’ ACCESS = ‘DIRECT’, RECORD LENGTH = 36 FORM = ‘FORMATTED’) Creating a direct access file: Unlike the sequential file random access file does not require the input records to be arranged in a ascending or descending order by key. Ex: DO 100 I = 999 READ (*, 30, END = 101) ROLLNO, NAME, MARKS
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
72
MATHEMATICAL FOUNDATION OF CS 30
FORMAT (13, 6A4, 313) WRITE (20, 30, REC = ROLLNO) ROLLNO, NAME, MARKS
100 CONTINUE In this statement records stored in unit 20 according to the format statement on 30 with ROLLNO as key. With the record no as ROLLNO.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
73
MATHEMATICAL FOUNDATION OF CS
UNIT -IV
FoxPro Overview and Sample Session ACCEPT, INPUT: The ACCEPT and INPUT commands are useful in command files. You use these commands to display prompts and to pass text or numbers directly from keyboard to a memory variable. After you type text or numbers, press Return to complete the entry. The ACCEPT command always treats data as character-type variable, while the INPUT command lets you either numeric or character-type variables. The form for these commands is: ACCEPT ‘Type the member ID number ‘ TO MID INPUT ‘Enter the membership fee ‘ TO MFEE.
Look at the following examples to see how you can use quotes and brackets. ACCEPT “Type the member’s initials “ TO MINIT INPUT ‘Enter the fee or type “Q” and RETURN to QUIT ‘ TO MFEE ACCEPT (Type member’s name or “X” to exit. ) TO MNAME
The space between the last character of the prompt text and the trailing quote is optional. This provides adequate separation between the text of the displayed prompt and the cursor position. Using the above lines in a command file results in a display similar to the following. Type the member’s initials _ Enter the fee Or type “q” and RETURN to Quit _ Type member’s name or “X” to exit.
Pressing Return always completes the typed response to the ACCEPT and INPUT commands. After Return is pressed, the program saves the typed value to the named memory variable. APPLICATIONS Use the ACCEPT command to store the name to a memory variable.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
74
MATHEMATICAL FOUNDATION OF CS ACCEPT ‘Enter the name to look up’ TO MNAME.
When you begin programming you select variable names according to specific rules. When naming a variable, use a name that has meaning. In the preceding example, the memory variable name is the same as the field name preceded by the letter “M” (for “memory”). This is an easy way to remember that the memory variable MNAME relates to the NAME field. As you work your way through the development of a command file, you can remember what you called the memory variable containing the name value. The variable MADDRESS relates to the ADDRESS field, MAMOUNT with AMOUNT and so on.
You can also use the following forms to create memory variable names. For example, STORE “Smith” TO M.NAME Or STORE “Jones” TO M->NAME
Both of these forms are acceptable in creating memory variable names in your programs. The letter “M” followed by a period or an arrow tells FoxPro that what follows is a memory variable. ACTIVATE/ DEFINE MENU DEFINE PAD DESCRIPTION The commands described in this module give the flexibility to create menus best suited for your programming needs. Menus are a part of everyday life in applications.
DEFINE MENU The first step in creating a menu system is to use the DEFINE MENU command. The DEFINE MENU command creates a menu bar and assigns it a name. Once you define the menu bar, you may use the DEFINE PAD command (described later in this module) to specify the pads that will appear on the menu bar. A PAD corresponds to an option on the menu bar. The general form of the DEFINE MENU command follows.
DEFINE MENU menu_name
In the example, a menu name appears after the command DEFINE MENU. You must define a menu bar with the DEFINE MENU command before you can display it with the ACTIVATE MENU command (described later in this module).
DEFINE MENU menu_name BAR AT LINE number
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
75
MATHEMATICAL FOUNDATION OF CS
In the example, the optional clause BAR creates a bar menu that emulates the FoxPro system menu bar. Each menu created in this manner has the following characteristics: After selecting a menu item, FoxPro deactivates the menu bar. The command draws a one-line0high horizontal menu bar the width of the screen or the window. FoxPro places the pads automatically when you define the pads for the menu. Remember this means that you cannot use the AT clause or FoxPro generates an error. When the size or number of pads defined exceeds the size of the screen or a window, FoxPro scrolls the menu bar. When you include the AT LINE optional clause of Bar, FoxPro places the menu bar on the row specified by the LINE number.
DEFINE MENU menu_name IN WINDOW window_name In the example, you place the menu bar in a specific window using the IN WINDOW clause. The WINDOW_NAME specifies the window where FoxPro places the menu bar.
DEFINE MENU menu_name KEY key_label
In the example, you specify the key or key combination used to avtive the menu bar. This is the same as using the ON KEY LABEL command. Module 69 lists the available keys and key combinations and the key label names.
The DEFINE MENU command most often to create a menu system. This type of menu system contains a horizontal menu bar with menu popups under each of the menu pads. When you use the Left or Right Arrows or the mouse, the light-bar on the menu moves from pad to pad. As you move from pad to pad, a menu popup appears under each pad. Using the Up or Down Arrows and Return or the mouse, you can choose an option from the menu popup.
DEFINE PAD The next step in creating a menu bar is using the DEFINE PAD command. You use the DEFINE PAD command to place command to place menu pads on a menu bar. When creating a menu system, you generally use this command with the DEFINE MENU command. You use the arrow keys or a mouse to move from pd to pad. Several forms of this command follow.
DEFINE PAD pad_name OF main_menu PROMPT expression
The following is an example.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
76
MATHEMATICAL FOUNDATION OF CS
DEFINE MENU sales DEFINE PAD pad1 OF sales PROMPT “Invoices” DEFINE PAD pad2 OF sales PROMPT “Customers” DEFINE PAD pad3 OF sales PROMPT “Parts” DEFINE PAD pad4 OF sales PROMPT “Suppliers” BEFORE pad2
ACTIVATE MENU sales
In the example, you DEFINEd the MENU sales. You then DEFINEd PAD pad4 using the BEFORE clause. As a result FoxPro places PAD pad2 in the menu.
Every pad that you place on a menu bar requires its own a DEFINE PAD command. You must assign a unique pad name to each menu pad. If you assign a new pad with a name used by a previously defined pad name, FoxPro overwrites the old pad definition with the new pad definition. The following is an example DEFINE PAD sales OF mainmenu PROMPT “INVOICES” DEFINE PAD sales OF mainmenu PROMPT “PAYMENTS”
In the example, you defined the first pad with a pad name of SALES. The prompt for the definition is “INVOICES”. The second pad also has the pad name SALES with the prompt “PAYMENTS”. The definition of the second pad overwrites the definition of the first pad.
ACTIVE MENU The final step in this process is the ACTIVE MENU command. This command works with the DEFINE MENU and DEFINE PAD commands and causes FoxPro to display the defined menu bar on the screen or in a window and ACTIVATEd for use. The general form for this command follows.
ACIVATE MENU main_menu
Now you have activated the menu bar and can move from menu pad by pressing the Left or Right Arrows keys. If a menu appears under a pad, then you can move between those options using the Up or Down Arrow keys. Pressing Esc deactivates the menu popup without making a choice. You can
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
77
MATHEMATICAL FOUNDATION OF CS DEACTIVATE the menu bar with the DEACTIVATE MENU command or by activating another menu bar. This command has an optional clause PAD. The general form for this command follows.
ACTIVATE MENU main_menu PAD sales
In this example, the optional clause PAD causes FoxPro to select and display the pad name SALES. If you omit the optional clause then FoxPro highlights the first pad.
DEACTIVATE MENU
The DEACTIVATE MENU command removes an active menu from the screen but not from memory, and you can only execute it from within a program file. Program control returns to the program line immediately following the line that activated the menu. The general form for this command follows.
DEACTIVATE MENU
Because only one menu ca be active at one time it is not necessary to include the name of the menu in this command. To release a specific menu from memory you use RELEASE MENUS command with the name of the menu bar. The CLEAR ALL and ALEAR MENUS commands also release all menus from memory.
HIDE MENU
The HIDE MENU command removes the specific menu bar, a set of menu bars, or all menu bars from the screen or a window, but not from memory. When you hide the menu bar, it stays resident in memory and you can display it on the screen or in a window with ACTIVATE MENU or SHOW MENU commands. The general form of the command follows. HIDE MENU main_menu, next_menu,â&#x20AC;Ś
You can also use the optional clause ALL to hide all menus. The general form of this command follows.
HIDE MENU ALL
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
78
MATHEMATICAL FOUNDATION OF CS In the example, FoxPro hides all menus without you having to specify ech menu name. Another optional clause that you can use is the SAVE clause. The general form of this command follows.
HIDE MENU SAVE
You use this optional clause to place an image of a menu bar on the screen or in a window.
SHOW MENU This command allows you to display a menu bar or a set of menu bars on the screen or in a window without activating them. FoxPro displays the menu bars but you cannot use them. You must define the menu bar or bars with the DEFINE MENU command before you can use this command. The general form of this command follows.
SHOW MENU main_menu
The following is an example of how you can use this command.
DEFINE MENU main_menu DEFINE PAD sales OF main_menu PROMPT “NEW SALES” DEFINE PAD customers OF main_menu PROMPT “CUSTOMERS” SHOW MENU main_menu
In the example you created a menu bar with two pads, SALES and CUSTOMERS. The SHOW MENU command displays the menu bar so you can see what it looks like.
You can use optional PAD clause to highlight a pad on the menu bar. The following is the example. DEFINE MENU main_menu DEFINE PAD sales OF main_menu PROMPT “NEW SALES” DEFINE PAD customers OF main_menu PROMPT “CUSTOMERS” SHOW MWNU main_menu PAD customers
CLEAR MENU Release all menu bars from memory and clears them from the screen or a window. The general form of this command follows.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
79
MATHEMATICAL FOUNDATION OF CS CLEAR MENUS
SET MESSAGE TO This command defines a character string that you can display as a message and to determine the position of a message (see module 86). The general form for this command follows. SET MESSAGE TO “Place your message here” Or SET MESSAGE TO 20 (LEFT | CENTER | RIGHT)
In the first example, you define a message that FoxPro can display; while in the second example, you define the position where FoxPro displays the message. The optional clauses LEFT, CENTER, RIGHT determine whether FoxPro justifies the message to the left or right on the screen or centered.
MENU( ) The MENU( ) function returns, as a character string of uppercase letters, the name of the currently active menu. PAD( ) The PAD( ) function returns, as a character string the name of the PAD that was last chosen from an active menu bar.
APPILATIONS Menus are an everyday occurrence in applications. The commands described in this module give you much flexibility to create an easy-to-use application for users. Menu systems give your applications the ability to be effective and efficient.
ACTIVATE/DEFINE POPUP, DEFINE BAR, BAR( ) DESCRIPTION The command described in this module let you create menu popups best suited for programming needs. These commands enhance the menu making process.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
80
MATHEMATICAL FOUNDATION OF CS DEFINE POPUP DEFINE POPUP lets you create a menu popup. A menu popup may contain a list of options that you define the contents of a database field, a list of files from a database. A menu popup is assigned a name and a position where it will appear on the screen or in a window, and you may also specify its size.
The general form for this command follows.
DEFINE POPUP popup_name FROM row, column
In the example, you use the DEFINE POPUP command to define a popup named popup_name. the FROM clause in the command line defines the position on the screen where FoxPro places the upper left corner of the menu popup.
The following optional clauses allow you to define menu options using information contains in an open database or on a directory. The following are examples.
DEFINE POPUP sales IN WINDOW window_name
In the example, FoxPro places the popup in the active outputwindow. If there is no active output window, FoxPro places the popup in the screen. By including the IN WINDOW clause in the DEFINE POPUP command, FoxPro places the popup in the window specified by the WINDOW_NAME. DEFINE POPUP sales FOOTER “Footer Message”
In the example, you specify the message that appears centered in the bottom border of the popup. The footer is wider than the popup, FoxPro truncates it. DEFINE POPUP sales key KEY_LABEL
In the example, you specify the key or combination of keys a user can press to activate the popup. Module 69 lists the keys available and the key label names. Using the KEY clause is the same the ON KEY LABEL command.
DEFINE POPUP sales MARGIN
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
81
MATHEMATICAL FOUNDATION OF CS In the example, you include the MARGIN to place an extra space to the left and right of each popup option. FoxPro displays mark characters in the space to the left of an option, and displays an arrow indicating an additional hierarchical popup is available to the right of an option. DEFINE BAR You use the DEFINE BAR command with the DEFINE POPUP and ACTIVE POPUP commands to create a menu popup and display it on the screen. The DEFINE BAR command specifies the position on the menu popup where the option will appear. The following is the general form of the command. DEFINE BAR position OF sales PROMPT “Expression”
In this example, you declare the position (numeric value) of the menu ooption for the menu popup named SALES. The PROMPT “Expression” is the text of the option htat appears on the menu popup. If you define more menu options than will fit on the menu popup, you create a scrollable popup. You can then scroll through th options using the Up or Down Arrow keys.
Another optional clause that you can use is the MESSAGE clause. The following is an example of its use. DEFINE BAR 1 OF sales PROMPT “Expresion” MESSAGE “Place message here”
In this example, a message appears outside the popup, and FoxPro determines the position of the message on the screen by the SET MESSAGE command (Module 86). Each message can be up to 79 characters in length.
The following optional clause is useful when you want to display an option but you do not want a user to select it. The following is an example. DEFINE BAR 1 OF sales PROMPT “Expression” SKIP Or DEFINE BAR 1 OF sales PROMPT “Expression” SKIP FOR paid
In this example, the menu option appears in the menu popup but you cannot choose it. In the second example, you cannot choose the menu option when the expression PAID is true.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
82
MATHEMATICAL FOUNDATION OF CS The BEFORE and AFTER optional clauses are useful when you want to place a popup option in a position relative to others in the group. You can also use the _MFIRST and _MLAST clauses with the BEFORE/AFTER clauses.
The following is an example.
DEFINE POPUP sales RELATIVE FROM 1 , 1 DEFINE BAR 4 OF sales PROMPT “Invoices” DEFINE BAR 3 OF sales PROMPT “Customers” DEFINE BAR 2 OF sales PROMPT “Parts” DEFINE BAR 1 OF sales PROMPT “Suppliers” DEFINE BAR 6 OF sales PROMPT “Reports” BEFORE _MLAST
ACTIVE POPUP The ACTIVE POPUP command works in conjunction with the DEFINE POPUP and DEFINE BAR commands and causes FoxPro to display the defined menu popup, named popup_name, on the screen or in a window and ACTIVATEd for use.
Once you activate a menu popup, you can navigate among the available options using the Up and Down Arrow keys. You can choose a menu option by highlighting it and pressing Return at clicking the mouse on the option. Pressing Esc deactivates a menu popup without making the choice. You can also deactivate the menu popup using the DEACTIVATE POPUP command by activating another menu popup. The following is the general form of this command.
ACTIVATE POPUP popup_name
There are three clauses you can use with the ACTIVATE POPUP command. They are the AT row/col, BAR number, and NOWAIT clauses. The AT row,col clause allow you to specify where FoxPro locates the popup on the screen or in a window. The row and column you specify is the coordinate of the upper left corner of the popup. This coordinate position takes precedence over a screen or window position specified by the FROM clause of the DEFINE POPUP command. The following is an example of this command.
ACTIVATE POPUPP popup_name AT 5 , 15
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
83
MATHEMATICAL FOUNDATION OF CS The BAR option_number automatically selects the popup option number when you display the popup. If the option number selected is not within the range of options, FoxPro selects the first option. The following exercise illustrates this.
ACTIVATE POPUP popup_name BAR 3
The NOWAIT clause allows you to continue your program execution after FoxPro displays and activates a popup. When you use this clause, the program does not wait for the user to make a selection. The following example illustrates this.
ACTIVATE POPUP popup_name NOWAIT
DEACTIVATE POPUP The DEACTIVATE POPUP command removes an active menu popup from the screen or a window but not from memory. You can only execute this command from within program files. Program control returns to the program line immediately following the line that activated the menu popup. The general form of this command follows.
DEACTICATE POPUPUP+
HIDE POPUP
The HIDE POPUP command removes the specified menu popup, a set of menu popups, or all menu popups from the screen or a window but not from memory. When you hide a menu popup, it stays resident in memory abd you can display it on the screen or in a window with ACTIVATE POPUP or SHOW POPUP commands. The general form of the command follows. HIDE POPUP popup_1, popup_2â&#x20AC;Ś
You can also use the optional clause ASLL to hide all menu popups. The general form of this command follows.
HIDE POPUP ALL
In the example, FoxPro hides all menu popups without you having to specify each menu popup name
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
84
MATHEMATICAL FOUNDATION OF CS SHOW POPUP This command allows you to display a menu popup or a set of menu popup on the screen or in a window without activating them. FoxPro displays the menu popups but you cannot use them. You must define the menu popup or popups with the DEFINE POPUP command before you can use this command. The following is an example of how you can use this command. DEFINE MENU main_menu DEFINE PAD sales OF main_menu PROMPT “NEW SALES” DEFINE PAD customers OF main_menu PROMPT “CUSTOMERS”
ON SELECTION PAD sales OF main_menu SHOW POPUP salespop ON SELECTION PAD customers OF main_menu SHOW POPUP custpop DEFINE POPUP salespop FROM 02, 01 DEFINE BAR 1 OF salespop PROMPT “New sales” DEFINE BAR 2 OF salespop PROMPT “Print reports” DEFINE BAR 3 OF salespop PROMPT “List All sales” ON SELECTION POPUP salespop DO salesproc
DEFINE POPUP custpop FROM 02, 16 DEFINE BAR 1 OF custpop PROMPT “New customers” DEFINE BAR 2 OF custpop PROMPT “Print Labels” DEFINE BAR 3 OF custpop PROMPT “List All customers” ON SELECTION POPUP custpop DO custproc
ACTIVATE MENU main_menu
In the example you defined a menu bar with bar with two pads, SALES and CUSTOMERS. The SHOW POPUP command displays the menu popups so you can see what each popup looks like. You cannot use the popups, only display them.
CLEAR POPUPS This command releases all menu popups from memory and clears that from the screen or a window.
RELEASE POPUPS This command releases selected popups from memory and from the screen or a window. The following is an example.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
85
MATHEMATICAL FOUNDATION OF CS RELEASE POPUPS popup_1, popup_2,â&#x20AC;Ś..
In the example, you released popup_1 and popup_2 from memory and the screen. If you use RELEASE POPUPS without a popup list, FoxPro removes all popups from memory and the screen or a window.
BAR( ) BAR( ) returns a value of zero if there is no active menu popup or if the Esc key is pressed to exit the menu. POPUP( ) The POPUP( ) function returns, as a character string, the name of the active menu popup.
PROMPT( ) The PROMPT( ) function returns, as a character string, the option chosen an and active menu popup.
ACTIVATE/DEFINE WINDOW, ACTIVATE SCREEN
DESCRIPTION One of the most notable features of the FoxPro menu building capability is the use of window in the menus. This module describes windows and their uses in your applications. In this module you create windows in a step-by-step method for application other than menus.
DEFINE WINDOW The DEFINE WINDOW command creates a user-defined window and specifies the attributes fir the window such as TITLE, border, control options, and color. You determine the position of the upper left corner of the window using the FROM clause to specify arrow and a column. Then you determine the lower right corner using the TO clause with another set of row and column coordinates. The following is an example.
DEFINE WINDOW custom FROM 00, 01 TO 05, 20
In the example, you created a window named CUSTOM where the upper left corner is at row 00 and column 01 and the lower right corner is at row 05, column 20.to display the window you use the ACTIVATE WINDOW or SHOW WINDOW commands.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
86
MATHEMATICAL FOUNDATION OF CS
Window names can be up to 10 characters long. They must begin with a letter or underscore and can contain any combination of letter, numbers, and underscores. You can define as many windows as you like. Your only limitation is the amount of memory available in your computer.
FoxPro places each window definition in memory and lists their names in the bottom portion of the WINDOW menu popup. The first window that you define is first on the list, followed by each successively defined window.
You can use the following optional clauses to create various types of windows. DEFINE WINDOW custom FROM 00, 01, TO 05, 20 TITLE “SALES” – This option assigns a title to the window in the top border of the window. If the length of the title is wider than the window, FoxPro truncates the title. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 DOUBLE – This option draws a double line border around the window. The default border is a single line. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 footer “Message” – This option places text in the footer of a window. FoxPro centers the footer in the bottom border of the window. If the footer is wider than the window, FoxPro truncates it. DEFINE WINDOW custom FROM 00, 01 TO 05, MINIMIZE – This allows you to reduce a window to a minimize size. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 FILL CHR(176) – This filled background of a window with a character of your choice. In the example, the fill character. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 PANEL – This option draws a wide border around the window. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 NONE – This option suppresses the border entirely. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 CLOSE GROW ZOOM SYSTEM – This option causes the appropriate controls (size control, zoom control, or close box) associate with the systems windows to appear in the border of the user-defined windows.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
87
MATHEMATICAL FOUNDATION OF CS
DEFINE WINDOW custom FROM 00, 01 TO 05, 20 border string – You can define your custom border with this option. For example, the following creates a window with a double top and bottom and a single line side box. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 CLOSE – This option allows you to click a window from the system menu popup or with the mouse. When you close a window FoxPro removes the window from memory. To display the window again, you must DEFINE the window and ACTIVATE or SHOW it again. You can only CLOSE window from the system menu popup or with a close box that you defined with this option. The close a window created with this option you can choose CLOSE from the File menu popup. You can also use a mouse to close the window by clicking in the upper left corner of the window border. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 NOCLOSE – This option prevents you from closing a window unless you use the CLEAR WINDOWS, DEACTIVATE WINDOWS, or RELEASE WINDOWS command. If you omit this option, then the default state is NOCLOSE. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 FLOAT –This option allows you to move a window to any position on the screen. You can move the window by closing a menu option or dragging the window with a mouse. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 NOFLOAT – This option prevents you from moving a window on the screen. If you omit this option, then the default state is NOFLOAT. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 GROW – This option allows you to change the size of a window. You can change the window size with a keystroke combination by selecting a menu option, or by using a mouse. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 NOGROW – This option prevents you from changing the size of a window. If you omit this option then the default state is NOGROW. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 SHADOW – This option creates a darkened areas behind a window giving the illusion of a SHADOW. Any text or objects in the SHADOW are still visible.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
88
MATHEMATICAL FOUNDATION OF CS DEFINE WINDOW custom FROM 00, 01 TO 05, 20 NOSHADOW – This option prevents a SHADOW from showing. If you omit this option, then the default state is NOSHADOW. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 ZOOM – This option allows you to enlarge a window to fill the entry area of the screen. You can make a small window expand to the full-screen size by choosing a menu option or clicking the zoom control. Once you ZOOM a window to full-screen, you can ZOOM it back to its original size. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 NOZOOM – This option prevents you from the Zooming a window. If you omit this option, then the default state is NOZOOM.
ACITVATE WINDOW This command displays and activates a previously defined user window(s). Activating a window directs all screen output to that window. You can activate more than one window at a time but FoxPro only directs output to the last window activates. Thw general form for this command follows. ACTIVATE WINDOW custom_window1, custom_window2, ….. Or ACTIVATE WINDOW ALL
In the example, you can open one or more windows at a time or you can use the ALL option to open all the windows at the same time. If you open all windows at the same time, FoxPro displays them in the order you defined them. The last window defined becomes the activate output window.
Other options that you can use with this command include the following. ACTIVATE WINDOW custom BOTTOM – This option allows you to place the window at the bottom of a stack of windows. ACTIVATE WINDOW custom TOP –This option allows you to place the window at the top of the stack of windows.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
89
MATHEMATICAL FOUNDATION OF CS ACTIVATE WINDOW custom SAME – This option allows you to place the window back into a stack of windows in the same position the window occupied before you activated the DEACTIVATE WINDOW or HIDE WINDOW commands. ACTIVATE WINDOW custom NOSHOW – This option allows you to direct output to a window without changing the status of the window. When you ACTIVATE a window with this option, FoxPro directs output to the window without displaying the window. If you used the HIDE WINDOW command, FoxPro keeps the window hidden as it directs output to the window.
DEACTIVATE WINDOW The DEACTIVATE WINDOW command deactivates a window or set of windows and removes them from the screen. The window or windows are not removed From the memory and may be displayed again with the ACTIVATE WINDOW or SHOW WINDOW commands. The general form of this command follows.
DEACTIVATE WINDOW custom_window1, custom_window2... Or DACTIVATE WINDOW ALL
In this example, you can deactivate one or more windows at a time by specifying the names the windows. You can also deactivate all the windows at the same time by specifying the ALL option. MOVE WINDOW This command lets you move a DEFINEd window to a different located on the screen or in a window. You can move the window to a specific position, or you can move it relative to its current position. To move a window to a specific position on the screen or another window, you can use the following command.
DEFINE WINDOW custom FROM 00, 01 TO 05, 20 ACTIVATE WINDOW custom WAIT MOVE WINDOW custom to 10, 10
In this example, you define a window names custom where the left corner of the window is the row 0 and column 1. you can ACTIVATE the window and FoxPro WAITs for you to press key. After pressing a key, FoxPro MOVEs the window to the specific position.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
90
MATHEMATICAL FOUNDATION OF CS HIDE WINDOW You issue the HIDE WINDOW command to remove the named window or windows from the screen. When FoxPro HIDEs a window ,it stays resident in memory and activate in all respects. You can send output to a hidden – you just won’t be able to see it. The following illustrates this command.
DEFINE WINDOW custom FROM 00, 01 TO 05, 20 ACTIVATE WINDOW custom WAIT HIDE WINDOW custom
Or
HIDE WINDOW ALL
In this example, you DEFINEd the window named custom and ACTIVATEd it. FoxPro WAITs for you to press a key and then HIDEs the window from view. If you use the optional clause ALL, FoxPro HIDEs all windows.
SHOW WINDOW The SLOW WINDOW command controls the display and front-to-back screen placement of windows. If a window or windows have been DEFINED but not ACTIVATEd, SHOW WINDOW places them on the screen. If you have hidden a window or windows, SHOW WINDOW places them on the screen. The following example demonstrates this.
DEFINE WINDOW custom FROM 00, 01 TO 05, 20 ACTIVATE WINDOW custom WAIT HIDE WINDOW custom WAIT SHOW WINDOW custom Or SHOW WINDOW ALL
If you display a windows on the screen, the SHOW WINDOW command lets you change the front-to-back order in which they appear on the screen.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
91
MATHEMATICAL FOUNDATION OF CS SHOW WINDOW custom BOTTOM – This option allows you to place the window behind all other currently displayed windows. SHOW WINDOW custom TOP – This option allows you to place the window in front of all other currently displayed windows.
SAVE WINDOW The SAVE WINDOWS command saves currently defined windows to a disk file or a memo field. You can restore them later with the RESTORE WINDOW command. You can save selected windows to a file by including a window list, or you can save all currently defined windows using the keyword ALL. The following illustrates this.
DEFINE WINDOW custom FROM 00, 01 TO 05, 20 ACTIVATE WINDOW custom WAIT WINDOW custom TO hold_win CLEAR WINDOWS When you save a window to a file, FoxPro also saves the window’s status. For example, if the window was hidden when you saved it to a file, then the hidden status of the window remains when you restore it from the file.
RESTORE WINDOW
The RESTORE WINDOW command restored to memory specified windows saved in a window disk file or a memo field. You can restore some or all of the windows from a file memo field by specifying a window list or using the keyword ALL. The following illustrates this. DEFINE WINDOW custom FROM 00, 01 TO 05, 20 ACTIVATE WINDOW custom WAIT SAVE WINDOW custom TO hold_win CLEAR WINDOWS RESTORE WINDOW custom FROM hold_win You can also restore a window or windows to a memo field. See the following illustration. DEFINE WINDOW custom FROM 00, 01 TO 05, 20
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
92
MATHEMATICAL FOUNDATION OF CS ACTIVATE WINDOW custom WAIT SAVE WINDOW custom TO MEMO tempmemo CLEAR WINDOWS RESTORE WINDOW custom FROM MEMO tempmemo
ACTIVATE SCREEN The ACTIVATE SCREEN command directs input and output to the screen behind any open windows. All activated windows remain on the screen and all input and output sent to the screen appears behind them.
Once you finish sending input or output to the screen, you can activate the windows to direct input or output back to the windows.
CALCULATE DESRIPTION CLACULATE command you can perform financial and statistical operations on fields is a database or an expressions involving fields. The general form for this command follows. CALCULATE function ( ) The function in the command can be any combination of the following FoxPro functions. AVG(n) – This function computes the arithmetic mean of a database field or field expression. CNT( ) – This function returns the number of records in a database. MAX(expression) – This function returns the largest value of an expression or field. You can specify any numeric, character, or data field as the expression or any valid expression using these field types. MIN(expression) – This function returns the smallest value of an expression or field. You can specify any numeric, or character, or data field as the expression or any valid expression using these filed types.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
93
MATHEMATICAL FOUNDATION OF CS NPV(n1, expression, n2) – This function computes the net present value of a series of future cash flows discounted at a constant periodic interest rate.
The numeric (n1) is the interest rate, expressed as a decimal value.
The expression is a field, field expression, or valid numeric expression representing a series of cash flows.
The numeric n2 is an optional initial investment. If the initial investment (n2) is not present, then the initial investment is assumed to occur at the end of the first period. This initial investment would be the first record in the field and would be negative to represent a cash outflow. STD(n) – This function computes the standard deviation of the values in a field or field expression. The standard deviation measures the degree to which the field values differ from the average of all the values in the field. The smaller the standard deviation, the less the values in the field or field expression deviate from the average. SUM(n) – This function adds the values in a field or field expression. VAR(n) – This function computes the variation from the average of a field or field expression. The variance is the square root of the standard deviation. The smaller the variance, the less the values in the field vary from the average.
You can use the optional clauses FOR or WHILE with the CALCULATE command. This allows you to calculate only records that meet the conditions specified in the command line. The following illustrates this.
USE sales CALCULATE AVG (quantity) FOR units = “Bags” Or USE sales CALCULATE AVG (quantity) WHILE amount > 100
In the first example, you average the contents of the field named quantity for all records. You have UNITS equal to “Bags”. In the second example, you average the contents of the fields QUALTITY for those records where the amount is greater then 100.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
94
MATHEMATICAL FOUNDATION OF CS
You can also store the values of the calculations to a memory variable or an array. If you use array, you must DECLARE or DIMENSION the array before you can use it with CALCULATE command. The following illustrates this.
USE sales CALCULATE AVG (quantity), SUM (amount) TO hold_avg, hold_sum
OR
USE sales DIMENSION
hold_value (5)
CALCULATE AVG (quantity), SUM (amount) TO hold_value
In the first example, you average the contents of the field named QUANTITY and store then in a memory variable called HOLD_AVG. You then SUM the contents of the field named AMOUNT and store the result ina memory variable called HOLD_SUM.
In the second example, you create an array with 5 elements called HOLD_VALUE. You can store the result of the AVG() function in the first element of the array and the result of the SUM(amount) function in the second element of the array. The remaining three elements of array are unchanged.
CALL, LOAD, RELEASE MODULE
DESCRIPTION This module provides a brief description of the LOAD and CALL commands for your information. If you are an assembly language programmer armed with the macro assembler, then you may wish to experiment with these commands. However, this book does not assumed availability of software beyond that supplied with the FoxPro program. Therefore, this module omits the Typical Operation section.
You can use the LOAD and CALL commands together to load binary program files into memory. From memory you can call the binary program files onto use. Before using CALL, use the LOAD command to place from one to five binary files into memory. You can LOAD up to
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
95
MATHEMATICAL FOUNDATION OF CS sixteen binary files. The binary files can be as large as 32,000 bytes. The default file extension for a binary file is BIN.
Once loaded, use the CALL command to call the binary file (or memory resident program module) into use, as you would use the DO command to run a FoxPro command file.
The form of the LOAD command is: LOAD binary_filename
After you place the named binary file into memory, you can access the CALL command, FoxPro treats the called file as a subroutine, or module, rather than as an external program.
The general form of the CALL command is
CALL binary filename WITH expression or memory variable
Omit the filename extension when using the CALL command. In addition, you should always use unique filenames. The following command files uses the LOAD and CALL commands, and assumes you loaded CLOCKBIN into memory as a callable module.
LOAD CLOCK CALL CLOCK MX=0 DO WHILE MX < 100 MX = MX + 1 ENDDO RELEASE MODULE CLOCK CLEAR RETURN
If you have BIN files loaded into memory, you can use DISPLAY or LIST STATUS to review their names. Because FoxPro does not check the integrity of the loaded modules, they must be of binary type and operate properly.
Listed here for your convenience are some assembly language programming notes supplied by fox software.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
96
MATHEMATICAL FOUNDATION OF CS
Use an offset of zero at origination (ORG) for the first executable instruction.
The LOAD command uses the file size to allocate memory. therefore, the program must not allocate memory beyond its actual size.
The assembly language program must not change the length of the meory variable.
The module must restore the code segment (CS) and stack segment (SS) registers before returning to FoxPro.
Use a RET FAR rather than the more common exit call to return FoxPro control.
When the program is terminated by an exit system call rather than a far return, execute the assembly programs with the RUN/! Command.
You must use the macro assembler or an equivalent assembler the source program. This operation is beyond the scope of this book, which addresses only FoxPro commands and functions. DIR The Dir command is similar to dos dir command. You can also use dos wild card (*) to list selected files. For ex, if you want to list files having extension .prg, you can use the command form :
Dir *.PRG
This lists every filename having the extension prg. To list all files on the logged disk drive type
Dir *.*
Notice that the last two command forms are the same as those used by dos. There are the options that you can use with the dir command to redirect the output to a printer of file. The forms are as follows :
Dir *.prg to print This forms redirects the file listing the printer.
Dir *.prg to file filename
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
97
MATHEMATICAL FOUNDATION OF CS This routes the file listing to a text file. If the text file exists, then foxpro prompts with a message asking whether or not you want to overwrite the existing file. Display, List, Clear
This module describes the display and list commands, which you use to display the contents of a database. It also describes the clear command, used to clear the screen. This module also introduces the RECNO() function where recno stands for record number. You can use the recno() function to display or store database record numbers. The term current record represents the current location of the foxpro, record pointer.
Display : Use the display command to perform several tasks. These include: Display the contents of a database. Display the structure of an active database. Display the files on a disk (same as directory). Display the status of open files and set commands. Display the active memory variables and their contents. Display and print database information simultaneously.
If you want to display this information for all records, you can use : DISPLAY ALL FIELD NAME, ST_ADR, PAID_UP The same command followed by the off clause suppresses the display of record numbers. EDIT The edit command to change the contents of one or more records in a database. You can also use the browse command for editing, module 15 describe : the BROWSE command, you must open a database with the USE command before you can use edit command. The following list presents forms the edit command. As with all commands, you must press return at the end of command line.
Edit : Displays the contents of the current record in an editing mask.
SET COMMANDS The FoxPro program has a large repertoire of set functions used to control the FoxPro operating environment. For ex, set talk off is a function used in command files to turn off the FoxPro dialog. Set talk on turns the dialog back on. Set print on directs displayed information to your printer. Set print off turns simultaneous printing back off.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
98
MATHEMATICAL FOUNDATION OF CS The following list describes each of the set functions. The boldfaced parameter is the default value. Set alternate to filename – directs displayed information to a file. The filename has the extension txt unless you specify another. Including the keyword additive appends screen output to the end of the alternate file. If you omit the keyword additive foxpro overwrites the contents of the file. Set alternate on/off – turns output to alternate file on or off. Set ANSI on/off – allows you to compare sql strings. When on, FoxPro compares the two strings character –by- character for the full length of the strings. When off, you compare two strings until the program encounters the end of the shorter string. Set auto save on/off – flushes the buffers to disk. Flushing buffers reduces the chance of data loss if your computer loses power. When auto save is on, FoxPro flushes the buffers to disk whenever you exit a read command or return to the command windows. Set bell on/off - speaker “beeps” during data entry when cursor reaches the end of a field. It also sounds when you enter invalid data. Set bell to frequency, duration – allows you to adjust the frequency (pitch) of the bell and the duration (length of time) the bell sounds. You can set the frequency between 19 and 10,000 hertz, and duration between 1 and 19. Set blink on/off – affects CGA and VGA monitors only. If blink is on, it makes screen borders, shadows, text blink. If the blink is off, it brightens background colour, doubles the number of colours available.
Set block size to an integer - specifies bow FoxPro allocates disk space for storage memo fields. You can use an integer between 1 and 32. FoxPro allocates the disk space for storage of memo fields in blocks of size (integer * 512) bytes. If you specify an integer greater than 32, FoxPro allocates disk space for blocks in bytes corresponding to the size integer. Specifying a value for block size greater than 32 can result substantial savings in disk space for the storage of memo fields. The default value for the block size is 64.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
99
MATHEMATICAL FOUNDATION OF CS DO DESCRIPTION You use the DO command to start operating a FoxPro command (or program) file .You can use the DO command either from the FoxPro command window or as a statement within a command file. The form of the DO command is: DO filename Where filename is the name of a command file. You can also use the DO filename command as statement in a command file. When used as a statement within a command file, the DO command causes the named command file to begin operation. The named command file operates until:
1. It reaches the end of the command file, which passes control back to the FoxPro command window. 2. It encounters a QUIIT command, which passes control back to the DOS operating system. 3. It encounters a CANCEL command, which passes control back to the FoxPro command window. 4. It encounters a RETURN command, which returns control to the calling command file. If you issue the DO command from the FoxPro command window, RETURN passes control back to the Fox Pro command window. 5. You press the Esc key, which interrupts program operation and displays a â&#x20AC;&#x153;cancel, Resume, Ignoreâ&#x20AC;? prompt. 6. It encounters a command file error, such as not closing an IF with an ENDIF or a DO WHILE with an ENDDO.
7. FoxPro displays an error message.
You can also start operation of a FoxPro command file directly from the DOS prompt by typing.
FOXPRO filename
Where the filename is the name of a command file.
You can also place a command statement in the CONFIG.FP file to run a command file anytime you start FoxPro. For example, the CONFIG.FP file can contain the line:
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
100
MATHEMATICAL FOUNDATION OF CS COMMAND = DO filename Where the filename is the name of a command file. The DO command also has the following optional clause.
DO filename WITH parameters
DO CASE, CASE, OTHERWISE, ENDCASE
DESCRIPTION You can use the family of CASE commands to check for a specified condition. If the condition moves to be true, the appropriate CASE statement executes. The following paragraphs describe each element of the CASE statement, beginning with DO CASE.
DOCASE The DOCASE command is the first statement used. This statement tells FoxPro that one or more CASE statements follow.
DO CASE CASE x = 1 Command line (s) CASE x = 2 Command line (s) â&#x20AC;Ś.. CASE x = N Command line (s) OTHERWISE Command line (s) ENDCASE.
CASE One or more command lines follow each CASE statement. If a CASE expression is the command lines associated with that CASE statement execute. Once operation is complete, control passes to the command line following the ENDCASE statement.
OTHERWISE
You can use the OTHERWISE clause as a default statement. If none of
the CASE expressions are true, the OTHERWISE statement comes into play, and the command lines associated with the OTHERWISE statement execute.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
101
MATHEMATICAL FOUNDATION OF CS ENDCASE
As you have probably noticed, the CASE statement starts with DO CASE
and ends with ENDCASE. The clause ENDCASE is necessary to complete the CASE statement. When FoxPro encounters ENDCASE in the command file, control passes to the command line following the ENDCASE statement.
DO WHILE, EXIT, LOOP, ENDDO, EOF ( )
DESCRIPTION The DO WHILE command is a stru8ctured programming command that sustains operation “while” some condition is true. The first line of the DO WHILE statement has the form:
DO WHILE expression
This statement sustains continuous operation as long as the expression is true or until an EXIT or LOOP command executes. The complete DO WHILE statement has the form:
DO WHILE expression | (command lines) | ENDDO
The EXIT command transfers control from within the DO WHILE loop to the command line following the ENDDO statement, which is the last line in a DO WHILE statement. The LOOP command is also available to “loop” control back to the command line following the DO WHILE command line. The series of commands beginning with DO WHILE expression and ending with ENDDO is the complete statement.
Think of DO WHILE and ENDDO as book ends with the books in between representing command statements. So for every DO WHILE there is always a corresponding ENDDO. You can “nest” interior DO WHILEs and ENDDOs as well as IFs and ENDIFs and DO CASEs and ENDCASEs within a DO WHILE statement. An example containing IFs and ENDIFs
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
102
MATHEMATICAL FOUNDATION OF CS follow. Notice how each DO WHILE and IF has a corresponding ENDDO and ENDIF. Interior (nested) DO WHILE-ENDDO pairs (and IF-ENDIF pairs) must reside within the statement.
LOOP When the program encounters the LOOP command, control passes back to the command line following DO WHILE. You can use the LOOP command to restart the DO WHILE loop when a certain condition exists within a command file. The DO WHILE statement operation and loops back automatically unless the DO WHILE condition becomes END or the EXIT, CANCEL, RETURN, or QUIT command executes.
The EXIT statement is a convenient way to get out of a DOWHILE loop. The alternative of the DO WHILE condition to false. You can use the EOF ( ) statement, which stands for end of file, with several command including DO WHILE, DO CASE, and IF. When an end-of –file condition exists, EOF ( ) Return a true value. Going to the bottom of a file with GO BOTTOM does not position the record pointer to the end of file. It positions the record pointer to the last record in the file. There i9s a distinct difference. To prove this to yourself, try the following command from the FoxPro command window.
Use members GO BOTTOM
&&
puts the members database file in use.
&&
Goes to the last record in the file.
? EOF ( )
&&
checks for end-of –file status.
. F.
&&
FoxPro says false.
Skip
&&
moves record pointer down (hits end of file ).
? EOF ( )
&&
checks for end-of-file status.
.T.
&&
FoxPro says True, you’ve reached end of file.
You can also go to the end of file with the COUNT command. If you use the COUNT command in place of GO BOTTOM in the last example, the first ? EOF ( ) check would have returned the true value.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
103
MATHEMATICAL FOUNDATION OF CS
104
Unit V FIND, SEEK, SEEK( ) DESCRIPTION: FIND and SEEK commands let you find the first record within an indexed database that predetermined expression. FIND operates with character strings, while SEEK with either character strings or numeric values. However, if you use SEEK with a string, you must enclose the string in single or double quotes or square brackets. The string FIND and SEEK commands achieve the same result.
The FIND and SEEK commands are similar to LOCATE. However, these only operate with key fields, used during the indexing process. FIND and SEEK find only the first match within a database. Also, the “FOR”, as in the LOCATE FOR AGE>=35, is unavailable with these commands. On the other LOCATE and CONTINUE search through records within a database until the search finds record or the end of the database. You can also use LOCATE with logical values FIND and SEEK cannot locate logical values. 1. FIND expression –
Positions the record pointer to the first record containing an expression
in a key field. FIND JO Finds the first record containing “jo” as the two characters of a
key
field. Jo matches string such as Jones or Johnson. Note that an exact uppercase and lowercase match must occur.
DISPLAY NAME, ZIP Displays NAME and ZIP fields.
2. FIND &MNAME --
Finds the first record containing the contents of the memory
variable MNAME in a key field. The macro substitution function
(&)
substitutes memory variable contents for its name. STORE ‘Joh’ TO MNAME
Stores string Joh to MNAME.
FIND &MNAME Finds the first record containing Joh as the starting string of the key field. 3. SEEK ‘Jones’ -4. SEEK 112
--
5 .SEEK MVAL --
Finds the first record containing the name “Jones”. Finds the first record containing 112. Finds the first record containing the contents of the memory
variable MVAL in s key field. 6. SEEK (“112”) --
Finds the first record containing 112.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS 7. SEEK (MVAL) --
Finds the first record containing the contents of the memory
variable MVAL in s key field. FOR, ENDFOR DESCRIPTION: Use the FORâ&#x20AC;ŚENDFOR commands to execute a set of statements within a loop a specified number of times. You can use a memory variable as a counter to determine how many times FoxPro executes the statements inside the loop. The following is an example of this command.
FOR counter = 1 TO 10 ? counter ENDFOR In the example, FoxPro initializes the memory variable counter to 1 and increments it by 1 Each it loops. When the value of counter is 10, FoxPro executes the last loop in this Command. Each time the command loops, it executes the statement within the command and displays the value of the counter.
You can use the optional clause STEP to increment the counter by a value other than 1. The following is an example
FOR counter = 1 TO 10 STEP 2 ? Counter ENDFOR
In the example, FoxPro increments the counter by 2. This means that you reach the value 10 in the loop instead of 10 in the previous example. You can also decrement the counter using the STEP clause with a negative value. To do this, the initial value of the counter must be greater than the final value. The following is an example
FOR counter = 10 TO 1 STEP -1 ? counter ENDFOR
In the example, FoxPro initializes the memory variable counter to 10 and decrement it by -1 each time it loops. When the value of counter is 1, FoxPro executes the last loop in this
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
105
MATHEMATICAL FOUNDATION OF CS command. Each time the command loops, it executes the statement within the command and displays the value of the counter.
LOOP When the program encounters the LOOP command, control passes directly back to the FOR command. You can use the LOOP command to restart the FOR loop when a certain condition exists within a command file. The FOR statement continues operation and loops back automatically until the counter reaches the final value defined or the EXIT, CANCEL, RETURN or QUIT command executes.
The following is an example
FOR counter = 10 TO 1 STEP -1 IF counter = 5 LOOP ENDIF ? counter ENDFOR
EXIT the EXIT statement is a convenient way to get out of a FOR loop. You can put a routine similar to the following one in your command file to escape from a FOR loop.
FOR counter = 1 TO 10 IF counter = 5 EXIT ENDIF ? counter ENDFOR
GO, GOTO, GO BOTTOM, GO TOP, SKIP DESCRIPTION: This module describes commands used to move the record pointer to a specific record with in a database file. Like all commands, you must place a database in use before a record positioning command operates. Once the database is open, you can position the record pointer to record within the database using the GO and SKIP commands. The following list includes a summary of each of these commands.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
106
MATHEMATICAL FOUNDATION OF CS
107
GO n, GOTO n, or n – Moves the record pointer to record n. Notice that GO, GOTO Simply typing a number all position the record pointer to the number (n). To save keystrokes, you may prefer
Specified record to use “n” or GO n.
GO n IN alias – Moves the record pointer to record n in the specified work area. The alias can be a work area letter, number, or alias name. GO BOTTOM – Positions the record pointer to the last record of the database in use. GO TOP - Positions the record pointer to the first record of the database in use. SKIP – Moves the record pointer of the following record. SKIP IN alias - Moves the record pointer to the next record in the specified work area. The alias can be a work area letter, number, or alias name. SKIP n – Moves the record pointer n records below the present record position. Most of the entries in the preceding list are self-explanatory. This module provides an example of each to be sure that you understand their use. To set up the example, assume you are using a database file named INVTORY that contains 10 records.
USE INVTORY
&& Puts INVTORY database in use.
GO BOTTOM
&& Moves record pointer to last record in database *
&& Displays record number ? RECNO ( )
(expressed as an integer).
*10
&& FoxPro dialog displays record number.
3
&& Moves record pointer to record 3.
SKIP 3
&& Moves record pointer to record 6.
SKIP -2
&& Moves record pointer to record 4.
GOTO 7
&& Moves record pointer to record 7.
STORE RECNO ( ) TO X
&& Stores record number to memory variable.
7
&& FoxPro dialog displays stored value.
GO TOP
&& Moves record pointer to record 1.
GO X
&& Moves record pointer to record 7,
* the value of X.
IF, ELSE, ENDIF DESCRIPTION: The IF, ELSE, and ENDIF commands form a complete branching statement. The entire set of commands is called the IF statement. It is similar in operation to the DO CASE, OTHERWISE, ENDCASE commands which form the CASE statement described in Module 39. However, the IF statement is better than CASE for checking the presence of single condition.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS Look at the following IF statement. IF expression | (Commands lines) | ENDIF The IF statement checks to see if the expression is true. If the expression is true, the command lines following the IF statement execute. If the expression is false, control passes to the command line following the ENDIF statement.
The ELSE statement is an optional command that adds branching to the IF statement. For example, if you drink your coffee black unless real cream is available, you can use the following statements
If real cream is available I’ll take my coffee with cream. Else I’ll drink my coffee black End if (or the decision) process. Here is the command form in “computerize”. IF expression | (Commands lines) | ELSE | (Commands lines) | ENDIF When you use the IF statement within a DO WHILE statement, ENDIF must occur before ENDDO. The following diagram illustrates this.
DO WHILE .NOT. EOF ( ) |
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
108
MATHEMATICAL FOUNDATION OF CS (Commands lines) | IF expression | (Commands lines) | DO WHILE expression | (Commands lines) | ENDDO | ENDIF | (Commands lines) | IF expression | (Commands lines) | ELSE | (Commands lines) | IF expression | (Commands lines) | ELSE | (Commands lines) | ENDIF | (Commands lines) | ENDIF
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
109
MATHEMATICAL FOUNDATION OF CS | (Commands lines) | ENDDO
Notice how you can nest IF and DO WHILE statements within If statements. Although not known, you can also nest CASE statements within IF statements, so you have a large amount of flexibility in command file design.
You should also be aware of the IIF ( ) function, described in Appendix H. this function is a one line substitute for the complete IF-ELSE-ENDIF statement. It uses the form: IIF (condition, command1, command2) where a true condition executes the command1; a false condition executes command2.
INDEX, REINDEX DESCRIPTION: FoxPro lets you create two types of index files. These are an .IDX file containing one index and a compound .CDX file containing multiple index entries called tags.
The INDEX command lets you arrange database records in alphabetic order. In this respect INDEX is similar to SORT. The INDEX command creates an index file with the extension .IDX or tags an index file a compound index file with the extension .CDX and associates the .IDX or .CDX file with the currently elected database. The index file lets you look at a database an indexed or different order. However, if you change the database file itself, you can REINDEX to update corresponding index files.
The INDEX command lets you use one or more key fields, where key fields are those used a control the indexing sequence. For example, you may want to index a customer database on the CITY and STATE fields. These fields, then, become your key fields. If you want to view the records within a database by state and cities within the state, your INDEX command is:
NDEX ON STATE+CITY TO index-name where index-name is a descriptive index filename of your choice.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
110
MATHEMATICAL FOUNDATION OF CS
USING AN INDEX FILE FoxPro directs commands to the last index file created automatically. However, if you have just opened a database file containing index files, you can put the index file of your choice in use. For example, to use the index file SORTDEX, specify the name of the database file used to create the index file with the USE command. If the database file you used to create the SORTDEX file is STATS, open the SORTDEX index file with:
USE STATS INDEX SORTDEX You can think of this statement as saying, “Use the STATS database index file named SORTDEX”.
INDEX COMMAND FORMS The preceding paragraphs described a few forms of the INDEX command. However, for your convenience the following list contains the commands with explanations of each. INDEX ON fieldname – Indexes database structure and contents, indexed on the named field in alphanumeric (ascending) order, to the named file.
INDEX ON NAME TO TEMPLATE INDEX ON filed 1+field2…TO filename – Indexes database on the named fields to the named index file.
INDEX ON ZIP+NAME TO TEMPLATE
INDEX ON fieldname TAG tag-name OF file.cdx- Creates a .CDX compound index file. The .cdx compound index file is a single index file that consists of one or more separate tags or index entries. FoxPro keeps track of each tag by the unique tag name you assign to it. The only limit to the number of tags in a .CDX file is available memory and disk space. Since FoxPro always compacts multiple entry index files, you do not have to include the COMPACT clause when you create this type of index.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
111
MATHEMATICAL FOUNDATION OF CS You can use the optional clause DESCENDING with a .CDX tag to create an index in reverse order. If you want to create a descending index with an .IDX file, use the SET ORDER TO command described below. The following example illustrates this.
INDEX ON fieldname TAG tag-name OF file.cdx DESCENDING In this example, you create a .CDX tag that indexes a file in reverse order. INDEX ON fieldname TO filename FOR expression – Indexes database on the named field. This creates an index that acts as a filter on the existing database. INDEX ON CITY+ZIP TO TEMPLATE FOR = ”Denver”. INSERT DESCRIPTION: The module describes the INSERT command, which you use to insert new records within the of a database. The INSERT command is similar to the APPEND command, which 7 describes. While APPEND adds a new record to the end of a database, INSERT adds a record immediately after the current record within the database.
CAUTION:
Do not use INSERT with large database. Inserting a record near the front of a large database forces FoxPro to rewrite every record in the database. This will take a very long time to accomplish. In these situations use the APPEND command instead.
FoxPro positions the record pointer and you can use one of the following forms of the INSERT command.
1. INSERT - Inserts a record after the current record, then it displays a record entry mask, like the one displayed by the EDIT or APPEND command, to let you type the contents of each field.
2. INSERT BEFORE - Same as INSERT except it inserts a record before the current record.
3. INSERT BLANK - Inserts a blank record following the current record.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
112
MATHEMATICAL FOUNDATION OF CS JOIN DESCRIPION If information about the same item, such as a part number or person’s name, is in two databases you can use the JOIN command to create a third database must be in use.
Two available forms of the JOIN command are:
JOIN WITH alias TO rename FOR expression JOIN WITH alias TO filename FOR condition FIELDS field list
CAUTION
Using the JOIN command may be very time consuming depending on the size of the two database files you are joining. Also be aware that you may exceed the available disk space with the JOIN command. This is possible even if the sizes of the two database files are modest. Module 85 describes the alias expression, an optional alias name assigned to a selected database file. The FOR expression can contain a statement like “FOR AMOUNT >100.” This form of the command lets you select individual records.
LOCATE, CONTINUE DESRIPTION
The LOCATE command lets you find records within a database that match one or more specific string, numeric, or logical expressions. The location process begins with the first record in the active database and moves down in a top-down sequence. When FoxPro locates a matching record, you can display, alter, or delete the record, or you can extract information from one or more fields. If there are several records within the database that match the LOCATE parameters. You can move down to the next matching record using the CONTINUE command. The general form of the LOCATE command is:
LOCATE FOR fieldname = expression
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
113
MATHEMATICAL FOUNDATION OF CS
114
Once the command finds a match, FoxPro displays the record number in the form “Record = n” where n is the record number. To find the next match, types CONTINUE and press Return.
The following list provides examples of the LOCATE and CONTINUE commands. LOCATE FOR fieldname = expression – Positions the record pointer to the first record
1.
where the named field contains the expression.
LOCATE FOR NAME = ‘Jo’
Locates first record containing a value that
matches ‘Jo,’ such as Jones and Johnson, where NAME is a character-type field that must match upper and lowercase.
2.
CONTINUE – Continue searching for next matching record beginning at the
current record position until it encounters an end-of-file condition. CONTINUE 3.
LOCATE FOR field1 = expression. AND. Field2 = expression – Positions the
record pointer to the first record having fields that match the expressions. You can specify two or more fields; you can also use the OR statement. LOCATE FOR SUBSTR (DTOC(DATE), 1, 8) =
‘03/15/90’ .AND. ZIP =65450
LOCATE FOR SUBSTR (DTOC(DATE), 1, 8) = ‘12/25/90’ .OR NAME = ‘Bates’
Here, the example uses the substring and date-to-character functions to convert a date expression into a character expression. 4. LOCATE FOR expressions $ fieldname – Locates the record containing a partial match within the named field. For example, if you’re trying to find “Smithsonian” in the NAME field, your expression could be: LOCATE FOR ‘Smith’ $ NAME 5. LOCATE FOR fieldname = memory variable – Positions the record pointer to the first record where the field contents match the value of the named memory variable. The following example illustrates the use of a memory variable. STORE ‘Smith’ TO MNAME LOCATE FOR NAME = MNAME
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS 6. LOCATE FOR fieldname = expression SCOPE – This form of the LOCATE command lets you specify a scope, or range, in your instruction. LOCATE FOR ZIP = ‘75080’ NEXT 10 7. LOCATE FOR fieldname = expression1WHILE expression2 – This form of the LOCATE command lets you specify a condition in the statement. The following example looks for a match while a condition exits. LOCATE FOR ZIP =’75080’ WHILE PAID_UP = .T.
MODIFY COMMAND DESCRIPTION If you are working your way through this book using the learning sequence, you have used MIDIFY COMMAND in previous modules. You used it to create new command files or to create new command files or to view existing ones. The text editor that allows you to create command files is the same one you use to edit text in the Memo Windows, Command Windows, and in Dialog Text Boxes.
There are two forms of this command shown here. MODIFY COMMAND filename
The form assumes the .PRG extension. Another form of the command is: MODIFY 7FILE filename.ext The MODIFY FILE command does not assume the .PRG extension for a file. In this form you must supply the extension. You can use the following optional clauses with the MODIFY COMMAND or MODIFY FILE commands. MODIFY COMMAND file NOEDIT – Restricts all changes to the text file. This is useful when you wait the user to view a text file but you want to prevent any changes to the text file. MODIFY COMMAND file RANGE n1, n2 – This option marks and blocks text for deletion within the file you are editing. The beginning of the block starts at (n1) and ends at (n2). The value n1 represents the number of characters from the text. For example, if n1 is 3, then the block begins at the third character from the beginning of the text. The value of n2 should be greater than or equal to n1. When you start typing new data into the file, FoxPro deletes the blocked text.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
115
MATHEMATICAL FOUNDATION OF CS MODIFY COMMAND file SAVE – Keeps a Modify Command window and any open memo windows on the screen after you exit the Modify Command Window. Normally, FoxPro removes the Modify Command and memo windows from the screen after you exit the window. MODIFY COMMAND file WINDOW window_name – Opens a Modify file within another window using this option. The editor assumes the attributes of the window in which you place it.
The MODIFY COMMAND starts the built-in FoxPro full-screen editor. This creates ASCII text files. Although you can create any kind of document. Its intended use creating FoxPro command (or program) files.
FILENAME EXTENSIONS If you use MODIFY COMMAND and you do not include extension with the filename, FoxPro assigns it the extension PRG. If you specify the filename and extension, such as REPE.FRM for a report form file or LETTER.TXT for a text file, FoxPro displays an editing screen for entry exists, FoxPro displays the named file, to edit or view.
EDITING COMMANDS
Once the full-screen editor is in operation, you can use the current
sequence displayed in the edit menu popup and listed in Appendix E. you use these sequence to move the cursor, insert, delete, and so on. When you type the file, you can save it by pressing Ctrl-W for write. If you display a file, make changes, and then decide not to save the changes, you can abort without saving by pressing (or Ctrl-Q for Quit).
This is about all there is to using the FoxPro full-screen editor. You might type MODIFY COMMAND SAMPLE to create a new file. Enter several lines of text and experiments with the control keys. When satisfied that you know how they all work, you can either save the document for future practice with Ctrl-W or quit without saving with Ctrl-Q.
DEVELOPING COMMAND FILES The mechanics of creating a command file are came if you plan. Once you block out the general structure of your database and the necessary command files, you can begin writing and testing command files one at a time. To help you want the file creation process, the following pages give some tips.
When you are ready to design an application, there are several things to consider. The following applications include these considerations in the design steps.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
116
MATHEMATICAL FOUNDATION OF CS 1. Database file structure -- This structure of your database is the first considerations an application design. Jot down a list on paper that includes the following information. a. What kind of information must you store and maintain (field names)? b. Each piece (field) of information needs how many characters? c.
What type is each information element (character, numeric, date, logical, or mnemonic? If numeric, how many decimal places does it need?
When you have determined all the fields you will need, their names, and their types and sizes go ahead and create your database structure. Do not enter all of the data. Limit entry to one or two records for testing. 2. Data manipulation – Next, decide what you will do with the information once you have captured it in a database file. Will you: a. Add records? b. Change records? c.
Delete records?
3. Reports – Once you have decided how you will maintain the information, Decide upon the kinds of printed or displayed output you will need. Will you want to: a. List information to the screen (all or selective)? b. List information to your printer (all or selective)? c.
List information with the date?
You can design reports, labels, and view files using the appropriate FoxPro development attributes described in Module 28 through 30. you can also develop them from scratch by using the commands that display and print information. 4. Application structure – Once you have an idea of what you want to do with the information, you can block out the structure of the command files that make up your application. It is a good idea to use a modular structure, where separate command files perform different tasks. For example, you may want to write a command file for adding records, one for changing records, and still another for deleting records. You can also write several small, relatively simple command file instead of putting everything into one large command file that may take forever to debug. The diagram contained in figure illustrates a series of command files. 5. Individual command file design – With the main structure blocked out, you can begin the design of individual command files. If you want, you can do this directly on your computer using MODIFY COMMAND, with a word processor, or with a pop-up utility like Borland’s Sidekick.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
117
MATHEMATICAL FOUNDATION OF CS 6. Typing the command file – Once you have outlined your MENU command file, you can type command lines under each block. It’s a good idea to leave your comment lines in place to show you what each section of the command file, or program, does. You should know that FoxPro ignores spaces within command files during operation, but it counts them as part of the 254 allowable characters on a command line. If a command line exceeds the width of your screen, use a semicolon at the end of the line and press Return. The semicolon combines multiple lines into a single statement. Remember, when you run the command file, FoxPro execute each line in a top-to-bottom order. Therefore, be careful to organize your commands in the proper sequence. NOTE When command files use a series of the same or similar commands, you can make a copy of an existing command file, rename it, edit the contents, and try it out. This technique is faster than retyping everything from scratch 7. Testing the command file – Once you have finished your first command file, you can test it. If you are using the SET TALK OFF command, you may wish to place an at the beginning of that line so you can see the FoxPro dialog during test runs. If the first command files runs without any hitches, you are ready to build the second one. If you encounter problems, you may want to take advantage of the SET DOHISTORY ON to capture each command in a history of file. Type LIST HISTORY and press Return to display the command for a blow-by- blow report of what is happening during program operation. Do not DOHISTORY on during normal operation as it slows down program operation.
The SET STEP ON command lets you step the program through its paces a line at a time. The command file pauses at every step and waits for you to type Y to go on to the next step. It gives you the option of typing N to continue or Esc to exit. Once the first command file is optional, you can move on to the next one, writing and testing each command file as you develop it. It is like “eating an elephant;” you’ve got to do it one at a time.
MODIFY MEMO, CLOSE MEMO, MEMLINES( ), MLINE( ) DESCRIPTION MEMO field can contain any type of keyboard symbol, graphic, foreign alphabet, or special symbols. FoxPro MEMO field can also contain any possible 8-bit value, including the NULL character CHR(0).
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
118
MATHEMATICAL FOUNDATION OF CS You can use MEMO fields wherever you can use character data. This means that you can think any types of data in MEMO fields. For example, you can store scanned images, digitized and binary object modules, executable programs, and many other data as well. The only on MEMO fields is the amount of disk space used to store them. They stored in MEMO fields are part of the database but are not stored with the database file. FoxPro stores them in a separate file with the same name as the database and with an expression of .FPT. Once you store information in MEMO fields you can modify the information with the MIDIFY MEMO command.
MODIFY MEMO MODIFY MEMO opens editing windows for memo fields from the current database.
You can enter the MODIFY MEMO command with several useful options. The following list gives an example of each with a brief description. MODIFY MEMO memo_field NOEDIT – Restricts all changes to the memo field. This is useful when you want the user to view the memo field but you want to prevent any changes to the memo field. MODIFY MEMO memo_field NOWAIT – Continues program execution after you open the memo field window in program mode. The program does not wait for the memo window to be closed, but continues on the next program line. MODIFY MEMO memo field SAVE – Keeps a memo field window open on the screen you exit the memo field window. Normally, FoxPro removes the memo field window type the screen after you exit the memo field window. MODIFY MEMO memo_field WINDOW window_name – Opens a memo field with another window using this option.
CLOSE MEMO CLOSE MEMO closes a memo window or windows that were opened the MODIFY MEMO or BROWSE commands and saves any changes made to the memo field. The general form of this command is as follows.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
119
MATHEMATICAL FOUNDATION OF CS MEMLINES( ) The MEMLINES( ) function returns the number of lines in a memo field or if arbitrary length. The current value of SET MEMOWIDTH command affects the number of lines in the memo field. The general form for this function follows. MEMLINES (memo_field) MLINE( ) The MLINE( ) function returns a specified line number from a specified memo field. The general form of the function follows.
MLINE (memo_field, line_number) The MLINE( ) function returns the specified returns the specified line number from the specified memo_field in the current record. You can determine the number of lines within a memo field by the current value of SET MEMOWIDTH.
SET MEMOWIDTH This command specifies the displayed width of memo fields. The general form for this command follows.
SET MEMOWIDTH TO a_number
You can use this SET command to determine the width of memo field output in commands like DISPLAY, LIST, OR?/??. Memo field width also affects the values returned by the values returned by the ATLINE, MEMLINE, and MLINE functions. The default width for memo fields is 50.
MODIFY STRUCTURE DESCRIPTION: There times when you find that the structure of a database requires a change to fit an expected need. For example, you may need to add a field or change the length of a field. The MODIFY STRUCTURE command lets you insert, delete, add and change fields within your structure. Modify the structure of a database, put it in use with the USE filename command. Then type: MODIFY STRUCTURE press RETURN. The database creation mask is displayed showing field names, types, widths, of decimal places. You can move the cursor to the desired field and change the field information. You can also insert new fields at the cursor position by pressing CtrlI. Pressing Ctrl-D deletes field.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
120
MATHEMATICAL FOUNDATION OF CS It careful not to modify field lengths or types that might affect important data. For example, if we make a field length shorter than the information contained within it, the data will be “formed “due to the shorter field length. If you change a character field that contains alpha text to a numeric field, you will lose the text, and the field will contain a value of zero. REPLACE DESCRIPTION: Use the REPLACE command to replace the contents of one or more specified fields o database. These fields can be within either the current record or all records, depending on form of the command. You can also restrict replacements to certain records by using the “FOR expression” or “WHILE expression” clauses. The following list shows forms of the REPLACE command. REPLACE fieldname WITH string – Replaces the contents of the named field in the current record with the string, which can be character, numeric, or logical. After using the REPLACE command, FOXPRO positions the record pointer to the last record. Therefore, sure you know where the record pointer is before using the REPLACE command. REPLACE PART_NO WITH ‘250987-01’ 1 record replaced REPLACE field1 WITH string, field2 WITH string,….- Replaces the contents of the name fields in the current record with the corresponding strings. REPLACE QTY WITH 125, PART_NO WITH ‘250987_01’ 1 record replaced REPLACE scope field name WITH string – Replaces the contents of the named field(s) with the corresponding string(s) for records within a scope, such as “all” or “next 5”.
REPLACE ALL PRICE WITH PRICE*1.05 128 records replaced
REPLACE NEXT 3 PRICE WITH PRICE*1.05 3 records replaced
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
121
MATHEMATICAL FOUNDATION OF CS REPLACE field name WITH memory variable – Replaces the contents of the named field with the named memory variable.
REPLACE DATE WITH MDATE REPLACE date-field name WITH CTOD (‘MM/DD/YY’)-Replaces the contents of the date field with the MM/DD/YY string expression. REPLACE DATE WITH CTOD (‘11/12/91’) REPLACE field name WITH string FOR expression –Replaces the contents of the named field(s) with the corresponding string(s) for all records that match the FOR expression . REPLACE COST WITH COST*1.1 FOR DESCRIPTION=’Tire’ REPLACE field name WITH memory variable WHILE expression – replaces the contents of the named field(s) with the corresponding string(s) for all the records WHILE expression is true. REPLACE COST WITH COST*1.1 WHILE DESCRIPTION = ‘Battery’ REPLACE memo WITH string ADDITIVE – Replaces a memo field with the ADDTIVE clause. By including the ADDITVE clause, FoxPro appends replacements to memo fields of the memo field. If you do not include the ADDITIVE clause, the new string overwrites,
REPLACE REMARKS WITH NEW_REMARKS ADDITVE
RUN DESCRIPTION: Use the RUN command to run programs outside of the FoxPro program environment. For example, to run a BASIC program, use the command:
RUN BASIC filename You can substitute the exclamation mark (!) in place of the word “RUN” as an alternate command form. This module uses the RUN format.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
122
MATHEMATICAL FOUNDATION OF CS
If your computer has enough memory (more than 512k), the program executes. If it does not have enough memory, the operating system displays the message “Insufficient memory”.
You can also run command DOS commands, such as DIR and DEL, with RUN. When the program or DOS command finishes operation, the program returns control to FoxPro. You can also use the optional /N clause with the RUN command. This allows you to specify the amount of memory FoxPro makes available for external programs. The /N is the amount of memory FoxPro makes available for external programs. The /N is the amount of memory in kilobytes that is available. If N =0, FoxPro makes available as much memory as possible to the RUN command .The following is an example.
RUN /64 BASIC filename
In the example, FoxPro makes 64 kilobytes of memory available to RUN the BASIC program .If you specify a value greater than zero, FoxPro flushes all buffers to disk , invokes Fox Swap and makes available N kilobytes of memory to the RUN command.
SAY, SAY GET, SAY PICTURE, CLEAR GETS, READ DESCRIPTION: This module deals with a set of FoxPro statements used to display text and accept keyword entries into database fields and memory variables. This module describes several form of the SAY statement. Because you use the SAY statement with the GET and @ row, col statements this module also includes information about these statement. For more information about row, col and GET, see Modules 12 and 52. @ row, col SAY”…” the following list describes some forms of the @ row,col SAY statements. @ row, col SAY ‘displayed text’- FoxPro displays the text enclosed in single quotes, double quotes, or square brackets beginning at the row,col coordinates. @ 5, 20 SAY ‘Read the information and press any key’ @ row, col SAY fieldname –The content of the named field is displayed beginning at the row of coordinates. This uses the named field in the current record.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
123
MATHEMATICAL FOUNDATION OF CS @ 7, 15 SAY CITY @ row, col SAY memory variable –The content of he named memory variable is displayed beginning at the row,col coordinates.
STORE 25 TO AMOUNT @ 12, 35 SAY AMOUNT @ row, col SAY ‘displayed text’ + memory variable –Displays text and contents of special memory variable as a single expression. @ 3, 1 SAY ‘The value of the memory variable is ‘+MVAR @ row1, col1 TO row2, col2-Displays a single –line window. The upper left corner is the row1, col1; the lower right corner is at row2, col2. Adding “DOUBLE” uses a double.
@ 4, 4 TO 18, 75 @ 5, 6 TO 17, 74 DOUBLE When SET DEVICE TO PRINT is active, it directs the displayed output to your printer of to your screen. To bring it back to your screen, enter SET DEVICE TO SCREEN. This FoxPro’s default (normal) mode. As with other print statements, you can use single or double quotes or square brackets around displayed text. When you send output to your printer, it is essential to organize your row-columns position sequentially, from top to bottom, left to right. This is critical when you print information because your printer cannot move backwards; it prints a row and a column at a time. Some example of this form of the SAY statement follows. @ 10, 15 SAY “Press any key to continue…” @ 11, 15 SAY ‘Press Q to Quit, C to continue’ The PICTURE clause causes the value of the expression to appear as a specified character expression. The character string can consist of FUNCTION codes, PICTURE codes, the combination of both. The following is an example.
STORE 5678 TO AMOUNT @ 01, 01 SAY AMOUNT PICTURE “9,999.99” && Picture code. 5,678.00 STORE “John” TO NAME
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
124
MATHEMATICAL FOUNDATION OF CS @ 01, 01 SAY NAME PICTURE “@1” && Function code JOHN STORE “aC88” TO PARTNO @ 01, 01 SAY PARTNO PICTURE “@1A 99” && Both types of code. SCAN, ENDSCAN DESCRIPTION SCAN … ENDSCAN commands as you would the DO WHILE…ENDDO the SCAN command moves through a database file and executes commands for that meets the specified condition. Although similar to the DO WHILE command SCAN automatically advances the record pointer to the next record without the skip command and then tests for the specified condition. You must open a database the SCAN command. The following illustrates the general form of the command. SCAN Commands ENDSCAN Include a scope to SCAN a range of records. The following example illustrates this.
SALES GOTO 3 SCAN REST ? “Customer “+ name ENDSCAN
Example , you opened the database SALES, moved the record pointer to record three, and the REST of the database beginning at record three. For each record scanned, the displays a text.
Include the optional clauses FOR or WHILE with the SCAN command. The is an example.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
125
MATHEMATICAL FOUNDATION OF CS
USE SALES SCAN FOR DESC = ‘flowers’ ? “Description” + DESC ENDSCAN Or USE SALES SCAN WHILE QUANTITY >2 ? “QUANTITY” + STR (QUANTITY) ENDSCAN
SET COMMANDS DESCRIPTION The FoxPro program has a large repertoire of SET functions used to control the FoxPro operating environment. For example, SET TALK OFF is a function used in command files to turn off the FoxPro dialog. SET TALK ON turns the dialog back on. SET PRINT ON directs displayed information to your printer. SET PRINT OFF turns simultaneous printing back off. This module these and many other SET functions. The following list describes each of the SET functions. The boldfaced parameter is the default value. SET ALTERNATE TO filename – Directs displayed information to a file. The filename has the extension TXT unless you specify another. Including the keyword ADDITIVE appends screen output to the end of the ALTERNATE file. If you omit the keyword ADDITIVE FoxPro overwrites the contents of the file. SET ALTERNATE ON/OFF – Turns output to alternate file ON or OFF.
TIP: If you want to capture the contents of your history buffer to a file, use the SET ALTERNATE TO filename and SET ALTERNATE ON commands. Then type LIST HISTORY and press return. Next, close the alternate file with CLOSE ALTERNATE To view the contents of the new file, use TYPE filename and press return from the command window. SET ANSI ON/OFF – Allows you to compare SQL strings. When ON, FoxPro compares the two strings character-by-character for the full length of the strings. When OFF, you compare two strings until the program encounters the end of the shorter string.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
126
MATHEMATICAL FOUNDATION OF CS
SET AUTOSAVE ON/OFF – Flushes the buffers to disk. Flushing buffers reduce the chance of data loss if your computer loses power. When AUTOSAVE is ON, FoxPro flushes the buffers to disk whenever you exit a READ command or return to the command window. SET BELL ON/OFF – Speaker “beeps” during data entry when cursor reaches the end of a field. It also sounds when you enter invalid data. SET BELL TO frequency, duration – Allows you to adjust the frequency (pitch) of the bell and the duration (length of time) the bell sounds. You can set the frequency between 19 and 10000 hertz, and the duration between 1 and 19. SETBLINK ON/OFF – Affects EGA and VGA monitors only. If BLINK is ON, it makes screen borders, shadows, text BLINK. If BLINK is OFF, it brightens background colors, doubling the number of colors available. SET CARRY ON/OFF – Carries the contents of the previous record to the next record during APPEND operations. This saves retyping repetitive information. SET CARRY TO field _ list ADDITIVE –This allows you to specify which fields to carry forward. You can use the optional keyword ADDITIVE. If you use it, it adds the new set of fields carried forward to the previous set of fields. Using SET CARRY TO without a field list returns to the default condition where FoxPro carries forward all field. SET CENTURY ON/OFF – When ON, this SET command displays a four-digit year in the form 07/04/1990. The OFF setting displays the date in the form 07/04/90. SET CLEAR ON/OFF – When ON, this SET command clears the screen when you execute a SET FORMAT TO filename and a QUIT command. When set OFF before you QUIT, FoxPro allows you to display a “sign-off” message after you exit the system. The OFF setting also allows you to superimpose a FORMAT screen over a background screen. SET CLOCK TO row, column – You can place the clock on the screen with the SET CLOCK TO command and a set of screen coordinates. Using SET CLOCK TO without coordinates reset the clock to its default position in the upper right corner of the screen. The default screen coordinates for SET CLOCK TO are (0, 69).
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
127
MATHEMATICAL FOUNDATION OF CS SET COLOR commands – FoxPro has a sophisticated set of commands for full control of colors. These commands allow you to define the colors of FoxPro’s system interface (the system menu bar, windows, alerts, dialogs, etc.) and user-defined objects (@...SAY/GET, menus, windows, etc.). Certain commands, like DEFINE WINDOW, support an optical COLOR or COLOR SCHEME clause that lets you specify colors of user-defined objects directly. SET COLOR SET TO color_ set_ name – The SET COLOR SET TO command lets you load colors from a previously defined color set Color_ set_ name. You can define color sets with the SET COLOR OF SCHEME command or through the color picker dialog. After you define a color set, you must save it in the color picker if you want to use it again.
If you omit the optional COLOR SET Color_ set_ Name clause, the color set gets its colors from the last named color set. The last named color set is the last color set loaded or saved a color set defined with the SET COLOR SET TO command, a color set loaded from the CONFIG.FP configuration file on start up, or the FoxPro default color set. If there is no last named color set, FoxPro restores the default. SET COLOR TO standard _color, enhanced _color, border _color, background _color – The SET COLOR TO command allows you to define a variety of screen attributes for the use of color monitors and also for the use of monochrome monitors. The following define the colors in detail.
Standard _color is normal light-on-dark text. Enhanced _color is inverse video (reversed dark-on-light text). Border _color is the area around the edge of the screen. SET DEBUG ON/OFF – You can send displayed output to the printer when ON. The SET DEBUG command enables or disables access to the Debug and Trace windows. If SET DEBUG is ON, you may open both windows. If SET DEBUG is OFF, neither window may be opened.
If SYSMENU and SET DEBUG are both SET ON, you may open the Debug and Trace windows from the system menu bar during program execution. See the SET SYSMENU command for more information. SET DELETED ON/OFF – Commands like LIST and COPY ignore records marked for deletion when ON. The INDEX command does not ignore deleted records. If SET DELETED is ON, the RECALL ALL command will not recall any records.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
128
MATHEMATICAL FOUNDATION OF CS SET DELIMITERS TO’/’ – Specifies a character (/) to show field boundaries during data entry. You can use the SET DELIMITER ON to display the specified delimiter character. The default delimiter is a colon (. SET DELIMITERS TO DEFAULT – Displays colons as the default delimiter character. SET DELIMITERS ON/OFF – Displays the delimiter characters when ON.
SET HOURS TO 12/24 - The SET HOUR command lets you toggle the clock between a 12-hour (civilian) or 24-hour (military) format. Use SET HOURS TO without the 12 or 24 argument to return to the default format.
SET MEMOWIDTH TO 50 – The SET MEMOWIDTH TO command controls the width memo field output. The normal value is 50 characters, but there may be times when you want to change the width. SET MESSAGE TO text – This command lets you display a line of text on the bottom line your screen. To see the line, SET STATUS ON must be in effect. Look at the following example. SET MESSAGE TO ‘DO NOT PRESS Esc’ SET MESSAGE TO row/LEFT/CENTER/RIGHT – The SET MESSAGE TO also sets the two and the alignment where you can display the optional messages during the MENU TO command. SET MOUSE ON/OFF – You may enable or disable use of the mouse with SET MOUSE ON or SET MOUSE OFF. If you SET MOUSE ON, you have full use of the mouse. If you SET the MOUSE OFF, FoxPro disables the mouse. SET MOUSE TO 5 – The SET MOUSE TO controls the sensitivity of the mouse. The value controls how the pointer responds on the screen to any movement of the mouse. The value may range from 1 to 10, with 1 being the least sensitive and 10 being the most sensitive. SET NEAR ON/OFF – The SET NEAR command determines where FoxPro positions the record pointer after an unsuccessful search for a record. An unsuccessful search occurs when
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
129
MATHEMATICAL FOUNDATION OF CS FoxPro finds no record that meets the search criteria. SET NEAR affects the FIND and SEEK commands.
If SET NEAR is ON and a record is unsuccessful, FoxPro positions the record pointer immediately following the closest matching record. The RECNO ( ) function returns the record number of the closest matching record, FOUND ( ) RETURNS a value and EOF ( ) returns a value of .F.
If SET NEAR is OFF and a record search is unsuccessful, the record pointer will be positional at the end of the database file. The RECNO ( ) function returns the number of records in the database plus one, FOUND ( ) returns a value of .F., and EOF ( ) RETURNS A VALUE OF .t.
Regardless of the setting of SET NEAR, the RECNO ( ) function with an argument of zero returns the record number of the closest matching record if a search is unsuccessful. SET NOTIFY ON/OFF – The SET NOTIFY command allows you to suppress the display system messages. If you SET NOTIFY ON. FoxPro displays system messages. If you SET NOTIFY OFF, FoxPro suppresses the display of system messages. SET PATH TO path_ list – Searches the specified drive (s) and pathname(s) to locate a specified filename. SET PATH TO B: \FOX \PRGS Searches the current directory, then the \ FOX \PRGS subdirectory on disk drive B. SET POINT TO period – The SET POINT TO command allows you to change the decimal point to a different character. The expression may be a character string enclosed in single or double quotes or brackets, or a character memory variable. To reset the decimal point to the default value, use SET POINT TO without an expression. The default decimal point is a period. SET PRINTER ON/OFF, SET PRINTER TO file/port – These two commands let you output to a printer on or off and direct output to a designated port.
The SET PRINTER ON command enables output to the printer, while SET PRINTER OFF disables output. FoxPro does not route output to the printer, while SET PRINTER OFF disables output. FoxPro does not route output that you format with the @... SAY command to the
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
130
MATHEMATICAL FOUNDATION OF CS PRINTER is SET ON. To direct @... SAY commands to the primary use the SET DEVICE TO PRINTER command.
SORT DESCRIPTION The SORT command gives you the ability to copy the records and structure of a database to another database file arranged in either alphabetical, numerical, or alphanumeric order. The SORT is done on more named fields within the active database. You can also specify whether the SORT should be in ascending (A to Z 0r 0 to 9) or descending (Z to A or 9 to 0) order.
The following examples show forms of the SORT command accompanied by explanations of each. Before using SORT, place the desired database in use. SORT TO filename ON fieldname – Copies database structure and contents, sorted on the named field in ascending order, to the named file.
SORT TO NEW ADR ON CITY SORT TO filename ON fieldname /A – Copies database structure and contents, sorted on the named field in ascending order, to the named file.
SORT TO TEMPFILE ON AGE /A SORT TO filename ON fieldname /C – Copies database structure and contents, sorted on the named field while disregarding upper and lowercase, to the named file.
SORT TO TEMPFILE ON NAME /C SORT TO filename ON fieldname /D – Copies database structure and contents, sorted on the named field in ascending order, to the named file.
SORT TO TEMPFILE ON AGE /D
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
131
MATHEMATICAL FOUNDATION OF CS SORT TO filename ON fieldname /AC – Copies database structure and contents, sorted on the named field in descending order while disregarding upper and lowercase, to the named file.
SORT TO TEMDFILE ON NAME /AC SORT TO filename ON fieldname /AD – Copies database structure and contents, sorted on the named field in descending order while disregarding upper and lowercase, to the named file.
SORT TO TEMDFILE ON NAME /AD SORT TO filename ON field1, field2,… -- Copies the database to the specified filename organized on field1, field2. This is a multiple-variable sort. When entries in field1 are the same, field2 determines the order.
SORT TO NEWFILE ON AGE, NAME SORT TO filename ON foeld1 /D, filed2 ASCENDING – Copies the database to the specified filename organized on field1 in descending order and field2 in ascending order. SORT TO filename ON field1 /A,field2 DESCENDING – Copies the database the database to the specified filename organized on field1 in ascending order and field2 in descending order. SORT TO filename ON field1 NEXT 20 – Copies the next 20 records in the database to the specified filename organized on field1. SORT TO filename ON field1 FOR expression – Sorts those records matching the expression to the designated file.
SORT TO TENNIS35 ON NAME, AGE FOR AGE > = 35 SORT TO filename ON field1 while expression – Sorts those records, while an expression is true, to the designated file.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
132
MATHEMATICAL FOUNDATION OF CS SORT TO TENNIS35 ON NAME, AGE FOR AGE > = 35 SORT TO filename ON field1 FIELDS fields – Copies only those fields listed after the FIELDS option, to the specified filename.
SORT TO TEMPFILE ON NAME FIELDS NAME, ADDDRESS, CITY
NOTE: You must have enough disk space to hold the output file and work files of the SORT command. The disk space required can be as much as three times the size of the file you are sorting. If you can see, the SORT command is powerful. It resembles the COPY command (Module 24) accept that you can organize your records in alphanumeric order. One limitation is that SORT not let you use the SDF, DELIMITED, and TYPE clauses. STORE, RELEASE, SAVE, RESTORE DESCRIPTION Memory variables are nothing more than storage locations within your computer’s main memory which you can save character string, numeric date, or logical values. You used memory variables in some of the examples contained in previous modules, and until now, you used them “faith”. This module should take the mystery out of these powerful little “pigeon holes” by describing the STORE, RELEASE, SAVE, and RESTORE commands, where:
STORE
Creates memory variables or arrays
RELEASE
Removes memory variables
SAVE
Writes memory variables to a file.
RESTORE
Reads memory variables to memory from a file.
We can create memory variables with the STORE, ACCEPT, INPUT, AVERAGE, and SUM commands. You can also create them with an expression like: x = ‘Hello’
or
STORE ‘Hello’ to x
are you store the character string “Hello” to the memory variable X.
You can also use the STORE command to initialize every element of an array to the stated value. As must DIMENSION the array to issue the STORE command to an array.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
133
MATHEMATICAL FOUNDATION OF CS
For example:
DIMENSION array name(12) STORE .T. TO array name
STORE Several forms of the STORE command exist. The following list shows some examples.
STORE expression TO memory variable—Stores the expression to the memory variable, which can be up to ten characters in length. STORE ‘Gov. Johnson’ TO MGOV Or MGOV = ‘Gov. Johnson’
This command line stores a string expression to memory variable MGO. FoxPro displays the memory variable value following the command line.
STORE .T.TO TRUE
Store the logical true value to memory variable TRUE STORE 144 TO M2GROSS Stores numeric value 144 to memory variable MGROSS. STORE 2*MGROSS TO M2GROSS
Stores the product of two times the value of MGROSS to memory variable M2GROSS. STORE MGOV+’ elected.’ TO MRESULT Stores memory variable MGOV and the string “elected” to the memory variable MRESULT. FoxPro displays ”Gov. Johnson elected” when stored.
STORE fieldname TO memory variable -- Stores contents of named field to memory variable. When you use this form of STORE, a database must be in use and the record pointer positioned to the desired record.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
134
MATHEMATICAL FOUNDATION OF CS
STORE NAME TO MNAME Stores contents of the NAME field to the memory variable MNAME. STORE field1 + field2 + …TO memory variable -- Stores contents of named fields to memory variable. This also stores trailing blanks when you use the plus sign.
STORE NAME + ST ADR TO MVAR Miller, Gary
3270 Garden Brook
STORE field1 – field2 +….TO memory variable -- Stores contents of named fields to memory variable. Omits trailing blanks (“squashed”) when you use the minus sign. STORE NAME – ST_ADR TO MVAR Miller, Gary 3270 Garden Brook
STORE expression TO array name -- Sets the value of each element in the array to the value TRUE. The array must be DIMENSIONED before you can issue a command to an array. SAVE and RESTORE There are times when you would like to SAVE your memory variable to disk for later use and then RESTORE them when you need them. That’s precisely what the SAVE and RESTORE commands do SAVE writes the named memory variables to a named disk file. You do not have to type a filename extension, as FoxPro assigns MEM as an extension automatically. The RESTORE command reads saved memory variables from disk back to your computer’s memory. The following examples contain forms of the SAVE and RESTORE commands.
SAVE TO filename—Saves all memory variables to the named file and uses a MEM extensions. SAVE TO filenames ALL LIKE expression – Saves all memory variables that mach the expression. Use the * symbol as a “wild card,” which is substitute for one or more following characters.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
135
MATHEMATICAL FOUNDATION OF CS
Use the ? symbol as a place-for-place substitute and you can use at the beginning or end of a memory variable name.
SAVE TO MEMFILE ALL LIKE T????
SAVE TO MEMFILE ALL LIKE ?NA*
SAVE TO MEMFILE ALL LIKE M* SAVE TO filename ALL EXCEPT expression – Saves all memory variables except those matching the expression. You can use the * and ? symbols with the EXCEPT expression as in other forms of the SAVE expression.
SAVE TO MEMFILE ALL EXCEPT A*
SAVE TO MEMFILE ALL EXCEPT A??
SAVE TO MEMFILE ALL EXCEPT ?01 RESTORE FROM filename – Reads all memory variables previously saved to the named file. This Command replaces all active memory variables with the restored memory variables.
RESTORE FROM MEMFILE
SUM DESCRIPTION You use the SUM command to add one or more numeric fields of an active database file. You can either store or display the result to a memory variable. This following list shows forms of the SUM command and corresponding examples. SUM filename – Sums the contents of the specified field name and displays the result below (with SET TALK ON). SUM QTY 12 records summed Qty
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
136
MATHEMATICAL FOUNDATION OF CS 168 SUM field1, field2 …-- Sums specified field names and displays the results below. SUM QTY, COST, PRICE*1.05 105 records summed Qty cost price 2309 34523.48 74560.86 SUM fieldname TO memory variable – Sums specified field name to the named memory variable. SUM QTY TO MQTY SUM QTY, COST TO MQTY, MCOST SUM fieldname TO array—Sums specified field name to the named memory array. You must DIMENSION or DECLARE an array before you can store results from the SUM command to that array.
DIMENSION MQTY(50), MCOST(50) STORE 0 TO MQTY (1), MCOST (1) SUM QTY TO MQTY (1) SUM QTY, COST TO MQTY (1), MCOST(1) SUM fieldname TO memory variable FOR expression – Sums specified field name to named memory variable for those records that match the specified expression.
SUM QTY TO MQTY FOR COST>.99 SUM fieldname TO memory variable WHILE expression – Sums field name to named memory variable while expression is true. If expression becomes false, summing ceases.
SUM QTY TO MQTY WHILE COST <= 100.00 SUSPEND, RESUME DESCRIPTION
This pair of commands lets you suspend operating a command file temporarily and then resume it. You can suspend program operation in three ways. First, you can enter SUSPEND on a command line. When encountered, program operation ceases and FoxPro displays the command window. A second way is to press the Esc Key during a program input-output operation. This pauses p[program operation displays.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
137
MATHEMATICAL FOUNDATION OF CS
The FoxPro program “remembers” the position of the last line used in the command file. Use the RESUME command to restart program operation where you left off.
If you design your command file to display information, it is a good practice to clear your screen or window with the CLEAR command before resuming program operation. Otherwise, you may have confusing screen clutter and any commands entered during program suspension may interfere with future screen or window input-output operations. A third way to stop operation is to enter an error in a command file. The error stops normal operation and displays an error message followed by the “Cancel, Ignore, or Suspend?” prompt. If you choose suspend, FoxPro returns you to the Command Window. Here, you may be able to examine the problem. Once fixed, you can restart program operation with RESUME. The third option is not a graceful way to suspend operation and you should avoid it. TEXT, ENDTEXT DESCRIPTION You use the TEXT and ENDTEXT commands to display text to the screen, to a window, or to a printer. Because you use both of these commands in command files, you should not enter them at the Command Window. You can use the \and\\commands to facilitate text merge in FoxPro. This lets you output text to a file to create form letters or programs. The TEXT command lets you enter multiple lines of text. The ENDTEXT command terminators the TEXT statement. Below is an example of how you can use the TEXT and ENDTEXT commands within command files. CLEAR SET TALK OFF TEXT Use this program to enter customer information from invoices, change customer information, or delete obsolete customer information. Before starting, be sure you have all the latest customer paperwork available. ENDTEXT WAIT CLEAR TEXT --------------------------------------------------------------Customer Information System -------------------------------------------------------------ENDTEXT
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
138
MATHEMATICAL FOUNDATION OF CS WAIT ‘
139
’ TO CHOICE :
(more command lines) : The \ and \\ Commands: These commands cause FoxPro to merge text with the contents of database fields, memory variables, and the results of functions and expressions. If you enclose a database field, memory variable, function, or expression with text merge delimiters, FoxPro evaluates the contents and merges the values with the text. The default delimiters are the << and >> symbols. You can create your own text merge delimiters using the SET TEXTMERGRE DELIMITERS command. The following example illustrates this. SET DELIMITERS TO “&”
This command replaces both the << and >> delimiters with the % symbol. Remember, you use delimiters to enclose the contents of database fields, memory variables and the results of functions, and expressions. The following example, illustrates this. \Today is <DTOC(DATE( ))>> The resulting output is: Today is 09/28/91 Another command you use with the \and\\commands is the SETMERGE command to specify the text merge output file. If you do jot direct the text merge to a file, FoxPro outputs the text line only to the screen. If you want to suppress the screen output, include the NOSHOW clause with the SET TEXTERGE command.
SET TEXTMERGE TO file_name
&& Opens or creates the file
Or SET TEXTMERGE TO file_name NOSHOW && Suppresses screen output
When you use one backslash (\), FoxPro causes a carriage return and line feed to precede the results of the output line. Using two backslashes (\\), does not place a carriage return and line return before the output line. This is identical to the ?and ?? commands. The following example illustrates this. SET TEXTMERGE DELIMITERS TO “#” SET TEXTMERGE TO letter.txt USE customer SET TEXTMERGE ON
&& Creates new delimiters. && Sends output to file. && Opens CUSTOMER database. && Activates TEXTMERGE.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS \ #DTOC(date( ))#
140 && Outputs DATE>
\
&& Blank line.
\Dear #CUSTOMER-LAST_NAME#
&& Outputs data from table.
\
&& Blank line.
\Body of Text
&& Body of Text.
\
&& Blank line.
\Sincerely,
&& Outputs text.
\
&& Blank line.
\
&& Blank line. \The manager.
&& Outputs text.
TOTAL DESCRIPTION
Use the TOTAL command to transfer the sum of matching fields to a designated database file. This command consolidates the matching fields and sums the designated fields, which you must index or sort before you use this command.
Clearly, an example is in order. Imagine that you have an inventory database with multiple entries for the same part number. The part number field is a key field (one that you must index or sort). If you wish ton determine the total quantity on hand for each part number, you can TOTAL ON the part number field to a database file, specifying the quantity field. The Typical Operation section of this module demonstrates this process. The following list contains forms of the TOTAL command and corresponding examples. TOTAL TO filename ON fieldname â&#x20AC;&#x201C; Totals the numeric values for those records having the same contents in the designated filed name. The command copies the database in use to the specified filename. If the database exists, it uses the existing structure. If it is a new database, the command copies the structure of the database in use. TOTAL ON PART_NO TO LUMBER1 TOTAL TO filename ON fieldname FIELDS field1, field2 â&#x20AC;Ś -- Totals the numeric values for those records having the same contents in the designated field name. The FIELDS clause limits the totaling to only those fields listed in the command. Without the fields clause, the command totals all numeric fields. TOTAL ON PART_NO TO LUMBER1 FIELDS PART_NO, QTY, COST, PRICE
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
MATHEMATICAL FOUNDATION OF CS TOTAL TO filename ON fieldname FIELDS field1, field2 … ; FOR expression – This is the same as the previous command except that the FOR clause selects only those records matching the expression.
TOTAL TO LUMBER1 ON PART_NO FIELDS PART_NO, QTY, COST FOR QTY>0. TOTAL To filename ON fieldname WHILE expression – This command form operates as long as it satisfies the expression. IF the expression becomes invalid, the totaling process ends. In the following example, if the command encounters a value that is greater than 10 in the QTY field, the totaling process stops.
TOTAL TOM LUMBER1 ON PART_NO WHILE QTY <= 10
UPDATE DESCRIPTION
Use the UPDATE command to combine the contents of two databases. This command allowed you to replace the contents of one or more fields in a database with the contents of one or more fields from another database. The selected work area must contain the target database that you are updating. The source database must also be in an actives but unselected work area. (information about selecting work areas, see Module 85.)
The general form of the UPDATE command is: USE target UPDATE ON key field FROM source REPLACE field; WITH expression
To replace several fields, you can use the form:
USE target UPDATE ON key. field FROM source REPLACE field; WITH expression, field2 WITH expression,; Fields WITH expression … The key (or indexed) field must have the same field name in both the source and target databases.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
141
MATHEMATICAL FOUNDATION OF CS A key field is one that you can use as a basis for sorting or indexing. One final form of the UPDATE command uses the RANDOM statement. This statement; permits you to use a source database that you must index. That is, you do not have to sort or index the target database. However, you must always sort or index the source database for UPDATE to operate properly.
Here is an example of how you can use the UPDATE command. Assume that you have to databases that contain inventory quantities. The target database, called WHSE (for ware house), contains parts in your warehouse. The source database is WIP (for work in process). If you want to update the WHS database to those part counted in WIP, you can use the UPDATE command.
If the key field name in both databases is PART_NO and the field containing the quantity is QTY, you can proceed as follow:
SELECT 1 USE WIP ALIAS SOURCE SLECT 2 USE WHSE ALIAS TARGET UPDATE ON PART_ON FROM SOURCE REPLACE QTY WITH QTY+WIP->QTY
This series of commands puts WIP and WHSE in work areas 1 and 2. The command leave WHSE in the active work area. The UPDATE command adds the contents of the QTY (or quantity) fields. It also replaces the WHSE quantity values with their present value plus the quantity value in the WIP database. Look at the following list.
USE DESCRIPTION To use the information within a database, it must be open, or “in use.” The USE command followed by a database filename and Return opens the named database file, or “puts it in use.” The USE command also opens associated index and memo files, where memo files contain text and have the extension .
OPENING A DATABASE WITH USE If you try to enter a FoxPro command that interacts with a database file without a database in use, the FoxPro dialog window appears.
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
142
MATHEMATICAL FOUNDATION OF CS If this happens, just move the highlight bar to select the database filename, such as MEMBERS for the MEMBERS database file, and press Return. This opens the database, or puts it in use.
The conventional way to put a database in use is to type the USE command followed by the database filename, like:
USE MEMBERS
If you want to direct your command to a disk other than the default disk, prefix the filename with the disk designator. For example, using the command USE B:MEMBERS opens the MEMBERS database on drive B.
If database has associated index files, you can place the database and index files in use and assign an alias name to the entire group of files. For example, let’s assume that the MEMBERS database has two index files named NAMELIST and JOINDATE. You can open the database and the two index files (up to 25 index files are possible) and assign an alias name to the group with the command:
USE MEMBERS INDEX NAMELIST, JOINDATE ALIAS MBR
Your can have as many as 25 databases in use concurrently.
WAIT DESCRIPTION
You use the WAIT command to pause command file operation until you press a key. When you as the WAIT command without following text, FoxPro displays the prompt “Press any key to continue…”. Pressing a key continues command file operation. Pressing Esc interrupts the command file operation, and you can return to the Command Window. The following list includes forms of the WAIT command. You can enter the command examples from the FoxPro command Window if you want to be sure how they work. WAIT---Pauses operation and displays “Press any key to continue…”
WAIT
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
143
MATHEMATICAL FOUNDATION OF CS WAIT ‘Prompt’ --- Pauses operation and displays prompt enclosed in quotes or square brackets. WAIT ‘Read the text and press a key to continue..’ WAIT TO MVAR – Pauses operation, displays the “Press any key…” Prompt, and stores pressed key to the specified memory variable.
WAIT TO CHOICE WAIT ‘Type a letter’ TO MVAR – Pauses operation, displays “Type a letter” as a prompt, and stores the first key pressed to the specified memory variable. WAIT ‘TYPE 0 – 9’ TO CHOICE WAIT SPACE(1) TO MVAR – Pauses operation, suppresses display of a prompt, and store value of pressed key to the specified memory variable. .
WAIT SPACE (1) TO CHOICE
WAIT TIMEOUT 1.5 -- Pauses operation for a specified number of seconds for a keyboard input. If FoxPro terminates the WAIT by a TIMEOUT, FoxPro returns a null string. WAIT WINDOW 1.5 – Displays the WAIT message in a system message window in the upper right-hand corner of the screen.
If you entered these examples, you can see the results of the keys you typed by typing DISP MEMO and pressing Return. To release the memory variables, type RELEASE ALL and press Return.
Notice how the WAIT TO form of the command differs from WAIT as it stores the value of the pressed key to the designated memory variable. You may recall from Module 3 how you use the ACCEPT and INPUT commands to store either character or numeric strings to a named memory variable. In contrast, WAIT TO stores only a single character – the value of the first typed key.
----------------------------------------------------------THE END-----------------------------------------------
FOR MORE DETAILS VISIT US ON WWW.IMTSINSTITUTE.COM OR CALL ON +91-9999554621
144
MATHEMATI CALFOUNDATI ONOFCS
Publ i s he dby
I ns t i t ut eofManage me nt& Te c hni c alSt udi e s Addr e s s:E4 1 , Se c t o r 3 , No i da( U. P) www. i mt s i ns t i t ut e . c o m| Co nt a c t :9 1 +9 2 1 0 9 8 9 8 9 8