Open Means Open Means

CHARACTERISTICS OF C + +

No comments on “CHARACTERISTICS OF C + +”

                        C+ + is an object oriented programming language with a huge library of functions. It is very popular among programmers due to its multiple features.

1.C ++ is ideally suited for development of reusable software. This helps in cost reduction of software development

2.C + + is highly flexible language with versatility. It can be used for developing system software Viz operating systems compilers, editors and data bases.

3.There is no need of rewritten software if a computer is upgraded. In other words. We can say that C ++ is a machine independent language.

 

CHARACTERS USED IN C + + :-

The set of characters used in C + + consists of alphabets, digits and special characters.

The following table represents the characters used in this language:

Letters           A B C D ………………….. XYZ

                       a b c d ……………………. x y z

Numeric Digits       0 1 2 3 4 5 6 7 8 9

Special Characters:

 1. Arithmetic Operators: — , + , * , / , %

2.Logical Operators :    & ,   !

3.Brackets :  ( ), { }, [ ]

4.Relational Operators:   = #

5.Other Symbols   :, ; , _ ( Underscore)

General OOP concepts

No comments on “General OOP concepts”

General OOP concepts

With the rapidly changing world and the highly competitive and versatile nature of industry, the operations are becoming more and more complex. In the view of the increasing complexity of software systems, the software industry and software engineer continuously new approach for the software design and development. The increased complexity had become the chief problem with compute programs in traditional languages. Large programs, because of this complexity are more prone to errors, the software error can be expensive and can be life threatening. The most adopted and popular programming approach, structured programming approach, failed to show the desired results in terms of bug-free, easy to maintain, and reusable programs, the latest programming approach, Object-Oriented-Programming (OOP), offers a new and powerful way to cope with this complexity. Its goal is clearer, more reliable, more easily maintained programs. This article introduces general OOP concepts that the traditional languages like C, Pascal, COBAL and BASIC lack in the new generation languages (Object-Oriented Languages) support.

 

Evolution of software

A program serves the purpose of commanding the computer. The efficiency and usefulness of a program depends not only on proper use of commands but also on programming languages it is written in. the major types of programming languages offer different features of programming.

Low level language (i.e. , machine language and assembly language) are machine oriented and require extensive knowledge of computer circuitry. Machine language, in which instructions are written in binary code (using 0 and 1), is the only language the computer can execute directly. Assembly language, in which instructions are written using symbolic names for machine operations (e.g., READ, ADD, STORE etc.) and operands, makes programming less tedious than machine language programming. However, assembly program is then converted in to machine language using assembler software.

High level language (HLLs), on the other hand, offer English like keywords, constructs for sequence, election (decision) and iteration (looping) and use of variables and constants. Thus it is very easy to program with such languages compared to low level languages. The programs written in HLLs are converted in to machine languages compared to low level languages. The programs written in HLLS are converted in to machine languages using compiler or interpreter as a computer can work with machine language only.

A programming language should serve two related purposes:

(i) It should provide a vehicle for the programmer to specify actions to be executed and

(ii)It should provide a set of concepts for the programmer to use when thinking about what can be done. The first aspect ideally require a language that is “close to the problem to be solved” , so that all important aspects of a machine are handled simply and efficiently in a way that is reasonably obvious to the programmer. The second aspect ideally requires a language that is “close to the problem to be solved” so that the concepts of a solution can be expressed directly and concisely.

The low level languages serve only the first aspect i.e., they are close to the machine and high level language serve the second aspect i.e., they are close to the programmer. However, the languages ‘C’ and ‘C++’ serve both the aspects; hence can be called as ‘middle level languages’.

 

Programming paradigms

By programming paradigm one means a way of thinking. Paradigm means organizing principle of a program. It is an approach to programming.

Since the invention of the computer, many programming approaches have been tried such as procedural programming, modular programming, structural programming etc. The primary motivation in each case has been the concern to handle the increasing complexity of programs that are reliable and maintainable.

Let us discuss these different programming paradigms and key languages mechanisms necessary for supporting them.

Procedural Programming

A program in a procedural language is a list of instructions where each statement tells the computer to do something. The focus is one the processing, the algorithm needed to perform the desired computation. This paradigm is :

Decide which procedure you want: use the best algorithms you can find.

Languages support the paradigm by providing facilities for passing arguments to functions (sub-programs) and returning values from functions (sub-programs).

In procedural paradigm, the emphasis is on doing things. What happens to the data? Data is after all, the reason for a program’s existence. The important part of an inventory program isn’t function that displays or checks data; it is the inventory data itself. Yet data is given second-class status while programming.

Modular programming

With the increase in program size, a single list of instructions becomes unwieldy. Thus a large program is broken down in to smaller units i.e., functions (sub-program). The idea of breaking program in to functions can further be extended by grouping a number of functions together in to a large entity called module, but the principle is similar: grouping of components that carry out specific tasks.

A set of related procedures with the data they manipulates is called a module.

The programming paradigm, also known as ‘data-hiding principle’ states:

Decide which modules you want: partition the program so that data is hidden in modules.

Where there is no grouping of procedures with related data, the procedural programming style suffices. The techniques for designing ‘good procedures’ still apply on each member procedure of modules.

In modular programming, since many modules (or functions) access the same data, the way the data is stored becomes critical. The arrangement of the data can’t be changed without modifying all the functions that access it.

Another problem associated with procedural and modular programming is that their chief components- functions etc. do not model the real world very well. For instance, a procedural program for library maintenance aims at the operations Issue, Return etc. whereas the real world entities are Books. But ‘Books’ are given second class status in the program. We will understand this problem more clearly in the next paradigm-the object oriented paradigm.

The object oriented programming

To understand this most recent concept among programming paradigm, let us take an example. We have to prepare lot of dishes that involve baking; for instance cake, biscuits, pie, dhokla, pastries, buns etc. we have to write programs for it. Using procedural programming paradigm, we’ll have to write separate programs for every recipe and each program will be containing instructions for operating oven. Ovens are used to make a lot of different dishes. We don’t want to create a new oven every time we encounter a new recipe. Having solved a problem once, it would be nice to be able to reuse the solution in future programs. But the procedural programming paradigm suffers from this drawback. Though functional software reuse is theoretically possible, but it hasn’t work very well in practice. The large amount of interaction between conventional functions and its surroundings make reusing them difficult.

However, if the same problem is solved using object-oriented approach, it’ll not only be less complex but also make software reuse feasible and possible. The object-oriented approach views a problem in terms of objects involved rather than procedure for doing it.

Object is an identifiable entity with some characteristics and behavior.

For instance we can say ‘Orange’ is an object. Its characteristics are: it is spherical shaped, its colour is orange etc. Its behavior is juicy and it tastes sweet-sour. While programming using OOP approach, the characteristics of an object are represented by its functions associated. Therefore, in OOP programming object are represents an entity that can store data and has its interface though functions.

The above mentioned problem of baking dishes, in OOP approach, will be viewed in terms of object involved (i.e., OVEN) and its interface (i.e., the functions representing its working). This not only results in simple program design but also reduces software cost.

To understand this concept more clearly, let us consider another example. Let us simulate traffic flow at a red light crossing.

As you know, procedural programming paradigm focuses on the procedures or the working action.

Using procedural programming paradigm, the above said problem will be viewed in terms of working happening in the traffic-flow i.e., moving, halting, turning etc. The OOP paradigm, however, aims at the objects and their interface. Thus in OOP approach, the traffic-flow will be viewed in terms of objects involved. The objects involved are: cars, trucks, buses, scooters, auto-rickshaws, taxis etc.

With this elaboration, the concept must be clear enough to proceed for the OOP paradigm definition. But before that let us understand another very important term class.

 

 

 

Constructors Vs. Destructors

No comments on “Constructors Vs. Destructors”

CONSTRUCTORS VS. DESTRUCTORS

 

Constructors and Destructors are a very important concept of C++ language. C++ is an OOP or Object Oriented Programming Language and it provides special member functions called Constructors used to automatically initialize objects of a class. In the complement of it, it also provides another member function called Destructor to destroy objects when their need is no longer required. It is necessary so as to keep memory free. Constructors, as the name implies, are automatically invoked and initialize object. Its name is same as that of class name, e.g.

Class A

{

int m,n;

public:

A( ) ;                                             <---- Constructor

}

 

If no Constructor is defined in a program then default Constructor is supplied by the compiler automatically. They are declared in the Public section i.e., access mode is public. They have no return type i.e., they cannot return values to program. They cannot be inherited by other classes. We can pass arguments to a constructor. O a class can contain more than one class.

As indicated by name, Destructors destroy the objects that have been created by constructor. It is also a member function of a class having same name of class preceded by a tilde sign. E.g.,

Class A

{

int a;

Public;

A( ) ;                                        <------Destructor

};

 

A destructor never takes any value and never returns a value. It destroys the value of the object in reverse order of their creation. It is invoked automatically by the compiler, whenever a block or function ends or a program exit. Destructors clear the memory area occupied by initialization of object making memory space available for future use. So it is a good practice to declare a Destructor.

 

 

 

 

 

passing strings to funcation in c pro.

No comments on “passing strings to funcation in c pro.”

the strings are treated as charactor arrays in c and therefore the rules for passing string to functions are very similar to those for passing arrays to funcations.

basic rules are:

1>> the string to be passed must beclared as a formal argument of the funcation when it is defined exampl

 

void display(char item_name[ ])

{

 ................................

 .................................

}

2>>the funcation prototype must show that the argument is a string. for the above funcation definition , the prototype can be written as

                               void display(char str[ ]);

3>>a call to the funcation must have a string array name without subscripts as its actual argument example:

                                   display(name);

where names is a properly declared string array in the calling funcation .

we must note here that , link arrays , strings in c cannot be passed by value to funcations.

Binary Tree programing.

No comments on “Binary Tree programing.”
A binary tree is a special case of tree, in which no node of a tree can have a degree of more than 2. Therefore, a binary tree is a set of zero or more nodes T such that: 1. there is a specially designated node called the root of the tree 2. the remaining nodes are partitioned into two disjointed sets, T1 and T2, each of which is a binary tree. T1 is called the ‘left subtree’ and T2 is called ‘right subtree’. Below there is a programming in C language on the concept of Binary tree. So we have initialize a recursive structure each have two link part struct bt *lc and struct bt *rc and a data part. Like this …….…….. The left and right child contains either the same structure link or its NULL. Every time we create a node we call getnode() function where use malloc to allocate the space of the structure. Then the program will ask user to enter a data. And then whose left or right child do the user want to be the latest node is been asked. Now for print the tree we have use the concept of B.F.S. where we use a array whose data type is the same as the data type of the tree. We put the root node at the front of the array. Then we took the node at the front of the array and add its children to the rear of the array and print those with respect to the parent node’s data. There is an advantage of using binary tree over normal tree. That is in case of Tree we don’t know the number of children to be define in the structure as Tree can have different number children in every node. So it is tuff to initialize the number of children in the structure. But a Binary tree can’t have more than 2 children. So we can just put two children link in the structure. One more thing I would like to add that we can also implement a tree using a array and not using Linked list. In that type of representation we can easily obtain the parent and child node. But the problem is some time there are too many unused space in array type representation of Binary tree. Prograing Code………… #include #include #include struct bt { struct bt *lc; int data; struct bt *rc; }; struct bt *getnode() /*allocate space for new node.*/ { struct bt *newnode; newnode = (struct bt *) malloc(sizeof(struct bt)); return(newnode); } struct bt *inorder(struct bt *tr, int z) /*searching a node with inorder traversal*/ { inorder(tr->lc,z); if(tr->data==z) { return tr; } inorder(tr->rc,z); } void data(struct bt*); void display(struct bt *); void main() { char ch; struct bt *t; t->data = 0; t-> rc = ''; t-> lc = ''; do /*do-while loop starts */ { printf("enter chicen 1. datan 2. printn 3. up.n 4. exit.n"); scanf("%c", & ch); printf("u choose %c", ch); switch(ch) /* switch case*/ { case '1':printf(" u choose to enter data."); data(t); break; case 2: display(t); break; case 3: break; case 4: break; } }while(ch!=4); } void data(struct bt *t1) { int x,y,c; struct bt *tre; struct bt *temp; printf("n enter the value under whose u want a child"); scanf("%d", & x); tre= inorder(t1,x); temp=getnode(); printf("enter data"); scanf("%d", & y); temp->data = y; /* putting data in new node*/ temp -> lc = ''; temp -> rc = ''; printf("u want this node as 1. left child or 2. right child?"); scanf("%d", & c); if(c==1) { temp->lc = tre->lc; tre -> lc = temp; } else { temp->rc = tre->rc; tre -> rc = temp; } } void display(struct bt *t3) { struct bt *ar[100]; /* initialize structure type array*/ int fr,re; ar[1]=t3; fr=1; re=1; while(frlc != '') { ar[++re]= ar[fr]->lc; } if(ar[fr]->rc != '') { ar[++re]= ar[fr]->rc; } printf("n node is=%d", ar[fr]->data); printf("l child is=%d", ar[fr]->lc->data); printf("r child is=%d", ar[fr]->rc->data); fr++; } }

More Articles …

  1. Graphs
  2. Graph Continues..
  3. scope resolution operator
  4. OBJECT ORIENTED PROGRAMMING
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Page 5 of 21

  • About Us
  • Faqs
  • Contact Us
  • Disclaimer
  • Terms & Conditions