INLINE FUNCTION;

QUESTION- USE OF INLINE FUNCTION…..

ANSWER-

#include<iostream.h>
#include<conio.h>
using namespace std;
inline int sum(int, int, int); //adding inline cmd replaces the code by its calling argument it takes less time in execution
int main()
{
int add,a,b,c;
cout<<“\nENTER NO. 1:”;
cin>>a;
cout<<“\nENTER NO. 2:”;
cin>>b;
cout<<“\nENTER NO. 3:”;
cin>>c;
add=sum(a,b,c);
cout<<“\n\nSUM OF 3 NO. IS : “<<add;
cout<<“\n\n\tPROGRAMMING @ C#ODE STUDIO”;
getch();
}
int sum(int a,int b, int c)
{
return(a+b+c);
}

inline

TFUNCTION OVERLOADING;

QUESTION WHAT IS FUNCTION OVERLOADING IMPLEMENT A LOGIC TO PROVE YOUR WORDS;

ANSWER;

IN FUNCTION OVERLOADING WE CAN CREATE ONE OR MORE FUNCTION WITH SAME NAME BUT HAVING DIFFERENT RETURN TYPE OR ARGUMENT;

BELOW, IN EXAMPLE THERE IS 3 FUNC WITH NAME  AREA  BUT THEY ARE HAVING DIFFERENT ARGUMENTS;

EXAMPLE——

#include<iostream.h>
#include<conio.h>
using namespace std;
int area(int , int);
int area(float);
int area(int); //these are the various prototype having different arguments;
int main()
{
    int n,a,b,r;
    float c;
    cout<<“MAKE A CHOICE \n 1:RACT, 2:SQUARE, 3:SPHERE : “;
    cin>>n;
    switch(n)
    {
        case 1:
        {
            cout<<“\nENTER ARMS LENGTH :”;
            cin>>a;
            cout<<“\nENTER ARMS WIDTH :”;
            cin>>b;
            area(a,b);
            break;
        }
        case 2:
        {
            cout<<“\nENTER ARMS LENGTH :”;
            cin>>c;
            area(c);
            break;
        }
        case 3:
        {
            cout<<“\nENTER RADIUS :”;
            cin>>r;
            area(r);
            break;
        }
    }
    cout<<“\n\n\tPROGRAMMING @C#ODE STUDIO”;
    getch();
}
int area(int f, int g)
{
    int ar;
    ar=f*g;
    cout<<“\nAREA OF RACTANGLE IS “<<ar;
}
int area(float f)
{
    float ar;
    ar=f*f;
    cout<<“\nAREA OF SQUARE IS “<<ar;
}
int area(int r)
{
    float ar;
    ar=2*3.14*r;
    cout<<“\nAREA OF SPHERE IS “<<ar;
}

 

fn_over

USING A CLASS IN C++;

QUE- WAP TO MAKE A LIBRARY PROGRAM AND IMPLEMENT A CLASS AND USE IT VARIABLE AS PUBLIC;

ANSWER-

#include<iostream.h>
#include<conio.h>
using namespace std;
class library //Class containing variables and function;
{
      int reg;
      int book_no;
      char name[25];
      public:  //Making functions public;

             void issue()
             {
                  cout<<“\nenter name of book:”;
                  cin>>name;
                  cout<<“\nenter reg no.:”;
                  cin>>reg;
                  cout<<“\nenter book no.:”;
                  cin>>book_no;
                  cout<<“\nBOOK “<<name<<” ISSUED BY “<<reg<<” book no. “<<book_no;
             }
              void ret()
               {
                  cout<<“enter name of book:”;
                  cin>>name;
                  cout<<“\nenter reg no.:”;
                  cin>>reg;
                  cout<<“\nenter book no.:”;
                  cin>>book_no;
                  cout<<“\nBOOK “<<name<<” returned BY “<<reg<<” book no. “<<book_no;
              }
};
int main()
{
    int a,b;
    class library obj; //Creating a object to class ‘library’
    cout<<“\nTHIS PROGRAM IS A LIBRARY FUNCTION, 0:CONTINUE\t:”;
    cin>>b;
    while(b==0)
    {
               cout<<“\n1: WANT TO CHECK OUT BOOK,  2:WANT TO CHECK IN BOOK : “;
               cin>>a;
               if(a==1)
               {
                       obj.issue();
               }
               else
               {
                       obj.ret();
               }
               cout<<“\n 0 : CONTINUE PROGRAM or 1: EXIT THE PROGRAM :::= “;
               cin>>b;
     }
     cout<<“\n\nProgramming @ C#0DE Studio”;
     getch();
}

lib_b46

Factorial of a no.:

Que – Implement a c++ program to find the factorial of a no.

Ans:-

IOSTREAM-  contains some standard object

  • cout, an object of the ostream class, which displays data to the standard output device.
  • cerr, another object of the ostream class that writes unbuffered output to the standard error device.
  • clog, like cerr, but uses buffered output.
  • cin, an object of the istream class that reads data from the standard input device.

#include<iostream.h>
#include<conio.h>
int main()
{
    int a,counter;
    long int fact=1;
    cout<<“This program give factorial input no. – “; 
//use to give output on screen
    cin>>a;    //use to get input from user
        for(counter=1;counter<=a;counter++) //loop for counter increment
        {
            fact=fact*counter;
        }
        cout<<“\nFactorial of “<<a<<” is “<<fact;
    cout<<“\n\nPROGRAMMING @ CODE STUDIO”;
    getch();
    return 0;
}

fact