Learning C++: 2011-08-07

Pages

Wednesday, August 10, 2011

What is "for loop" and "array" in C language ? (Not for my C++ readers)

Hi ! I am here putting simple C program to demonstrate Loops and array in C language. Code is only for my C programmer friends,not for my C++ reader please wait for my next post regarding C++. This post is just because it urgently required by my C programmer friends.

Problem Definition: Program to count the number of student who has  pass in a particular subject in a given class and count Passing percentage

void main()
   {
    /* Variable Declaration */
    int student[100]; 
    // Declare integer array assuming max students are 100
    int nCount=0,i=0,passCounter=0;
    float passPercentage=0;
    clrscr();

    printf("\nEnter Number of Students: "); // Printing Message
    scanf("%d",&nCount); // Get count of number of students

    //Save marks for each student
    printf("\nEnter marks of student in sequence\n");
    for(i=0;i<nCount;i++)
    {
        printf("\nEnter mark for student number %d :",i+1); 
        // i+1 because for loop starts from 0
        scanf("%d",&student[i]); 
  // Dont write i+1 here because it saves number from 0 in Array
    }

    // Calculating count of pass students, here criteria of Passing is 40

    for(i=0;i<nCount;i++)
    {
         //checking mark of each student starting
         if(student[i]>40)
         {
        passCounter++; // Incrementing counter of Passing student
         }

    }

    // Calculating Percentage of Passing student

    passPercentage=(passCounter/nCount)*100;

    //Displaying result

    printf("\nCount of Pass Students are %d",passCounter);

    printf("\nPercentage of Pass students are%f",passPercentage);

    getch();
   } 

Comment me for any query regarding program.

Monday, August 8, 2011

What is Object oriented programming (OOP) ? (Using c++)

Object Oriented Programming (OOP) is programming paradigm (METHOD or you can say STYLE). In C++, everything happens around Object, that's why it is called as object oriented programming,
Now what is Objects? To understand object you first need to know what is class?

CLASS IN C++ : Take an example of a CAR. Each car has wheels, roof, color and many more features. But every car is not similar to each other. (Here i am talking about type of cars), still we categories them into car section. Put break here and read it once.......

Now this category of car is Class in C++ language and types and variety of cars are its Object. Hence Class is general representation of objects.

Now in reality our streets don't serves services to cars only, there are BIKES, BICYCLES, TRUCK and many more. These also represent them selves to some class. 

This object oriented programming has many concepts which makes any programming language rich like our C++.
These concepts are 

1) Class (ADT-Abstract data type)
2) Object
3) Inheritance
4) Encapsulation
5) Polymorphism
6) Method overloading
7) Operator overloading
8) Method overriding 
9) Friend function
10) Exception handling

If i missed something here then i will tell you later. but for mean while read it once. And don't scare we will learn each concept very easily.
Keep your IDE (Editor) ready for next time.....

Sunday, August 7, 2011

What is C++ and Programming Language?

"Computer Program" sounds good in hearing... But I can bet you will feel its magic when you start doing programming your own. I will give you small background of Programming language world. Programming era started on early before when computer was in its stage of maturation. 
          But serious first Programming language was started between 1969 and 1973, i.e. "C Programming". It was best ever product of Bell's Factory. It was built by  Dennis Ritchie. C is still booming programming language in this modern world. Its one of the main ingredient of UNIX Operating systems, Linux OS and many more... Android OS also contains some part of C. Here I am not going to elaborate you C Programming language. Don't worry many more concepts of C++ is similar to C. Even if you have any question or doubt put it into comments or ask me.... 

          Moving forward to next lap of programming language, i.e. Object Oriented Programming language, headed by C++. Its true that modern computer language takes lesson from C++ for its build up. Many recent languages are build on concept of C++. and of course its also a product of Bell's Laboratory. build by Bjarne Stroustrup, on one year before when Deepika Padukone was born.. :) means 1983.
Here through this blog i will post concepts of C++, I will explain this in short and sweet way. I want my readers to implement logic and programes at least once.DON'T WORRY IF YOU DON'T KNOW C EVEN IF YOU CAN LEARN C++ VERY WELL. 
          For implementation i will suggest you to use "turbo c", you can say it as IDE(Integrated development Environment ) or Editing software. I will recommend you to use VISUAL STUDIO 2008 or 2010. You can download it from torrent. Now why VISUAL STUDIO because you can create professional level programes here and I am also using this. My all C++ Programes here, are tested in Visual Studio. Of course it will run on Turbo C also.. but even if you face any problem let me know. 
My C programes on this blog are tested in Turbo C. You can download my notes or many other ebooks from here. So stay update and visit here to get smart.
Enjoy Coding.... :)