


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Two c++ programs. The first program demonstrates string manipulation by modifying a string using substr, erase, and insert functions. The second program defines and calls two functions: function1 and function2, which perform subtraction and addition operations respectively. The main function initializes variables, calls the functions, and prints the results.
Typology: Slides
1 / 4
This page cannot be seen from the preview
Don't miss anything!



using namespace std; #include
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;