Saturday 24 September 2011

Program for following sum of series

This program is used to find the sum of the exponential series:

1 + x/2! + x2/4! + x3/6! + x4/8! + ....... + xn/(2n)!



// The required function is :
#include 
#include 
double seqsum(double x, int n)
{
double sum=1, num=1, div=2, fact=1, term;
for(int i=2;i<=n;i++)
 {
  num=num*n;
  fact=fact*(div)*(div-1);
  term=(num/fact);
  div=div+2;
  sum=sum+term;
 }
 return sum;
}
void main()
{
 clrscr();
 int x, n;
 double sum = 0;
 cout << "Enter the value of x : ";
 cin >> x;
cout << "Enter the value of n : ";
 cin >> n;
sum = seqsum(x, n);
cout << "The value of the series : " << sum;
}



User defined datatypes

There are some derived data types which are user defined. Examples of these data types are : Class, structures, unions and enumerations. Thogh we will have a detailed discussion of these topics in the coming tutorials. But let us a short review of these topics.

  1. Class:
  2. A class is a group of similar or dissimilar elements that are referenced under the same name. The variables under these names may be different. For example, consider this:
    class student
                              {
                                   int roll_no;
                                   char name;
                                   float percentage;
                                   char subjects 
                              };
    
    
    In this example we see that this class student contains four dissimilar elements under the same name, i.e 'student'. All these four elements are of different types such as roll_no of int type, name of character type and so on.
  3. Structures :
  4. Structure is very similar to class. This is also a collection of similar or dissimilar elements which are referenced under the same name. Now there arises a question in your mind. What is the need to tell about structures when it is very similar to class. Yes you are right it is very similar to class. But there is a little difference between them. They differ by visibility modes. We will discuss about the visibility mode in details when we will study about classes and structures. An example for structure can be given as
    structure student
                              {
                                   int roll_no;
                                   char name;
                                   float percentage;
                                   char subjects 
                              };
    

Thursday 22 September 2011

Data types


In both the programmin languages, i.e C and C++ we use data types. Data types are the tools to identify the type of data and the operations to which it undergoes. In C and C++, there are two types of data types:
  1. Fundamental datatypes
  2. Derived datatypes
  • Fundamental datatypes:  The datatypes which are known as the root of all datatypes are called fundamental datatypes. There are basically five types of fundamental datatypes which can be listed below as:
    1. int data type : When ever we declare any identifier as int type, it becomes an integer variable. For example: If we declare int value then the identifier or variable vlaue will become an integer type data variables. What does this simply specify ? It specifies that the variable value can now store and reveal only integer values or simply it can operate only on integer values.
    2. char datatype: When ever we use char before any specifier, it becomes character type variable. This can be explained with the help of an example. Suppose: char words, now this variable word will become character type, i.e now it can store and reveal or can operate with all data of character type.
    3. float datatype: This datatype when used before any specifier, converts that specifier into a variable of floating type variables. What does this mean ? This means that now that variable can store and reveal or can operate with numerical values that contains digits after decimal.
    4. double datatype: This datatype works similar to float datatype. The only difference is that it can deal with numbers having more places after decimal with minimum chances of error.
    5. void datatype: Void datatype is simple datatype that is used to make any varialbe(mostly functions) which do not retun any values. Example: void main ()
  • Derived Data types : These data types which are derived or originated from default data tpye or fundamental data types. Such type of datatypes are called Derived datatypes. Example of Derived datatypes are : Arrays, Function, Pointer, Reference. We will be discussing about all these topics and programs in detail in the coming tutorials.


Monday 19 September 2011

Some important key terms and definitions

Before I start, I request to pay attention to my words. In the entire blog, my aim is to make your concepts very sharp in C and C++ programming. And at the very begenning let me tell you that i will pay more attention to programs(practical skills), rather than theoritical part. I will try to teach and make your concepts clear usng different programs and different places.

And I promise you will enjoy this programming in C and C++ !!!


Variablesvariables are the words that are used in C and C++ programmingsimply to store input and output information which can be retrieved later in the program. They are declared with the help of a data type. The declaration of a variable or set of variables should be followed by a semi colon.

Data types: Datatypes are the words that defines the characterstics of any variable. As you know variable can be of many types such as interger type, decimal type, or character type. Similarly different datatypes are used to declare different variables.

For eg :  int a,b,c;
               float number ;

Here 'a','b', and 'c' are variables of interger type and 'number' is a variable of floating (number with decimal places).

ConstantsConstants are the terms in any program whose value remain fixed in the entire program. The best example for the constant is 'pi' whose value can be fixed in the entire program, i.e 3.14. You must remember how to declare such constant. See below :

# define pi 3.14

This is declared along with the inclusion of headerfiles.





Friday 16 September 2011

Introduction to programming in C and C++




C is procedural programming language and C++ is an object oriented programming language. Most of the features of C and C++ are the same. C++ is just advanced version of C.

The C++ proghramming language was developed at AT & T bell laboratories in the early 1980's bu Bjarne Stroupstrup. He found 'C' lacking for simulations and decided to extend the language bu adding features from his favourite language, Simula 67. Bjarne called it as C with classes originaaly. The name C++ was coined  by Rick Mascitti where "++" is C increment operator. The maturation of C__ language was attested by two events:

  • The formation of an ANSI (American national standard institute) C++ committee and
  • The publication of The Annotated C++ Reference Manual by Ellis and Stroupstrup.
The latest C++ standards document was issued by ANSI/ ISO in the year 2003.

NOTE: If you learn C, it is very easy to understand C++, and if you learn C++, it's very easy to undestand C. Both are equivalent. You just need to command over any one language.


This is introduction to C and C++ programming.  In the further post you will learn programming in C and C++.