Explain the following function what does it do bool confcha

Explain the following function - what does it do? bool conf(char item) {int val = (int)item; if((val > = 65) && (val = 97) && (val > num; cout

Solution

A) Given Function is

#include <iostream>

using namespace std;

bool conf(char item)

{

int val=(int)item;

if((val>=65) && (val <=90))

return true;

else if((val>=97) && (val<=122))

return true;

else return false;

}

int main()

{

    int val ;

cin >> val;

cout<< conf(val) << endl;

return 0;

}

Output: 65

   1

Explanation: The above function returns True i.e 1, if the entered value is with in the given Range of Ascii values of alphabets i.e (A to Z = 65 to 90) and ( a to z = 97 to 122 ) Otherwise it Returns False i.e 0

B) Given Function is

#include <iostream>

using namespace std;

int place(char item)

{

   char temp=toupper(item);

   int index=(int)temp-65;

    return index;

}

int main()

{

char item ;

cin >> item;

cout<< place(item) << endl;

return 0;

}

Output: Z

   25

Explanation : the above function Finds the Ascii value of Entered character by the user and Subtracts 65 from that Ascii character value. Here the Ascii value of Z is 90 so the index is

index = 90- 65 = 25

C) Program:

#include<iostream>
int Fibonacci(int x) //Here the value of num is assigned to x
{
if(x==0) return 0;
if(x==1) return 1;
return Fibonacci(x-1)+Fibonacci(x-2);

// Here We returns the value of Fibonacci after performing Fibonacci(x-1)+Fibonacci(x-2)
}
int main()
{
int num;
cin >> num;
cout<< Fibonacci(num) << endl;
return 0;
}

Output: After Trace through the recursive calls the result of calling Fibonacci(5) is 5

Fibonacci(5)

Fibonacci(x-1)+Fibonacci(x-2)

Fibonacci(5-1)+Fibonacci(5-2)

Fibonacci(4) + Fibonacci(3)
3 + 2 = 5

 Explain the following function - what does it do? bool conf(char item) {int val = (int)item; if((val > = 65) && (val = 97) && (val > num;
 Explain the following function - what does it do? bool conf(char item) {int val = (int)item; if((val > = 65) && (val = 97) && (val > num;

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site