-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPredefinedFunctionsDEMO.cpp
More file actions
66 lines (52 loc) · 2.07 KB
/
Copy pathPredefinedFunctionsDEMO.cpp
File metadata and controls
66 lines (52 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//************************************************************************
// Author: Rolando Carreon
// Date: feb 06 2025
// Language: C++
// Assignment: PredefinedFunctionDEMO
// Description: working with predifined strcutures
//************************************************************************
#include<iostream>
// include math functions //
#include<cmath>
using namespace std;
int main()
{
// declare local variables
int base, exponent;
int result;
string string1 = "Hello World!";
string string2 = "Welcome to C++ Programming.";
string string3;
long strLength;
long startPos;
cout << "Demo of pre-defined functions\n\n";
// get the base and exponent from the user //
cout << "Please enter the base value:\n";
cin >> base;
cout << "Please enter the exponent value: \n";
cin >> exponent;
// calculate the result //
// uses the <cmath> include to calculate user input //
// since using int, max value is 2,147,483,647 //
result = pow(base, exponent);
cout << base << "^" << exponent << " is " << result << endl;
// calculate the square root using the user inputs //
result = sqrt(base);
cout << "The square root of " << base << " is " << result << endl;
// calculate the absolute value
cout << "The absolute value of -10 is " << abs(-10) << endl;
// find the length of a string //
// straight up cout the straing1 length instead of saving it to variable //
cout << "The length of string1 is " << string1.length() << endl;
// save strLength variable to the string2 length value
strLength = string2.length();
// cout the saved string2 length varrible from the strLegnth variable
cout << "The length of string2 is " << strLength << endl;
// find a substring within a string //
string3 = string1.substr(6,54);
cout << "The substring is " << string3 << endl;
// find the starting positon of a substring //
startPos = string1.find("World");
cout << "The substring \"World\" starts at position " << startPos << endl;
return 0;
}