Answer to Question #174878 in C++ for Kaviyan P

Question #174878

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


1
Expert's answer
2021-03-26T12:39:37-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS