• No results found

Vedic Maths C++ with source code

N/A
N/A
Protected

Academic year: 2021

Share "Vedic Maths C++ with source code"

Copied!
63
0
0

Loading.... (view fulltext now)

Full text

(1)

Computer Science Project

Vedic Mathematics

Teacher

(With illustration)

Please review this project.

[email protected]

By- Ashish Chaudhary XII A Computer Science Army Public School, Meerut Cantt. Board Roll No. 5716336

(2)

Contents:

1.)

Acknowledgement

2.)

System Requirements

3.)

Introduction To Vedic Mathematics

4.)

Advantages of Vedic Mathematics

5.)

Use of Vedic Mathematics in the field of Computers

6.)

Vedic Mathematics in schools and colleges

7.)

Researches on Vedic Mathematics

8.)

The Vedic Mathematics - Sutras

9.)

Basics of Vedic Mathematics

10.)

Concepts of C++ used

11.)

The Code

12.)

References

(3)

Acknowledgement

I would like to express my special thanks of gratitude to my teacher Mr. Sachin Chahal

as well as my school Army Public School, Meerut Cantt. who gave me the golden

opportunity to do this project on the

topic

Vedic Mathematics Teacher With

illustration

, which also helped me a lot in remodeling the way I calculate and also I

came to know about so many new things.

I am really thankful to them.

Secondly i would also like to thank my parents and friends who helped me a lot in

finishing this project within the limited time.

THANKS AGAIN TO ALL WHO HELPED ME.

Certificate

This is to certify that Ashish Chaudhary (Board Roll No. 5716336) of class

XII A, Army School Meerut Cantonment has successfully completed his

project work on the topic

“Veda Mathematics Teacher ( With

Illustration).”

(4)

System Requirements:

Minimum System Requirements for running the program:

• Intel Pentium II/300 MHz or better

• Microsoft Windows Server 2003 (SP1)Microsoft Windows XP Professional

(SP2)Windows 2000 Professional (SP4)Windows 2000 Server (SP4)

• 128 MB RAM or better

• CD-ROM or DVD-ROM drive

• SVGA or higher-resolution monitor (XGA recommended)

The following C++ program has been constructed via a free

software Turbo C++ for windows 7 and has been compiled on

Windows 8 Professional 32-bit (6.1, Build 7601) Service Pack 1.

The program has been successfully compiled with the following specifications of the machine used:

---System Information

---Time of this report: 1/11/2013, 18:36:32 Machine name: GAMING-PC

Operating System: Windows 8 Professional 32-bit (6.1, Build 7601) Service Pack 1 (7601.win8sp1_rtm.101119-1850)

(5)

System Manufacturer: INTEL_ System Model: DG41RQ__

BIOS: BIOS Date: 02/08/08 17:50:03 Ver: 08.00.10

Processor: Intel(R) Core(TM)2 Quad CPU E7500 @ 2.93GHz (4 CPUs), ~2.9GHz Memory: 6144MB RAM

Available OS Memory: 6144MB RAM

Page File: 1287MB used, 2800MB available Windows Dir: C:\Windows

DirectX Version: DirectX 11 DX Setup Parameters: Not found User DPI Setting: Using System DPI

System DPI Setting: 96 DPI (100 percent) DWM DPI Scaling: Enabled

DxDiag Version: 6.01.7601.17514 32bit Unicode

---Display Devices

---Card name: AMD Radeon HD 6990

Manufacturer: Advanced Micro Devices, Inc. Chip type: ATI display adapter (0x954F) DAC type: Internal DAC(400MHz)

Device Key: Enum\PCI\VEN_1002&DEV_954F&SUBSYS_03541043&REV_00 Display Memory: 2803 MB

(6)

Dedicated Memory: 2038 MB Shared Memory: 765 MB

Current Mode: 1980 x 1080 (32 bit) (120Hz) Monitor Name: Generic PnP Monitor

Monitor Model: W2043 Monitor Id: GSM4E9E

Native Mode: 1980 x 1080(p) (120.000Hz) Output Type: DVI

Driver Name: aticfx32.dll,aticfx32.dll,atiumdag.dll,atidxx32.dll,atiumdva.cap Driver File Version: 8.17.0010.1129 (English)

Driver Version: 8.970.100.3000 DDI Version: 10.1

Driver Model: WDDM 1.1 Driver Attributes: Final Retail

Driver Date/Size: 7/4/2012 11:57:08, 918528 bytes WHQL Logo'd: No

WHQL Date Stamp: None

Device Identifier: {D7B71EE2-D60F-11CF-9A77-5E23BEC2C535} Vendor ID: 0x1002

Device ID: 0x954F

SubSys ID: 0x03541043 Revision ID: 0x0000 Driver Strong Name:

(7)

Rank Of Driver: 00E62001

---Sound Devices

---Description: Speakers (Realtek High Definition Audio) Default Sound Playback: Yes

Default Voice Playback: Yes Hardware ID:

HDAUDIO\FUNC_01&VEN_10EC&DEV_0662&SUBSYS_8086D613&REV_1001 Manufacturer ID: 1

Product ID: 100 Type: WDM

Driver Name: RTKVHDA.sys

Driver Version: 6.00.0001.6662 (English) Driver Attributes: Final Retail

WHQL Logo'd: Yes

Date and Size: 6/19/2012 16:54:20, 3240400 bytes Other Files:

Driver Provider: Realtek Semiconductor Corp. HW Accel Level: Basic

Cap Flags: 0xF1F

(8)

Introduction To Vedic Mathematics

About a hundred years ago the scholars in the west discovered the Indian

Vedas: ancient texts in their millions containing some of the most profound

knowledge. In fact the Sanskrit word ‘Veda’ means ‘knowledge’. They found

Vedic texts on medicine, architecture, astronomy, ethics etc and according

to the Indian tradition all knowledge is contained in these Vedas.

The age of these Vedic texts is disputed, tradition telling us that oginally the

Vedas were carried on by word of mouth, by pandits who recited the texts

exactly and passed them on to their children.

However certain writings that were entitled Ganita Sutras, which means

mathematics, were not found to contain any mathematics and the scholars

rejected them saying they were nonsense.

Now a brilliant eastern scholar, Sri Bharata Krsna Tirthaji (1884-1960),

heard what was being said about the Ganita texts and determined to

uncover the mathematics in them. Between 1911 and 1918 he studied the

texts and eventually was able to reconstruct the system that had been lost

long ago.

He discovered that all of mathematics is governed by just sixteen sutras or

word-formula (and some sub-Sutras), and he showed some really amazing

examples of their power and versatility. He wrote sixteen books (one on

each sutra) but these have been lost. In 1958 when the loss was confirmed

he wrote an introductory book, which is currently available (Reference 1).

Recent attempts to reconstruct the system from this book have led to an

upsurge of interest and the Vedic system which being taken up by

(9)

Advantages of Vedic Mathematics:

We are living in the age of tredemdous amount of competitions and Vedic

Mathematics methods come to us as a boon for all the competitions.

Present maths,a scary subject requires higher amount of effort in learning.

Maths can be learnt and mastered with miminum efforts in a very short

span of time and can be translated into a playful and a blissful subject with

the help of Vedic Maths.

The several advantages of Vedic Maths are:

It reduces the burden of remembering large amount of stuff because it

requires you to learn tables upto 9 only.

It enables faster calculations when compared to the conventional

method. Thus, the time that gets saved in the process can be used to

answer more questions

It acts as a tool for reducing finger counting and scratch work.

It plays an important role in increasing concentration as well as

improving confidence.

It is very simple, direct, totally unconventional, original and straight

forward.

It encourages mental calculations.

It enriches our understanding of maths and enables us to see links and

continuity between different branches of maths.

Vedic Maths system also gives us a set of checking procedures for

independent crosschecking of whatever we do.

It keeps the mind alert and lively because of th element of choice and

flexibility at each.

Holistic development of the human brain takes place through Vedic

Mathematics along with multidimensional thinking.

Vedic Mathematics system to quite an extent also helps us in

(10)

It can introduce creativity in intelligent and smart students, while

helping the slow-learners grasp the basic concepts of mathematics. More

and more use of Vedic math can without any doubts generate interest in a

subject that is generally dreaded by children.

Thus, Vedic maths is considered to be more than the blessing of the Veda

for the entire humanity.

A large number of people in the field of education, especially maths

professors consider Vedic Maths to be a new and a better approach in

studying and understanding Maths. Even students studying at the Indian

Institute of Technology are said to be making use of this technique for

quicker calculations. Several other institutes are also emphasizing the

significance of Vedic Maths.

(11)

Use of Vedic Mathematics in the field of Computers:

Vedic mathematics is used by

several researchers in the field of

Digital signal processing, Chip

designing, Discrete Fourier

Transform , High speed low power

VLSI arithmetic and algorithm, RSA

encryption system . Most of the

researchers have used the vedic

mathematics method such as

multiplication, division, squares

and cubes in above mention fields.

VLSI Implementation of RSA

encryption

H. Thapliyal implementated RSA

encryption or decryption algorithm

using the algorithm of ancient

Indian vedic mathematics which is

being modified to improve the

performance .The most significant

aspect is the development of

divisor architecture based on

straight division algorithm of Vedic

mathematics and embedding it in

RSA encryption or decryption

circuitry for improved efficiency

.They proved that RSA circuitry

implemented using vedic division

and multiplication is efficient in

terms of area and speed compared

to its implementation using

conventional multiplication and

division architecture.

Multiplier and square

architecture

Time, area and power efficient

multiplier and square architecture

based on ancient Indian vedic

mathematics is developed by H.

Thapliyal. Developed algorithm was

for low power and high speed

applications. It is based on

generating partial product and their

sums in one step. The design

implemented is described at both

gate and

high level using verilog Hardware

Description Language. The design

code is tested using

“Veriwelsimulator. Their work

relates to the field of mathematical

coprocessor in computers and

more specifically to improve speed

and power over the conventional

co-processor. The Vedic multiplier

and square architecture developed

by them were faster than array

multiplier and booth multiplier in

FPGA implementation.

(12)

Digital Signal Processing

Digital Signal processing is a

technology that is present in

almost every engineering

discipline. It is also the fastest

growing technology of the century

and hence it posses tremendous

challenges to the engineering

community. Faster addition and

multiplication are of extreme

importance in DSP for Convolution,

DFT and Digital filters .The core

computing process is always a

multiplication routine and hence

DSP

engineers are constantly looking

for new

algorithms and hardware to

implement them. The methods in

Vedic Mathematics are

complementary directly and easy.

Mr. Mangesh Karad and Mr.

Chidgupkar highlight the use of

multiplication process based on

vedic algorithms and implemented

on 8085 and 8086 microprocessors

. Use of Vedic algorithms shows

appreciable saving of processing

time.

ALU Design

The ever increasing demands in

enhancing the ability of processors

to handle the complex and

challenging processes has resulted

in the integration of number of

processor cores into one chip still

the load on processor is not less.

This load is reduced by

supplementing the main

coprocessor which is designed to

work on specific types of functions

like numeric computations, signal

processing, graphics etc. The speed

of ALU depends on the multipliers.

In algorithm and structure levels,

numerous multiplication techniques

have been developed to enhance

the efficiency of multiplier which

concentrates on reducing the

partial product and their additions.

But in this case principle behind

the multiplication remains same.

Use of Vedic mathematics for

multiplication strikes difference in

actual process. M. Ramalatha used

Urdhva tiryakbhyam Sutra of Vedic

mathematics to build a high speed

power efficient multiplier in the

coprocessor. Using Vedic

techniques various arithmetic

modules can be designed and

integrated into a Vedic ALU, which

is compatible for co-processor. The

advantages of Vedic multipliers are

increase in speed, decrease in

delay, decrease in power

consumption and decrease in area

occupancy. This Vedic coprocessor

is more efficient than the

conventional one.

Performance Analyses of Vedic

Algorithms

Various parameters are

recommended by

researchers to evaluate the

performance of Vedic Maths

algorithm. Researchers suggested

many parameters few of them are:

(13)

Time, Delay, Power and Number of

slices. The following table shows

the comparison of Delay (ns) factor

for multiplication implemented in

different algorithms between

Conventional

and Vedic way.

Conclusion

Vedic mathematics can be used in

implementation of fast algorithms

in various fields of engineering.

The performance analysis of Vedic

algorithms is done on the basis of

delay. This shows efficiency of

Vedic multiplier interms of high

speed and less complexity.

(14)

VEDIC MATHS IN SCHOOLS AND COLLEGES:

A few years ago several schools began to teach the Vedic system. The

response received was so huge that this remarkable system is today in

many schools and institutions in India as well as abroad. It is not only

taught in schools but also to a lot of MBA and Economic students. There are

obviously many benefits of making use of a flexible, distinguished and

proficient mental system like Vedic math. Pupils can come out of the

imprisonment of the ‘only one correct’ way, and make their own distinct

methods under the Vedic system.

Ever since the year 1999, a forum which has been initiated in Delhi called

International Research Foundation for Vedic Mathematics and Indian

Heritage, has arranged several lectures on Vedic maths in various schools

and colleges in Delhi.

(15)

RESEARCHES ON VEDIC MATHS:

People like Aryabhatta, who laid the foundation of Algebra, Baudhayan, the great geometer and the saint duo, Medhatithi and Madhyatithi, who formulated the basic structure for numerals, have conducted large number of researches. Several research programmes have currently been undertaken in many areas. These researches have been initiated in order to try and find the effects of learning Vedic maths on children, to develop more commanding and simple applications of the Vedic sutras in different fields such as geometry, calculus, and computing.

(16)

THE VEDIC MATHEMATICS – SUTRAS

Sutras: The Natural Formula

In Sanskrit, the ancient language of India, the word Sutra means "Thread of

Knowledge". In English we have the word Suture from Sutra and Suture is the

thread used for stitching wounds together. So each rule is a thread of knowledge and the whole subject is based on these sutras. The system is based on 16 Vedic Main-Sutras together with 13 Sub-Sutras which are actually word formulae

describing natural ways of solving a whole range of mathematical problems. These are 16 one-line formulae originally written in Sanskrit,

which can be easily memorized, enable one to solve long mathematical problems quickly.

• The Sutras (aphorisms) apply to and cover each and every part of each and every chapter of each and every branch of mathematics (including Arithmetic, Algebra, Geometry – plane and solid, Trigonometry – plane and spherical, Conics – geometrical and analytical, Astronomy, Calculus – differential and integral etc.) In fact, there is no part of mathematics, pure or applied, that is beyond their jurisdiction.

• The Sutras are easy to understand, easy to apply and easy to remember, and the whole work can be truthfully summarized in one word ‘Mental’!

(17)
(18)

Basics Of Vedic Mathematics:

1

GIVE AND TAKE

A Addition and subtraction always seem to come together. For example, if you take some money out of your pocket it is now in your hand but is no longer in your pocket.So it is no surprise that there is a Vedic Sutra for this:

By Addition and By Subtraction

We naturally use this when, say, we add 55 and 19.

Most people will add 20 and take 1 away, so 55 + 19 = 74.

Similarly for 198 + 64 we could add 200 to 64 and take off 2 after. So 198 + 64 = 262.

In the same way we can subtract easily:

For 44 – 19 we take 20 from 44 and add 1 back on. So 44 – 19 = 25.

And for 333 – 198 we can take 200 from 333 and add 2 back. We get 333 – 198 = 135.

This is what many people would naturally do. B For this we use the Sutra:

All from 9 and the Last from 10 To take 357 from 1000 for example,

we apply All from 9 and the Last from 10 to the figures of 357. So 1000 – 357 = 643.

We take the 3 from 9 to get 6, take the 5 from 9 to get 4,

and take the 7 from 10 to get 3. Similarly 10,000 – 7621 = 2379,

we take 7, 6 and 2 from 9 and the 1 from 10.

If the number of figures in the number being subtracted is less than the number of zeros in the base number, we just add as many zeros as needed to make them the same:

For example in 10,000 – 643 there are four zeros and only three figures in 643. So we write 10,000 – 0643 so that 0643 has four figures.

Then 10,000 – 0643 = 9357.

(We take 0, 6, 4 from 9 and 3 from 10)

(19)

Now suppose with don’t have a base number, but a multiple of it: like 200, 3000 etc.

Suppose you had 3000 – 444. We get 3000 – 444 = 2556.

The 444 will come off one of the three thousands, so the initial 3 becomes 2. Then applying “All from 9 and the Last from 10” to the 444 we put down 556. Similarly 700 – 52 = 648.

The 7 reduces to 6, and applying the sutra to 52 gives 48. There is one thing to be careful of though.

Suppose you had 7000 – 430.

When you apply the Sutra to 430 you just apply it to the 43, not to 430. So you get 7000 – 430 = 6570.

(7 becomes 6, the Sutra converts 43 to 57 and the zero is carried over).

C Amazingly, this simple method can handle all subtractions! Suppose we had: 444 – 286.

Subtracting in each column we get 4 – 2 = 2, 4 – 8 = –4, 4 – 6 = –2. Since these negative answers can be written like this :

2 (42) and 2 (42) is easily converted into 158 because this is just the kind of sum you have just done:

2 (42) means 200 – 42 = 158. Similarly

6767-1908= 5(2)6(1)

Here to convert 5(2)6(1) we split it into 5(2) / 6(1)

and 5(2)=48 (because 50-2) also 6(1)=59 (because 60-1=59).

(20)

MIGHTY MULTIPLICATIONS

In the Vedic system there are general methods that always work (see Chapter 3 for general multiplication) and there are special methods which can be

applied in special cases. Here we look at a very powerful special method that works when the numbers are near a base number (like 10, 100, 1000 etc.) or a multiple of a base

number.

A Numbers below a base number. 88 × 97 = 8536

We notice here that both numbers being multiplied are close to 100: 88 is 12 below 100, and 97 is 3 below it.

So we write 88 = 88(3) or 97= 97(12) which is equal to 88-3=85 or 97-12=85 (whichever you like).

Then we multiply the deficiencies ie 12 and 3 to get 12 × 3= 36. So the answer (in two parts) becomes 85 / 36 = 8536.

Similarly, 93 × 96 = 8928 Deficiencies are 7 and 4 so 93 =93(4) and 96= 96(7)

Which equals 93-4=89 or 96-7=89. Then 7 × 4= 28.

Therefore the answer is 89 / 28 =8928. 89 × 89= 7921

Here the first part is 89(11)=89-11=78 and multiplying the deficiencies gives 121.

So we write 21 out of the 121 and carry 1 to 78 to become 79. This gives the answer is 79 / 21 =7921.

876 × 998 = 874 / 248

Same rule here, but the base number is 1000 so the deficiencies are 1000-876= 124 by All from 9 and the Last from 10 sutra and 1000-998=2.

(21)

So the answer is 874 / 248 = 874248.

D But this is not all: if the numbers are above the base number the method still works:

103 × 104 = 10712

Here the excess is 103-100=3 and 104-100=4.

So the first part in this case becomes 103+4=104+3=107 and the second part becomes 4×3=12.

This gives the answer 10712.

E But suppose one number is above the base and the other number is below it.

Can the method still be used? The answer is yes, most certainly. 124 × 98 = 122(48)= 12152

Here the base number is 100 and the deficiency is 100-98=2 also the efficiency is 124-100=24.

Therefore the first part is 124-2 or 98+24= 122 (whichever you like), the second part is 24×minus 2 =(48).

So the answer is 122(48)= 12200-48. Now applying All from 9 and the Last from 10 sutra 122 becomes 121 and 48 gives 52 therefore the answer becomes 12152.

F Let’s look at one more extension of this method: where the numbers are not near a base number, but are near a multiple of a base number, like 30, 200, 6000.

In fact we use a sub-sutra called Proportionately. 213 × 203 = 2 × 216/39 = 43239

Here excess is 213-200=13 and 203-200=3.

We observe here that the numbers are not near any of bases used before: 10, 100, 1000 etc. But they are close to 200, and are 13 and 3 above 200. The usual procedure gives us 216/39 (213+3=216, 13×3=39).

(22)

part of the answer by 2 to get 43239.

29 × 28 = 3×27/2 = 812

Deficiency is 30-29=1 and 30-28=2.

So 29-2=28-1= 27 and 3 × 27=81 and 2 × 1 =2, therefore the answer becomes 812.

3

(23)

_____________________________________________________

The Vedic Sutra Vertically and Crosswise enables us to multiply any two

numbers together in one line (from left to right or from right to left) no matter how big the numbers are.

A Let us start with multiplying 2-figure numbers. 21 × 23 = 483

we put the numbers one below the other and multiply: A. vertically on the right,

B. then crosswise and add,

C. and then vertically on the left. C. multiply vertically in the right-hand column: 1 × 3 = 3,

so 3 is the last figure of the answer. D. multiply crosswise and add: 2 × 3 = 6,

1 × 2 = 2, 6 + 2 = 8,

so 8 is the middle figure of the answer. E. multiply vertically in the left-hand column: 2 × 2 = 4,

4 is the first figure of the answer. So the answer is 483.

The previous examples involved no carry figures, so let us consider this next. 23×41=943

The 3 steps give us: 3×1 = 3,

2×1 + 3×4 = 14, so we carry 1 to the left as shown. 2×4 = 8, and 8 + the carried 1 = 9.

So 23 × 41 = 943.

(24)

a.

Switch case:

switch ( expression )

case constant-expression : statement [default : statement]

If a matching expression is found, control is not impeded by

subsequent case or default labels. The break statement is used to stop execution and transfer control to the statement after the switch statement.

Without a break statement, every statement from the matched case label to the end of the switch, including the default, is executed.

For example:

// switch_statement1.cpp #include <stdio.h>

int main() {

char *buffer = "Any character stream"; int capa, lettera, nota;

char c;

capa = lettera = nota = 0;

while ( c = *buffer++ ) // Walks buffer until NULL { switch ( c ) { case 'A': capa++; break; case 'a': lettera++; break; default: nota++; } }

printf_s( "\nUppercase a: %d\nLowercase a: %d\nTotal: %d\n", capa, lettera, (capa + lettera + nota) );

}

In the above example, capa is incremented if c is an uppercase A.

The break statement after capa++ terminates execution of the switch statement body and control passes to the while loop. Without

(25)

the break statement, lettera and nota would also be incremented. A similar purpose is served by the break statement for case 'a'. If c is a

lowercase a, lettera is incremented and the break statement terminates the switch statement body. If c is not an a or A, the default statement is executed.

A switch statement can be nested. In such cases, case or default labels associate with the closest switch statement that encloses them.

////////////////////////////////////////////////////////////////////////

b. Classes:

A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.

An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable.

Classes are generally declared using the keyword class, with the following format: class class_name { access_specifier_1: member1; access_specifier_2: member2; ... } object_names;

Where class_name is a valid identifier for the class, object_names is an optional list of names for objects of this class. The body of the declaration can contain members, that can be either data or function declarations, and optionally access specifiers.

All is very similar to the declaration on data structures, except that we can now include also functions and members, but also this new thing called access

specifier. An access specifier is one of the following three

keywords:private, public or protected. These specifiers modify the access rights that the members following them acquire:

• private members of a class are accessible only from within other members of the same class or from theirfriends.

(26)

• protected members are accessible from members of their same class and from their friends, but also from members of their derived classes.

• Finally, public members are accessible from anywhere where the object is visible.

By default, all members of a class declared with the class keyword have private access for all its members. Therefore, any member that is declared before one other class specifier automatically has private access.

For example:

class CRectangle {

int x, y; public:

void set_values (int,int); int area (void);

} rect;

Declares a class (i.e., a type) called CRectangle and an object (i.e., a variable) of this class called rect. This class contains four members: two data members of type int (member x and member y) with private access (because private is the default access level) and two member functions with public

access: set_values() and area(), of which for now we have only included their declaration, not their definition.

////////////////////////////////////////////////////////////////////

c. Scope Resolution:

‘::’ is known as Scope Resolution Operator. C++ is a block structured language. Different program modules are written in various blocks. Same variable name can be used in different blocks. Scope of a variable extends from the point of

declaration to the end of the block. A variable declared inside a block is ‘local’ variable. Blocks in C++ are often nested.

e.g. …. …. { int x = 10; …. ….

(27)

{ int x = 20; ….. …. } …. }

The declaration of the inner block hides the declaration of same variable in outer block. This means, within the inner block, the variable x will refer to the data object declared therein. To access the global version of the variable, C++ provides scope resolution operator.

In the above example, x has a value of 20 but ::x has value 10.

Similarly, this operator is used when a member function is defined outside the class e.g. Class MyClass { int n1, n2; public: {

void func1(); ---Function Declaration }

};

public void MyClass::func1() ---Use of Scope Resolution Operator to write function definition outside class definition {

// Function Code }

//////////////////////////////////////////////////////////////////////////////

d. Inheritance:

Inheritance is a mechanism of reusing and extending existing classes without

modifying them, thus producing hierarchical relationships between them.

Inheritance is almost like embedding an object into a class. Suppose that you declare an object x of class A in the class definition of B. As a result, class B will have access to all the public data members and member functions of class A. However, in class B, you have to access the data members and member functions of class A through objectx. The following example demonstrates this:

#include <iostream> using namespace std;

(28)

class A { int data; public:

void f(int arg) { data = arg; } int g() { return data; }

}; class B { public: A x; }; int main() { B obj; obj.x.f(20);

cout << obj.x.g() << endl; // cout << obj.g() << endl; }

In the main function, object obj accesses function A::f() through its data memberB::x with the statement obj.x.f(20). Object obj accesses A::g() in a similar manner with the statement obj.x.g(). The compiler would not allow the statementobj.g() because g() is a member function of class A, not class B. The inheritance mechanism lets you use a statement like obj.g() in the above example. In order for that statement to be legal, g() must be a member function of class B.

Inheritance lets you include the names and definitions of another class's members as part of a new class. The class whose members you want to include in your new

(29)

class is called a base class. Your new class is derived from the base class. The new class contains a subobject of the type of the base class. The following example is the same as the previous example except it uses the inheritance mechanism to give class Baccess to the members of class A:

#include <iostream> using namespace std;

class A { int data; public:

void f(int arg) { data = arg; } int g() { return data; }

};

class B : public A { };

int main() { B obj; obj.f(20);

cout << obj.g() << endl; }

Class A is a base class of class B. The names and definitions of the members of class Aare included in the definition of class B; class B inherits the members of class A. ClassB is derived from class A. Class B contains a subobject of type A. You can also add new data members and member functions to the derived class. You can modify the implementation of existing member functions or data by overriding base class member functions or data in the newly derived class.

(30)

You may derive classes from other derived classes, thereby creating another level of inheritance. The following example demonstrates this:

struct A { }; struct B : A { }; struct C : B { };

Class B is a derived class of A, but is also a base class of C. The number of levels of inheritance is only limited by resources.

////////////////////////////////////////////////

e. if-else ladder:

When in any situation number of conditions arise in a sequence, then we

can use ladder-if

statement.

In this, first condition is checked. If it is true then action will be taken.

Otherwise further

action will be checked and this process will continue till the end of the

condition.

The general syntax of this is :

if(condition 1)

{

statement1

}

else if(condition 2)

{

statement 2;

}

else if(condition 3)

{

statement 3;

}

(31)

...

...

else if(condition n)

{

statement-n;

}

else

{

default statement;

}

Statement -x

Example :

#include <iostream.h>

#include <conio.h>

void main()

{

int x;

int y;

clrscr();

cout << "\nEnter X : ;

cin >> x;

cout << "\nEnter Y : ;

cin >> y;

if ( x > y )

{

cout << "\nX is Greater Than Y";

}

(32)

else if ( y > x)

{

cout << "\nY is Greater Than X";

}

else

{

cout << "\nBoth Are Same";

}

getch();

}

f. File Handling

So far we have done I/O of basic data types. Since the class objects are the central elements of C++ programming, it is quite natural that the language supports features for writing and reading from the disk files objects directly. The binary input and output functions read() and write() are designed to do exactly this job.

The write() function is used to write the object of a class into the specified file and read() function is used to read the object of the class from the file.

Both these functions take two arguments: 1. address of object to be written.

2. size of the object.

The address of the object must be cast to the type pointer to char.

One important point to remember is that only data members are written to the disk file and the member functions are not.

Writing an object into the file #include

(33)

{ private: char name[40]; int age; public: void getData() {

cout << “\n Enter name:”; cin >> name; cout << “\n Enter age:”; cin >> age; }

} ; // End of the class definition void main()

{

Person per ; // Define an object of Person class

per.getData(); // Enter the values to the data members of the class. ofstream outfile(“Person.txt”); // Open the file in output mode

outfile.write((char*)&per, sizeof(per)); // Write the object into the file }

fstream object can be used for both input & output.

In the open() function we include several mode bits to specify certain aspects of the file object.

app -> To preserve whatever was in the file before. Whatever we write to the file will be appended to the existing contents.

We use in and out because we want to perform both input and output on the file. eof() is a member function of ios class. It returns a nonzero value if EOF is

(34)

The Code:

// VEDIC MATHEMATICS TEACHER BY ASHISH CHAUDHARY XII A // CLASS XII PROJECT FOR BOARD EXAMS 2012-2013

#include<iostream.h> #include<conio.h>

(35)

#include<stdio.h> //for gets function #include<process.h> //for exit function #include<fstream.h> class io { public: char name[35]; int n1,n2,k,x1,x2,y1,y2,z1,z2,l1,l2,m1,m2,k1,k2,j; void wel(); void enter1(); void show1(); };

//function definitions of class io

void io::wel() { gets(name); clrscr(); cout<<"\nWelcome "<<name; } void io::enter1() {

(36)

cin>>n1;

cout<<"\nEnter the second number "; cin>>n2; } void io::show1() { clrscr(); if(n1>=n2)

cout<<"\nThe entered numbers are "<<n1<<" and "<<n2; else cout<<"\nERRORENOUS CHOICE "; } class teacher:public io { public: int c; void choice(); void sep(); void add(); void subs(); void might(); void piece(); void give_func(); void mig_func(); void vert_func();

(37)

void mu(); };

//function definitions of class teacher

void teacher::choice() { cin>>c; if(c>0 && c<6) { switch(c) { case 1: clrscr();

cout<<"\nYou have entered piecewise automated illustration as your choice "; piece();

break;

case 2: clrscr();

cout<<"\nYou have entered addition as your choice "; add();

break;

(38)

clrscr();

cout<<"\nYou have entered substraction as your choice "; subs();

break;

case 4: clrscr();

cout<<"\nYou have entered mighty multiplication as your choice "; might(); break; } } else {

cout<<"\nWrong choice, press any key then enter to exit "; cin>>k; exit(c); } } void teacher::sep() { enter1(); x1=n1/100; z1=n1%10; y1=((n1%100)-z1)/10;

(39)

x2=n2/100; z2=n2%10; y2=((n2%100)-z2)/10; l1=(x1+x2)/10; l2=(x1+x2)%10; m1=(y1+y2)/10; m2=(y1+y2)%10; k1=(z1+z2)/10; k2=(z1+z2)%10; } void teacher::add() { sep();

cout<<"\nWe have to find "<<n1<<" + "<<n2; cout<<"\nAdding coloumn wise :";

cout<<"\n"<<x1<<" + "<<x2<<" = "<<x1+x2; cout<<"\n"<<y1<<" + "<<y2<<" = "<<y1+y2; cout<<"\n"<<z1<<" + "<<z2<<" = "<<z1+z2; m2+=k1;

l2+=m1;

cout<<"\nThe excess in 2nd coloumn is "<<m1; cout<<"\nThe excess in 3rd coloumn is "<<k1;

cout<<"\nAdding excess 2nd to the value of coloumn 1 gives "<<x1+x2+m1; cout<<"\nAdding excess 3rd to the value of coloumn 2 gives "<<y1+y2+k1; cout<<"\nTherefore the answer is "<<1000*l1+100*l2+10*m2+k2;

(40)

cout<<"\nThankyou for using the calculator "; }

void teacher::subs() {

sep();

cout<<"\nWe have to find "<<n1<<" - "<<n2; if(n1>=n2)

{

cout<<"\nSubstracting coloumn wise: ";

cout<<"\n"<<x1<<" - "<<x2<<" = "<<x1-x2; cout<<"\n"<<y1<<" - "<<y2<<" = "<<y1-y2; cout<<"\n"<<z1<<" - "<<z2<<" = "<<z1-z2; cout<<"\n The anser (without conversion) is "; cout<<x1-x2; if(y1-y2>0) cout<<y1-y2; else cout<<"("<<y2-y1<<")"; if(z1-z2>0) cout<<z1-z2; else cout<<"("<<z2-z1<<")";

cout<<"\nTo convert, put a 0 in place of (n) and subtract 10*n for tens and n for ones "<<"\n from the resultant number ";

cout<<"\nThe answer in converted form is "<<100*(x1-x2)+10*(y1-y2)+z1-z2; }

(41)

else {

cout<<"\nThis can be written as "<<" -("<<n2<<" - "<<n1<<")";

cout<<"\nWe will first find "<<n2<<" - "<<n1<<" and then add a minus sign "; cout<<"\nSubstracting coloumn wise: ";

cout<<"\n"<<x2<<" - "<<x1<<" = "<<x2-x1; cout<<"\n"<<y2<<" - "<<y1<<" = "<<y2-y1; cout<<"\n"<<z2<<" - "<<z1<<" = "<<z2-z1; cout<<"\n The anser (without conversion) is "; cout<<x2-x1; if(y2-y1>0) cout<<y2-y1; else cout<<"("<<y1-y2<<")"; if(z2-z1>0) cout<<z2-z1; else cout<<"("<<z1-z2<<")";

cout<<"\nTo convert, put a 0 in place of (n) and subtract 10*n for tens and n for ones "<<"\n from the resultant number ";

cout<<"\nThe converted form is "<<100*(x2-x1)+10*(y2-y1)+z2-z1;

cout<<"\nThefore the answer (with minus sign) is "<<100*(x1-x2)+10*(y1-y2)+z1-z2;

} }

void teacher::piece() {

(42)

cout<<"\nThis option lets you learn Vedic Mathematics step by step "; cout<<"\nPress 1 to continue "; cin>>n1; if(n1==1) { clrscr();

cout<<"\nPress 1 to learn the chapter GIVE AND TAKE ";

cout<<"\nPress 2 to learn the chapter MIGHTY MULTIPLICATION ";

cout<<"\nPress 3 to learn the chapter VERTICALLY AND CROSSWISE(smaller multiplications) "; cin>>j; switch(j) { case 1: give_func(); break; case 2: mig_func(); break; case 3: vert_func(); break; default: cout<<"\nInvalid Choice";

(43)

} }

else {

cout<<"\nPress any key then enter to exit "; cin>>n2; exit(n2); } } void teacher::give_func() { clrscr(); ofstream Ofile("d:\\giveandtake.txt",ios::out); clrscr();

cout<<"\nThe first step is GIVE AND TAKE ";

cout<<"\nAddition and substraction always seem to come together. For example if you take some money ";

cout<<"\nout of your pocket it is now in your hand but is no longer in your pocket. So there is no ";

cout<<"\nsurprise there is a Vedic Sutra for this: "; cout<<"\nBY ADDITION and BY SUBSTRACTION ";

cout<<"\nWe naturally use this when,say,we add 55 and 19."; cout<<"\NMost people will add 20 and take 1 away, so 55+19=74";

cout<<"\nIn the same way we can subtract easily: For example 44-19, we take 20 and give 1, so 44-19=23";

(44)

cout<<"\nNow we will apply the vedic sutra for this "; Ofile<<"\nThe first step is GIVE AND TAKE "

<<"\nAddition and substraction always seem to come together. For example if you take some money "

<<"\nout of your pocket it is now in your hand but is no longer in your pocket. So there is no "

<<"\nsurprise there is a Vedic Sutra for this: " <<"\nBY ADDITION and BY SUBSTRACTION "

<<"\nWe naturally use this when,say,we add 55 and 19." <<"\NMost people will add 20 and take 1 away, so 55+19=74"

<<"\nIn the same way we can subtract easily: For example 44-19, we take 20 and give 1, so 44-19=23"

<<"\nThis is what most people do "

<<"\nNow we will apply the vedic sutra for this "; j=0; cout<<"\nPress 1 to continue "; cin>>j; if(j==1) { clrscr();

cout<<"\nTo take 357 from 1000 for example, we apply ALL FROM 9 AND THE LAST FROM 10";

cout<<"\nSo we take 3 from 9 to get 6, take 5 from 9 to get 4, and take the 7 from "; cout<<"\n10 to get 3, so the anser becomes 643.";

cout<<"\nSimilarily 10,000-7621, we take 7,6 and 2 from 9 and 1 from 10 to get the answer 2379.";

cout<<"\nIf the number of figures in the number being subtracted is less than the number of zeroes ";

(45)

cout<<"\nin the bas enumber, we just add as many zeroes as needed to make them the same :";

cout<<"\nFor example in 10,000-643 there are four zeroes and only three figures in 643. ";

cout<<"\nSo we write 10,000-0643 so that 0643 has 4 figures ";

cout<<"\nThen 10,000-0643, we take 0,6,4 from 9 and 3 from 10 to get 9357."; Ofile<<"\nTo take 357 from 1000 for example, we apply ALL FROM 9 AND THE LAST FROM 10"

<<"\nSo we take 3 from 9 to get 6, take 5 from 9 to get 4, and take the 7 from " <<"\n10 to get 3, so the anser becomes 643."

<<"\nSimilarily 10,000-7621, we take 7,6 and 2 from 9 and 1 from 10 to get the answer 2379."

<<"\nIf the number of figures in the number being subtracted is less than the number of zeroes "

<<"\nin the bas enumber, we just add as many zeroes as needed to make them the same :"

<<"\nFor example in 10,000-643 there are four zeroes and only three figures in 643. "

<<"\nSo we write 10,000-0643 so that 0643 has 4 figures "

<<"\nThen 10,000-0643, we take 0,6,4 from 9 and 3 from 10 to get 9357."; } else cout<<"\nInvalid Choice"; j=0; cout<<"\nPress 1 to continue "; cin>>j; if(j==1) { clrscr();

(46)

cout<<"\nNow suppose we don't have a base number, but a multiple of it:like 200,3000 etc.";

cout<<"\nSuppose you had 3000-444. We get 2556. The 444 will come off from one of the ";

cout<<"\nthree thousands, so the initial 3 becomes 2. Then applying the sutra to 444 we get 556.";

cout<<"\nSo the anser is 2556. Similarily 700-52, 7 reduces to 6 and applying the sutra to 52 gives 48 ";

cout<<"\nThere is one thing to be careful of though, suppose you had 7000-4430, "; cout<<"\nWhen you apply the sutra to 430 to have to just apply it to 43, not to 430 and put the ";

cout<<"\n0 as it is. So you get 7000-430=6570 ";

Ofile<<"\nNow suppose we don't have a base number, but a multiple of it:like 200,3000 etc."

<<"\nSuppose you had 3000-444. We get 2556. The 444 will come off from one of the "

<<"\nthree thousands, so the initial 3 becomes 2. Then applying the sutra to 444 we get 556."

<<"\nSo the anser is 2556. Similarily 700-52, 7 reduces to 6 and applying the sutra to 52 gives 48 "

<<"\nThere is one thing to be careful of though, suppose you had 7000-4430, " <<"\nWhen you apply the sutra to 430 to have to just apply it to 43, not to 430 and put the "

<<"\n0 as it is. So you get 7000-430=6570 "; } else cout<<"\nInvalid Choice"; j=0; cout<<"\nPress 1 to continue "; cin>>j; if(j==1)

(47)

{

clrscr();

cout<<"\nNow suppose we had 444-286";

cout<<"\nSubtracting in each coloumn, we get 4-2=2, 4-8=-4, 4-6=-2 "; cout<<"\nThese negative answers can be written as 2(42) ";

cout<<"\nand 2(42) can be easily converted to 158 as this is just the kind of sum yopu have done: ";

cout<<"\n2(42) means 200-42=158.";

cout<<"\nSimilarily 6769-1908=5(2)6(1), we split it into 5(2) / 6(1) "; cout<<"\nand 5(2)=50-2=48 also 6(1)=60-1=59 ";

cout<<"\n"; cout<<"\n";

cout<<"Hope this chapter is clear to you. If not please review again "; Ofile<<"\nNow suppose we had 444-286"

<<"\nSubtracting in each coloumn, we get 4-2=2, 4-8=-4, 4-6=-2 " <<"\nThese negative answers can be written as 2(42) "

<<"\nand 2(42) can be easily converted to 158 as this is just the kind of sum yopu have done: "

<<"\n2(42) means 200-42=158."

<<"\nSimilarily 6769-1908=5(2)6(1), we split it into 5(2) / 6(1) " <<"\nand 5(2)=50-2=48 also 6(1)=60-1=59 "

<<"\n" <<"\n"

<<"Hope this chapter is clear to you. If not please review again. ";

cout<<"\nA text file of the chapter has been generated in D drive. You can take a print out ";

} else

(48)

cout<<"\nInvalid Choice"; j=0; Ofile.close(); } void teacher::mig_func() { ofstream Ofile("d:\\migmul.txt",ios::out); clrscr();

cout<<"\nThe second step is MIGHTY MULTIPLICATIONS ";

cout<<"\nIn the vedic system there are general methods that always work, and there are special methods that can be applied in special cases. ";

cout<<"\nHere we look at a very powerful special mehod that works when the numbers are near a base number (like 10,100,1000 etc ";

cout<<"\nor a multiple of a base."; cout<<"\n";

cout<<"\nNUMBERS BELOW A BASE NUMBER ";

cout<<"\nFor example 88 x 97=8536. We notice that both the numbers being multiplied are close to 100 ";

cout<<"\n88 is 12 below 100 and 97 is 3 below it. ";

cout<<"\nSo we write 88=88(3) or 97=97(12) which is equal to 88-3=85 or 97-12=85 (whichever you like)";

cout<<"\nThen we multiply the deficiencies i.e. 12 and 3 to get 12 x 3 =36. So the answer in two parts becomes 85 / 36 ";

cout<<"\n=8536.";

cout<<"\nSimilarily 93 x 96=8928, the deficiencies are 7 and 4 ";

cout<<"\nSo 93(4)=96(7) is equal to 93-4=89 or 96-7=89. Then 7 x 4=28"; cout<<"\nTherefore the answer is 89 / 28 =8928.";

(49)

Ofile<<"\nThe second step is MIGHTY MULTIPLICATIONS "

<<"\nIn the vedic system there are general methods that always work, and there are special methods that can be applied in special cases. "

<<"\nHere we look at a very powerful special mehod that works when the numbers are near a base number (like 10,100,1000 etc "

<<"\nor a multiple of a base." <<"\n"

<<"\nNUMBERS BELOW A BASE NUMBER "

<<"\nFor example 88 x 97=8536. We notice that both the numbers being multiplied are close to 100 "

<<"\n88 is 12 below 100 and 97 is 3 below it. "

<<"\nSo we write 88=88(3) or 97=97(12) which is equal to 88-3=85 or 97-12=85 (whichever you like)"

<<"\nThen we multiply the deficiencies i.e. 12 and 3 to get 12 x 3 =36. So the answer in two parts becomes 85 / 36 "

<<"\n=8536."

<<"\nSimilarily 93 x 96=8928, the deficiencies are 7 and 4 "

<<"\nSo 93(4)=96(7) is equal to 93-4=89 or 96-7=89. Then 7 x 4=28" <<"\nTherefore the answer is 89 / 28 =8928.";

j=0; Ofile<<"\nPress 1 to continue "; cin>>j; if(j==1) { clrscr(); cout<<"\n876 x 998=874 / 248";

cout<<"\nThe same rule here, but the base number is 1000 so the deficiencies are 1000-876=124 ";

(50)

cout<<"\nand by ALL FROM 9 AND LAST FROM 10 sutra 1000-998=2. So the first part ia 876-2=998-124=874 ";

cout<<"\nand the second part is 124 x 2=248. So the answer is 874 / 248=874248."; cout<<"\n";

Ofile<<"\n876 x 998=874 / 248"

<<"\nThe same rule here, but the base number is 1000 so the deficiencies are 1000-876=124 "

<<"\nand by ALL FROM 9 AND LAST FROM 10 sutra 1000-998=2. So the first part ia 876-2=998-124=874 "

<<"\nand the second part is 124 x 2=248. So the answer is 874 / 248=874248." <<"\n"; } else cout<<"\nInvalid Choice"; j=0; cout<<"\nPress 1 to continue "; cin>>j; if(j==1) { clrscr();

cout<<"\nNUMBERS ABOVE THE BASE NUMBER "; cout<<"\nSuppose 103 x 103=10712";

cout<<"\nHere the excess is 103-100=3 and 104-100=4. So the first part in this case becomes 103+4=107 ";

cout<<"\nor 104+3=107 (whichever you like) and the second part becomes 4 x 3=12. This gives ";

cout<<"\nthe answer 10712. "; cout<<"\n";

(51)

<<"\nSuppose 103 x 103=10712"

<<"\nHere the excess is 103-100=3 and 104-100=4. So the first part in this case becomes 103+4=107 "

<<"\nor 104+3=107 (whichever you like) and the second part becomes 4 x 3=12. This gives " <<"\nthe answer 10712. " <<"\n"; } else cout<<"\nInvalid Choice"; j=0; cout<<"\nPress 1 to continue "; cin>>j; if(j==1) { clrscr();

cout<<"\nONE NUMBER ABOVE THE BASE NUMBER AND ONE BELOW IT "; cout<<"\nSuppose 124 x 98=122(48)=12152 ";

cout<<"\nHere the base number is 100 and the deficiency is 100-98=2 also the excess is 124-100=24 ";

cout<<"\nTherefore the first part becomes 124-2=122 or 98+24=122 (whichever you like)";

cout<<"\nand the second part becomes 24 x minus 2=(48). So the answer is 124(48) ";

cout<<"\n12200-48, now applying ALL FROM 9 AND THE LAST FROM 10 sutra, 122 becomes 121 ";

cout<<"\nand 48 gives 52 therefore the answer is 12152."; cout<<"\n";

(52)

<<"\nSuppose 124 x 98=122(48)=12152 "

<<"\nHere the base number is 100 and the deficiency is 100-98=2 also the excess is 124-100=24 "

<<"\nTherefore the first part becomes 124-2=122 or 98+24=122 (whichever you like)"

<<"\nand the second part becomes 24 x minus 2=(48). So the answer is 124(48) " <<"\n12200-48, now applying ALL FROM 9 AND THE LAST FROM 10 sutra, 122 becomes 121 "

<<"\nand 48 gives 52 therefore the answer is 12152. " <<"\n"; } else cout<<"\nInvalid Choice"; j=0; cout<<"\nPress 1 to continue "; cin>>j; if(j==1) { clrscr();

cout<<"\nNUMBERS NEAR A MULTIPLE OF BASE NUMBER ";

cout<<"\nSuppose the numbers to be multiplied are not near a base number but to its multiple ";

cout<<"\nHere we use a sub-Sutra called PROPORTIONATELY "; cout<<"\nFor example 231 x 203 =43239 ";

cout<<"\nHere excess is 213-200=13 and 203-200=3.";

cout<<"\nWe observe that the numbers are close to 200, a multiple of base number 100";

cout<<"\nThe usual procedure gives us 216 / 39 (because 213+3=216 and 13 x 3=39)";

(53)

cout<<"\nNow since our base is 200 which is 100 x 2, we multiply only the left-hand part ";

cout<<"\nof the answer by 2 to get 43239."; cout<<"\nSimilarily 29 x 28= 3 x 27 / 2= 812"; cout<<"\nDeficiency is 30-29=1 and 30-28=2";

cout<<"\nso 29-2=27 or 28-1=27 and 3 x 27 =81 and 2 x 1=2, therefore the answer becomes 812 ";

cout<<"\n"; cout<<"\n";

cout<<" Hope this chapter is clear to you. If not please review again "; Ofile<<"\nNUMBERS NEAR A MULTIPLE OF BASE NUMBER "

<<"\nSuppose the numbers to be multiplied are not near a base number but to its multiple "

<<"\nHere we use a sub-Sutra called PROPORTIONATELY " <<"\nFor example 231 x 203 =43239 "

<<"\nHere excess is 213-200=13 and 203-200=3."

<<"\nWe observe that the numbers are close to 200, a multiple of base number 100" <<"\nThe usual procedure gives us 216 / 39 (because 213+3=216 and 13 x 3=39)" <<"\nNow since our base is 200 which is 100 x 2, we multiply only the left-hand part "

<<"\nof the answer by 2 to get 43239." <<"\nSimilarily 29 x 28= 3 x 27 / 2= 812" <<"\nDeficiency is 30-29=1 and 30-28=2"

<<"\nso 29-2=27 or 28-1=27 and 3 x 27 =81 and 2 x 1=2, therefore the answer becomes 812 "

<<"\n" <<"\n"

(54)

cout<<"\nA text file of the chapter has been generated in D drive. You can take a print out "; } else cout<<"\nInvalid Choice"; j=0; Ofile.close(); } void teacher::vert_func() { ofstream Ofile("d:\\vertcros.txt",ios::out); clrscr();

cout<<"\nThe third step is VERTICALLY AND CROSSWISE ";

cout<<"\nThe Vedic Sutra VERTICALLY AND CROSSWISE enables us to multiply any two numbers together ";

cout<<"\nin one line (from left to right or right to left),no matter how big the numbers are ";

cout<<"\nFor example 21 x 23=483";

cout<<"\nWe put the numbers and multiply:";

cout<<"\nA. vertically on the right, B. then crosswise and add, C. then vertically on the left ";

cout<<"\nmultiply vertically in the right-hand coloumn 1 x 3 =3, so 3 is the last figure of the answer ";

cout<<"\nmultiply crosswise then add, 2 x 3=6, 1 x 2=2 and 6 + 2=8"; cout<<"\nSo 8 is the middle figure of the answer ";

(55)

cout<<"\nmultiply vertically in the left-hand coloumn, 2 x 2=4, so 4 is the last figure of the answer ";

cout<<"\nSo the answer becomes 483.";

Ofile<<"\nThe third step is VERTICALLY AND CROSSWISE "

<<"\nThe Vedic Sutra VERTICALLY AND CROSSWISE enables us to multiply any two numbers together "

<<"\nin one line (from left to right or right to left),no matter how big the numbers are " <<"\nFor example 21 x 23=483"

<<"\nWe put the numbers and multiply:"

<<"\nA. vertically on the right, B. then crosswise and add, C. then vertically on the left "

<<"\nmultiply vertically in the right-hand coloumn 1 x 3 =3, so 3 is the last figure of the answer "

<<"\nmultiply crosswise then add, 2 x 3=6, 1 x 2=2 and 6 + 2=8" <<"\nSo 8 is the middle figure of the answer "

<<"\nmultiply vertically in the left-hand coloumn, 2 x 2=4, so 4 is the last figure of the answer "

<<"\nSo the answer becomes 483."; j=0; cout<<"\nPress 1 to continue "; cin>>j; if(j==1) { clrscr();

cout<<"\nThe previous example has no carry figure so lets consider 23 x 41=943 "; cout<<"\nThe three steps give us : 3 x 1=3, 2 x 1 + 3 x 4=14, so we carry 1 to the left coloumn ";

cout<<"\n2 x 4=8 and 8 + the carried 1 gives us 9."; cout<<"\nSo 23 x 41=943";

(56)

cout<<"\nHope this chapter is clear to you. If not please review again ";

Ofile<<"\nThe previous example has no carry figure so lets consider 23 x 41=943 " <<"\nThe three steps give us : 3 x 1=3, 2 x 1 + 3 x 4=14, so we carry 1 to the left coloumn "

<<"\n2 x 4=8 and 8 + the carried 1 gives us 9." <<"\nSo 23 x 41=943"

<<"\nHope this chapter is clear to you. If not please review again ";

cout<<"\nA text file of the chapter has been generated in D drive. You can take a print out "; } else cout<<"\nInvalid Choice"; j=0; Ofile.close(); } void teacher::might() {

cout<<"\nEnter two numbers near base number 100 "; cout<<"\nFor example 98 and 97 or 103 and 92"; enter1();

if(n1>90 && n1<110) {

if(n2>90 && n2<110) {

cout<<"\nBase number here is 100"; if(n1>100)

(57)

cout<<"\nThe excess in the first case is "<<n1-100; x1=n1-100;

} else {

cout<<"\nThe deficiency in the first case is "<<100-n1; x1=n1-100;

cout<<"\nWhich will be written as ("<<100-n1<<")"; }

if(n2>100) {

cout<<"\nThe excess in the first case is "<<n2-100; x2=n2-100;

} else {

cout<<"\nThe deficiency in the first case is "<<100-n2; x2=n2-100;

cout<<"\nWhich will be written as ("<<100-n2<<")"; }

mu(); } else

cout<<"\nThe entered numbers are not near the same base number "; }

}

(58)

{ c=0; cout<<"\nPress 1 to continue "; cin>>c; if(c==1) { clrscr();

cout<<"\nWe have to find "<<n1<<" x "<<n2;

cout<<"\nAs usual we will add the deficiency/excess of first number to the second one ";

cout<<"\nOr add deficiency/excess of second number to the first number whichever convineint ";

cout<<"\nThis gives us the first part of the answer";

cout<<"\nTherefore the first part is "<<n1<<" + "<<x2<<" = "<<n1+x2; cout<<"\nOr the first part is "<<n2<<" + "<<x1<<" = "<<n2+x1;

cout<<"\nTo find the second part we will as usual multiply the excess/deficiency of the 2 numbers ";

cout<<"\nThe following points are to be kept in mind "; cout<<"\n1.) excess X excess is positive ";

cout<<"\n2.) excess X deficiency is negative "; cout<<"\n3.) deficiency X deficiency is positive "; cout<<"\nPress 1 to continue "; c=0; cin>>c; if(c==1) { clrscr();

(59)

cout<<"\nThe second part must have one less digit than the first part";

cout<<"\nIf it is not so, add as many zeros in front of it to make the number of digits 1";

cout<<"\nlesser than the main part ";

cout<<"\nAlso as you have learnt in the tutorial, (n) would be replaced by a zero everywhere ";

cout<<"\nin the unconverted answer and then 10*n or n would be subtracted from the resulting number";

cout<<"\ndepending upon the place where (n) is substituted, 10*n for tens place and n for ones place";

cout<<"\nPress 1 to continue "; c=0; cin>>c; if(c==1) { clrscr();

cout<<"\nSo the first part is "<<n1+x2<<" as calculated before"; cout<<"\nThe second part is ";

if(x1>=0 && x2<=0) cout<<x1*x2;

else if(x1<0 && x2>0)

cout<<"("<<-(x1*x2)<<")"; else if(x1>0 && x2<0)

cout<<"("<<-(x1*x2)<<")"; else if(x1<0 && x2<0)

cout<<x1*x2;

(60)

if(x1*x2>=0 && x1*x2<=9) {

cout<<"0"<<x1*x2;

cout<<"\nObserve that a zero has been added for making the no. of digits "; cout<<"\n1 less than the first part ";

}

else if(x1*x2>9) cout<<x1*x2;

else if(x1*x2<0 && x1*x2>=-9) {

cout<<"0("<<-(x1*x2)<<")";

cout<<"\nObserve that a zero has been added for making the no. of digits "; cout<<"\n1 less than the first part ";

}

else if(x1*x2<-9)

cout<<"("<<-(x1*x2)<<")";

cout<<"\nNow the converted answer becomes "; cout<<100*(n1+x2)+x1*x2; } else cout<<"\nWrong choice "; } else cout<<"\nWrong choice "; }

(61)

} //main body void main() { clrscr(); int q;

cout<<"Veda Mathematics teacher (with illustration)--Ashish Chaudhary XII A "; cout<<"\nEnter your name ";

io i; i.wel();

cout<<"\n"<<i.name<<", this program helps you learn the basics of the "<<"\n ancient art of Veda Mathematics ";

cout<<"\nPress 1 to continue "; cin>>q;

if(q==1) {

clrscr();

cout<<"\nPress 1 for piecewise automated illustartion ";

(62)

cout<<"\nPress 3 for substraction of two numbers (upto 3 digits) ";

cout<<"\nPress 4 for multiplication of two numbers near the base number 100 "; }

else

cout<<"\n"<<i.name<<",thank you for using the program, press any key then enter to exit "; teacher t; t.choice(); getch(); }

References:

1 Vedic Mathematics by Bhararti Krsna Tirthaji, Delhi: Motilal Banarsidass, 1965.

(63)

ISBN 81-208-0164-4

2 Discover Vedic Mathematics by Kenneth Williams, Inspiration Books, 1984. ISBN 1869932013

3 Vertically and Crosswise, by Nicholas A. P., K. Williams, J. Pickles. London: Inspiration Books, 1984.

References

Outline

Related documents

The nowadays observational data of the magnetized neutron star (Fig. 1, for the table of data with corresponding references, see [3]) could not be explained by 1D cooling

Education standards have been shown to impact on the levels of evidence-based practice (EBP) in medicine and medical students ’ clinical reasoning [10].. The use of EBP has been

An overview of the routing goals is shown in Figure 35, which demonstrates the routing to each dependent core from the three CPUs. Figure 36 shows all the routing paths for all

This, however, is an appearance only; the first metaphase shows ten chromosomes and is followed by a normal cell division and formation of two equal second

An untrusted aggregator in mobile sensing can periodically obtain desired statistics over the data contributed by multiple mobile users, without compromising

However, Ulnaless does not resemble the loss-of-func- tion phenotype in any of the Hoxa or Hoxd genes in the following respects: the intermediate elements of the limb