-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;
Showing posts with label computer. Show all posts
Showing posts with label computer. Show all posts

Monday, 25 April 2016

File Access Methods in C++

I have discussed the concept of "files" in my previous blog.Today I am discussing the different file access method.

File access Method

The way in which a file can be accessed is called file access method.It depends on the manner in which data is stored in the files.Different file access methods are given below:

Sequential Access Method:

                                                                   It is used to access data in the same manner in which it is stored in a file.This method reads and writes data in a sequence.In order to access the last record,it has to to read all the records before the last one.

The record is not fixed in this access method.It means that each record occupies different amount of memory.

One of its advantages is that memory is not wasted.One of its disadvantages is that it takes very long time to search a record.For example,if the user wants to search the 4th record,it has to read the first 3 records to access the 4th record.

Random Access Method:

                                          It is used to access the data directly without accessing the preceding data.This method does not read or write data in a sequence.It is faster than sequential access method.

It stores data in fixed length records.This is the main disadvantage of this access method.It wastes memory space.Suppose a record of 10 bytes is used to store a complete sentence in a file.If a sentence consists of a single letter like 'H', it will occupy 10 bytes to store this letter.

However,this method speeds up access time because the position of each record can be determined easily as each record takes fixed length.Database management systems store files in a random access format.

Saturday, 23 January 2016

Concept of files in C++

Many students are confused with the concept of file handling in C++.So,today I will give you a little introduction about the concept of files in C++ which the essence of file handling.This would be a series of blogs which will help you to understand this concept easily.So,stay tuned !!1

Concept of files

As we see that a program inputs data from the user and stores it in variables.The data stored in the variables is temporary.When the program ends,all data stored in variables is also destroyed. The user has  to input data again from keyboard when the program is executed next time. the data has to be entered each time the program is executed that wastes time. The user may also type wrong data at different times.

Definition of files

A file is a collection of related records.It stores data about an entity(if you are unfamiliar with the concept of entity, remember that an entity is an object about which data is to be gathered.e.g., student is an entity). A data file can be used to provide input to a program.In can also be used to store the output of a program permanently.


Advantages of files

Now we will discuss the advantages of files in C++.

  • Files can store large amount of data permanently.
  • Files can be updated easily.
  • One file can be used by many programs for same input.
  • Files save time and effort to input data via keyboard.

Types of files

C++ provides two types of files.This categorization is based on how data is stored in files. Following are the types of files in C++.

Text files

A type of file that stores data as readable and printable characters in called text file.A source program of C++ is an example of text file.


Binary files

A type of file that stores data as non-readable binary code is called binary file.An object file of a C++ program is an example of binary file.


Reference

This reference of this article is taken from the book,Object Oriented Programming using C++(IT series).

Thursday, 3 September 2015

Concept of pointers in C++

Pointers are an extremely powerful programming tool. They can make some things much easier, help improve your program's efficiency, and even allow you to handle unlimited amounts of data. For example, using pointers is one way to have a function modify a variable passed to it. It is also possible to use pointers to dynamically allocate memory, which means that you can write programs that can handle nearly unlimited amounts of data on the fly--you don't need to know, when you write the program, how much memory you need.      

Concept of pointers

Pointers are aptly named: they "point" to locations in memory. Think of a row of safety deposit boxes of various sizes at a local bank. Each safety deposit box will have a number associated with it so that the teller can quickly look it up. These numbers are like the memory addresses of variables. A pointer in the world of safety deposit boxes would simply be anything that stored the number of another safety deposit box. Perhaps you have a rich uncle who stored valuables in his safety deposit box, but decided to put the real location in another, smaller, safety deposit box that only stored a card with the number of the large box with the real jewelry. The safety deposit box with the card would be storing the location of another box; it would be equivalent to a pointer. In the computer, pointers are just variables that store memory addresses, usually the addresses of other variables. 

Declaration of pointers

The general form of a pointer variable declaration is:
type *var-name;
Here, type is the pointer's base type; it must be a valid C++ type and var-name is the name of the pointer variable. The asterisk you used to declare a pointer is the same asterisk that you use for multiplication. 


Reference

The reference of this blog is taken from



       

Thursday, 13 August 2015

C++ The Complete Reference

Introduction

Helping book of C++

C++ The Complete Reference

Master programmer and best-selling author Herb Schildt has updated and expanded his classic reference to C++. Using expertly crafted explanations, insider tips, and hundreds of examples, Schildt explains and demonstrates every aspect of C++. Inside you'll find details on the entire C++ language, including its keywords, operators, preprocessor directives, and libraries. There is even a synopsis of the extended keywords used for .NET programming. Of course, everything is presented in the clear, crisp, uncompromising style that has made Herb Schildt the choice of millions. Whether you're a beginning programmer or a seasoned pro, the answers to all your C++ questions can be found in this lasting resource.
Detailed coverage includes:
  • Data types and operators
  • Control statements
  • Functions
  • Classes and objects
  • Constructors and destructors
  • Function and operator overloading
  • Inheritance
  • Virtual functions
  • Namespaces
  • Templates
  • Exception handling
  • The I/O library
  • The Standard Template Library (STL)
  • Containers, algorithms, and iterators
  • Principles of object-oriented programming (OOP)
  • Runtime type ID (RTTI)
  • The preprocessor
  • Much, much more

Author:

              Herbert Schildt

Date of publishing:

                                 November 19, 2002

Publisher:

                   McGraw-Hill Education

Language:

                   English

Genre:

              Programming

ISBN:

             
  •                   ISBN-10: 0072226803
  •                   ISBN-13: 978-0072226805

Rating:

             4.3/5.0 stars

Votes:

                  37

Reviewer:

                  A.Eassa

Review date:

                        April 18,2008

Reviewer rating:

                                         5/5 stars


Download link:

                                     Click here



Wednesday, 12 August 2015

Two-dimensional arrays in C++

Definition

In C++ Two Dimensional array in C++ is an array that consists of more than one rows and more than one column. In 2-D array each element is refer by two indexes. Elements stored in these Arrays in the form of matrices. The first index shows a row of the matrix and the second index shows the column of the matrix.

Syntax

data type name of array[no. of rows][no. of columns] 

For example,

int item[4][5];

Accessing each location


In order to store values in a C++ two dimensional arrays the programmer have to specified the number of row and the number of column of a matrix. To access each individual location of a matrix to store the values the user have to provide exact number of row and number of column.

Example:

int matrix[2][2];

matrix[0][0]=20;

matrix[0][1]=25;

matrix[1][0]=30;

matrix[1][1]=35;

Entering data

Nested loop is used to enter data in 2-D arrays. It depends upon the programmer which loop he wants to use it could be While loop or it could be a For loop. The outer loop acts as the number of rows of a matrix and the inner loop acts as the number of columns of a matrix.

Example:















#include<iostream.h>
#include<conio.h>
main()
{
int matrix [5] [5];
for (int m1=0 ; m1<5 ; m1++)
{
for (int m2=0 ; m2<5 ; m2++)
{
Matrix [m1] [m2] = 5 ;
}
}
getch();
}

                 Reference

The reference of this article has been taken from

Sunday, 9 August 2015

Swapping two numbers

"Swapping two number" is one of the most popular and easiest program of C++. If you want to make a good logic in C++,then you should practice this code.

Today I am here with the source code of this program.Hope you will like my effort.

Source code

sSwapping in C++

Output

Output of swapping

Logic

Below is the logic of this program.

I have taken 3 variables for this program,"a,b and tem(or temporary).

According to logic,

Suppose the value of a is 10 and the value of b is 20.

According to the given condition,

tem=a;
tem=10;
a=b
10=b or b=10;
b=tem
20=tem
b=10.

So,after swapping,the value of "a" becomes 20 and the value of "b" becomes 10. 

The ANCI C programming language

INTRODUCTION

C++ book
The ANCI C programming language
The authors present the complete guide to ANSI standard C language programming. Written by the developers of C, this new version helps readers keep up with the finalized ANSI standard for C while showing how to take advantage of C's rich set of operators, economy of expression, improved control flow, and data structures. The 2/E has been completely rewritten with additional examples and problem sets to clarify the implementation of difficult language constructs. For years, C programmers have let K&R guide them to building well-structured and efficient programs. Now this same help is available to those working with ANSI compilers. Includes detailed coverage of the C language plus the official C language reference manual for at-a-glance help with syntax notation, declarations, ANSI changes, scope rules, and the list goes on and on.

 Authors:

                            Brian W.Kernighan and Dennis.M.Ritchie.

Date of publishing:

                                                        April 1,1988.

Publisher:

                              Prentice Hall.

Language:

                             English

genre:            

                       programming.

ISBN:
               ISBN-10: 0131103628
  •                ISBN-13: 978-0131103627

Rating:

                     4.5/5.0 stars

Votes: 

                       514 

Reviewer:

                          Mark Cristie 


Review date:

                                 March 13,2000.

Reviewer rating:

                                            5.0/5.0 stars.

Download link:

                                           Click here