Docsity

C++ Programming: String Manipulation and Function Definitions, Slides of C programming

Partial preview of the text

Download C++ Programming: String Manipulation and Function Definitions and more Slides C programming in PDF only on Docsity!

using namespace std; #include using namespace std; int main (void) { string str1 = "What is the camel doing?"; string str2 = "fly"; string str3 = str1.substr(12, 5); str1.erase(12, 5); str1.insert(12, str2); cout << str1 << endl; // Remember strings are arrays as well. for (int i = 0; i < str3.length(); i++) cout << str3[i]; cout << endl;

using namespace std; int a = 18; int b = 6; int function1(int a, int b) { return a - b; } int function2() { int c; c = a + b; return c; } int main (void) { int b = 12; int c = 0; a = function1(b, a); c = function2(); cout << "a: " << a << " b: " << b << " c: " << c << endl;

using namespace std; void F1(int males, int females); void F2(int &m, int &f); int main() { int Boys = 3, Girls = 5; F1(Boys, Girls); cout << "\nAfter calling F1, within main()"; cout << "\n\tBoys = " << Boys; cout << "\n\tGirls = " << Girls; F2(Boys, Girls); cout << "\nAfter calling F2, within main()"; cout << "\n\tBoys = " << Boys; cout << "\n\tGirls = " << Girls; } void F1(int b, int g) { b += 3, g += 4; cout << "\nF1"; cout << "\n\tBoys = " << b; cout << "\n\tGirls = " << g; } void F2(int &b, int &g) { b = b + 8, g = g + 5; cout << "\nF2"; cout << "\n\tBoys = " << b; cout << "\n\tGirls = " << g;