Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pass by reference (C++ Programming) Write the function definition for the protot

ID: 655369 • Letter: P

Question

Pass by reference (C++ Programming)

Write the function definition for the prototype

void integer_value(int num, int &first, int &last, &length);

which given an input integer num

determines the following output values:

first is the leftmost digit

last is the rightmost digit

length is the number of digits in the integer

Example:    1234589

The value for first is 1

The value for last is 9

The length is 7

Example:   23514879

The value for first is 2

The value for last is 9

The length is 8

Explanation / Answer

#include<iostream.h>
#include<conio.h>

class a
{
public:
   void integer_value(int num, int &first, int &last, &length)
   {
       cout<<"Number is "<<num;
       cout<<"First Number is "<<first;
       cout<<"Last Number is "<<last;
       cout<<"Length of Number is "<<length+1;
   }
};

void main()
{
   int i=0,j,f,l,n;

a o;

   cout<<"Enter No";
   cin>>n;
   num=n;
   while (n>0)
   {
       j=n%10;
       if(i==0)
       {
           l=j;
       }
       n=n/10;
      
       i++;
      
   }
   f=j;

o.integer_value(num, f,l,i);
}