One box have some apples and another box have some oranges, develop a C++ program to find the sum of fruits and double the sum of fruits in the box using call by reference concept
#include <iostream>
using namespace std;
int sumInTwoBoxes(const int& a, const int& b);
void doubleInBox(int& a);
int main()
{
int apples = 0;
int oranges = 0;
cout << "Enter number of apples in box: ";
cin >> apples;
cout << "Enter number of oranges in another box: ";
cin >> oranges;
cout << "Now in first box " << apples << " apples and in another box " << oranges << " oranges." << endl;
cout << "Sum of two boxes is: " << sumInTwoBoxes(apples, oranges) << " fruits." << endl;
cout << "Now will double fruits in box with apples." << endl;
doubleInBox(apples);
cout << "Now in first box " << apples << " apples and in another box " << oranges << " oranges." << endl;
return 0;
}
int sumInTwoBoxes(const int& a, const int& b)
{
return a + b;
}
void doubleInBox(int& a)
{
a *= 2;
}#include <iostream>
using namespace std;
int sumInTwoBoxes(const int& a, const int& b);
void doubleInBox(int& a);
int main()
{
int apples = 0;
int oranges = 0;
cout << "Enter number of apples in box: ";
cin >> apples;
cout << "Enter number of oranges in another box: ";
cin >> oranges;
cout << "Now in first box " << apples << " apples and in another box " << oranges << " oranges." << endl;
cout << "Sum of two boxes is: " << sumInTwoBoxes(apples, oranges) << " fruits." << endl;
cout << "Now will double fruits in box with apples." << endl;
doubleInBox(apples);
cout << "Now in first box " << apples << " apples and in another box " << oranges << " oranges." << endl;
return 0;
}
int sumInTwoBoxes(const int& a, const int& b)
{
return a + b;
}
void doubleInBox(int& a)
{
a *= 2;
}
Comments
Leave a comment