Thursday, 27 June 2019

library function programe

  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main()
  5. {
  6. double x = 10.25, result;
  7. result = sqrt(x);
  8. cout << "Square root of " << x << " is " << result << endl;
  9. return 0;
  10. }

The pow() function computes a base number raised to the power of exponent number.

  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main ()
  5. {
  6. long double base = 4.4, result;
  7. int exponent = -3;
  8. result = pow(base, exponent);
  9. cout << base << "^" << exponent << " = " << result << endl;
  10. // Both arguments int
  11. // pow() returns double in this case
  12. int intBase = -4, intExponent = 6;
  13. double answer;
  14. answer = pow(intBase, intExponent);
  15. cout << intBase << "^" << intExponent << " = " << answer;
  16. return 0;
  17. }
When you run the program, the output will be:
4.4^-3 = 0.0117393
-4^6 = 4096 
The abs() function in C++ returns the absolute value of the argument.
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main()
  5. {
  6. double x = -87.91, result;
  7. result = abs(x);
  8. cout << "abs(" << x << ") = |" << x << "| = " << result << endl;
  9. return 0;
  10. }
When you run the program, the output will be:
abs(-87.91) = |-87.91| = 87.91
The strlen() function in C++ returns the length of the given string.
  1. #include <cstring>
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. char str1[] = "This a string";
  7. char str2[] = "This is another string";
  8. int len1 = strlen(str1);
  9. int len2 = strlen(str2);
  10. cout << "Length of str1 = " << len1 << endl;
  11. cout << "Length of str2 = " << len2 << endl;
  12. if (len1 > len2)
  13. cout << "str1 is longer than str2";
  14. else if (len1 < len2)
  15. cout << "str2 is longer than str1";
  16. else
  17. cout << "str1 and str2 are of equal length";
  18. return 0;
  19. }
When you run the program, the output will be:
Length of str1 = 13
Length of str2 = 22
str2 is longer than str1
The toupper() function in C++ converts a given character to uppercase.
  1. #include <cctype>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdio>
  5. using namespace std;
  6. int main()
  7. {
  8. char str[] = "John is from USA.";
  9. cout << "The uppercase version of \"" << str << "\" is " << endl;
  10. for (int i=0; i<strlen(str); i++)
  11. putchar(toupper(str[i]));
  12. return 0;
  13. }
When you run the program, the output will be:
The uppercase version of "John is from USA." is 
JOHN IS FROM USA.

The isupper() function in C++ checks if the given character is a uppercase character or not.
  1. #include <cctype>
  2. #include <iostream>
  3. #include <cstring>
  4. using namespace std;
  5. int main()
  6. {
  7. char str[] = "This Program Converts ALL UPPERCASE Characters to LOWERCASE";
  8. for (int i=0; i<strlen(str); i++)
  9. {
  10. if (isupper(str[i]))
  11. /* Converting uppercase characters to lowercase */
  12. str[i] = str[i] + 32;
  13. }
  14. cout << str;
  15. return 0;
  16. }
When you run the program, the output will be:
this program converts all uppercase characters to lowercase




Directory implementation

The selection of directory-allocation and directory-management algorithms significantly affects the efficiency, performance, and reliabil...