induction motor

concepts of oops

Objects:

Object is the basic unit of object-oriented programming. Objects are identified by its unique name. An object represents a particular instance of a class. There can be more than one instance of an object. Each instance of an object can hold its own relevant data.



An Object is a collection of data members and associated member functions also known as methods.

Classes:

Classes are data types based on which objects are created. Objects with similar properties and methods are grouped together to form a Class. Thus a Class represent a set of individual objects. Characteristics of an object are represented in a class as Properties. The actions that can be performed by objects becomes functions of the class and is referred to as Methods.

For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR represents individual Objects. In this context each Car Object will have its own, Model, Year of Manufacture, Colour, Top Speed, Engine Power etc., which form Properties of the Car class and the associated actions i.e., object functions like Start, Move, Stop form the Methods of Car Class.

No memory is allocated when a class is created. Memory is allocated only when an object is created, i.e., when an instance of a class is created.

Inheritance:

Inheritance is the process of forming a new class from an existing class or base class. The base class is also known as parent class or super class, The new class that is formed is called derived class. Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size of the program, which is an important concept in object-oriented programming.

Data Abstraction:

Data Abstraction increases the power of programming language by creating user defined data types. Data Abstraction also represents the needed information in the program without presenting the details.

Data Encapsulation:

Data Encapsulation combines data and functions into a single unit called Class. When using Data Encapsulation, data is not accessed directly; it is only accessible through the functions present inside the class. Data Encapsulation enables the important concept of data hiding possible.

Polymorphism:

Polymorphism allows routines to use variables of different types at different times. An operator or function can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning operator performing in different ways.

Overloading:

Overloading is one type of Polymorphism. It allows an object to have different meanings, depending on its context. When an exiting operator or function begins to operate on new data type, or class, it is understood to be overloaded.

Reusability:

This term refers to the ability for multiple programmers to use the same written and debugged existing class of data. This is a time saving device and adds code efficiency to the language. Additionally, the programmer can incorporate new features to the existing class, further developing the application and allowing users to achieve increased performance. This time saving feature optimizes code, helps in gaining secured applications and facilitates easier maintenance on the application.

The implementation of each of the above object-oriented programming features for C++ will be highlighted in later sections. 

oops lab / * Functions with default arguments */

/ * Functions with default arguments */

#include<iostream.h>
#include<conio.h>
int pnr(float principal=5000.00,float inrate=0.12,int period=5);
void main()
{
          clrscr();
          pnr();
          cout<<"\n\n";
          pnr(3000.00);
          cout<<"\n\n";
          pnr(3000.00,0.15);
          cout<<"\n\n";
          pnr(3000.00,0.15,3);
}

int pnr(float principal,float inrate,int period)
{
           int year,r;
 float sum,p;
           sum=principal;
 year=1;
 while(year<=period)
          {
                    sum=sum * (1 + inrate);
                    year=year+1;
 }
 cout<<endl<<"principal\t"<<principal;
 cout<<endl<<"period\t\t"<<period;
           cout<<endl<<"inrate\t\t"<<inrate;
 cout<<endl<<"sum\t\t"<<sum;
 getch();
          return(0);
 }




Output :

principal     5000
period         5
inrate          0.12
sum             8811.708984


principal     3000
period         5
inrate          0.12
sum             5287.024414


principal     3000
period         5
inrate          0.15
sum             6034.071289


principal     3000
period         3
inrate          0.15
sum             4562.625



/ * Implementation of swapping  using call by value */

#include<iostream.h>
#include<conio.h>
void swap(int x,int y)
{
          int t;
          t=x;
          x=y;
          y=t;
          cout<<"\nValues after swapping:"<<"\na="<<x<<"\nb="<<y;
}

void main()
{
          int a,b;
          clrscr();
          cout<<"Enter the Values of a and b:";
          cout<<"\na=";
          cin>>a;
          cout<<"\nb=";
          cin>>b;
          swap(a,b);
          getch();
}




Output :

Enter the Values of a and b:
a=43
b=25

Values after swapping:
a=25
b=43
/ * Implementation of swapping  using call by address */

#include<iostream.h>
#include<conio.h>
void swap(int *x,int *y)
{
          int t;
          t=*x;
          *x=*y;
          *y=t;
          cout<<"\nValues after swapping:"<<"\na="<<*x<<"\nb="<<*y;
}

void main()
{
          int a,b;
          clrscr();
          cout<<"Enter the Values of a and b:";
          cout<<"\na=";
          cin>>a;
          cout<<"\nb=";
          cin>>b;
          swap(&a,&b);
          getch();
}





Output :

Enter the Values of a and b:
a=43
b=25

Values after swapping:
a=25
b=43
/ * Implementation of swapping  using call by reference */

#include<iostream.h>
#include<conio.h>
void swap(int &x,int &y)
{
          int t;
          t=x;
          x=y;
          y=t;
          cout<<"\nValues after swapping:"<<"\na="<<x<<"\nb="<<y;
}

void main()
{
          int a,b;
          clrscr();
          cout<<"Enter the Values of a and b:";
          cout<<"\na=";
          cin>>a;
          cout<<"\nb=";
          cin>>b;
          swap(a,b);
          getch();
}

Output :



Enter the Values of a and b:
a=43
b=25

Values after swapping:
a=25
b=43

oops lab programe Implementation of class with primitive data members

/ * Implementation of class with primitive data members */

#include<iostream.h>
#include<conio.h>
class bank
{
          char name[25],acctype[10];
          int accno,tot;
          float balance,withdraw;
          public:
void data()
{

          cout<<"\nEnter the Name of the customer:";
          cin>>name;
          cout<<"\nEnter the acc.type of the customer:";
          cin>>acctype;
          cout<<"\nEnter the acc.no of the customer:";
          cin>>accno;
}
void bal()
{

          cout<<"\nEnter the total amount in the acc:";
          cin>>tot;
          cout<<"\nEnter the amount to be withdraw:";
          cin>>withdraw;
          balance=tot-withdraw;
}
void display()
{
          cout<<"\nDetails of the Customer\n";
          cout<<"\n\tName of the customer:\t"<<name;
          cout<<"\n\tAcc.Type:\t\t"<<acctype;
          cout<<"\n\tAcc.No:\t\t\t"<<accno;
          cout<<"\n\tTotal amount:\t"<<tot;
          cout<<"\n\tWithdraw amount:\t"<<withdraw;
          cout<<"\n\tBalance amount:\t\t"<<balance;
}
};
void main()
{
          clrscr();
          bank iob;
          iob.data();
          iob.bal();
          iob.display();
          getch();
}


Output:

Enter the Name of the customer: sivaraja

Enter the acc.type of the customer: SB

Enter the acc.no of the customer: 23743

Enter the total amount in the acc: 5600

Enter the amount to be withdraw: 3500.50

Details of the Customer

        Name of the customer:   sivaraja
        Acc.Type:                        SB
        Acc.No:                           23743
        Total amount:                           5600
        Withdraw amount:          3500.5
        Balance amount:              2099.5

A Beginner’s guide to Electrical Engineering

1. What is Electrical Engineering? Electrical engineering is comparatively one of the newer branches of engineering, and dates b...