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

1 comment:

  1. Lucky Club Live Casino | LuckyClub
    Lucky Club offers luckyclub.live you the chance to play a variety of table games including Blackjack, Roulette and Blackjack. Sign up to our casino to claim your welcome bonuses!

    ReplyDelete

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...