Showing posts with label PDS LAB. Show all posts
Showing posts with label PDS LAB. Show all posts

Tuesday, January 19, 2016

CS6301 Programming and Data Structure II

ABSTRACT CLASS
The purpose of an abstract class (often referred to as an ABC) is to provide an appropriate base class from which other classes can inherit. Abstract classes cannot be used to instantiate objects and serves only as an interface. Attempting to instantiate an object of an abstract class causes a compilation error.
Thus, if a subclass of an ABC needs to be instantiated, it has to implement each of the virtual functions, which means that it supports the interface declared by the ABC. Failure to override a pure virtual function in a derived class, then attempting to instantiate objects of that class, is a compilation error.
Classes that can be used to instantiate objects are called concrete classes.

EXCEPTION HANDLING
An exception is any unusual event, either erroneous or not, detectable by either hardware or software, that may require special processing.

Exception handling mechanism
To detect and report error
The error handling code performs the following task
1.  Find the problem (Hit the exception)
2. Inform that an error has occurred.(Throw the exception) 
3. Receive the error information.(Catch the exception)
4.  Take corrective actions(Handle the exception).

Keywords in Exception Handling
1.try 
2.throw 
3. catch
• TRY BLOCK -The keyword try is used to preface a block of statements(surrounded by braces) which may generate exceptions. 
->When an exception is detected, it is thrown using a throw statement in the try block.
• CATCH BLOCK - defined by the keyword catch ‘catches’ the exception ‘thrown’ by the throw statement in the try block, and handles it appropriately.

Monday, February 2, 2015

C Programs using Conditional and Control Statements

                        FIBBONACCI SERIES
EX.NO:2

AIM
            To write a C program to generate the Fibonacci series

ALGORITHM
Step-1: Start the program
Step-2: Enter the number
Step-3: Check the number whether the number is zero or not. If zero print Zero value. If  
             not zero go further.
Step-4: Set a loop up to the given number.
Step-5: fib=fib+a;
            a=b;
            b=c;
Step-6: Every increment in the loop prints the value of fib.
Step-7: After the execution of the loop stops the program

PROGRAM
#include<stdio.h>
main()
{
            int num,fib=0,a=0,b=1,i;
            printf(“Enter the number”);
            scanf(“%d”,&num);
            printf(“\n FIBBONACI SERIES\n”);
            if(num==0)
                        printf(“0”);
            else
            {
                        for(i=0;i<num;i++)
                        {
                                    fib=fib+a;
                                    a=b;
                                    b=fib;
                                    printf(“%d\t”,fib);
                        }}}