C++ Session 8
C++ Session 8
void callByReference(int x)
{ x = 5; } The value of x is 3
int main()
{
int x = 3; //change does affect function call
callByReference( x );
cout << "The value of x is " << x;
return 0; }
#include <iostream> Call by reference
using namespace std;
void swap(int &, int &);
int main()
{
int a=10,b=20;
swap(a,b);
cout<<a<<" "<<b;
Answer
return 0;
}
20 10
void swap(int &c, int &d)
{
int t;
t=c;
c=d;
Call by Reference
#include <iostream>
using namespace std;
d. Display
i. Custmers name:
ii galons of water consumed:
ii Amout of water consumed GHC:
iii 2% of amount consumed to be added for rural water project and fire service.
iv. Total amount payable = Amount of water consumed + amount for rural water and fire service
NB:
Customer name is of type string
Water consumed, amount of water consumed, total Amont payable and 2% rural water project are of type float.