In: Computer Science
make the following "swap" working corretly,
write the missing code at line 14.
#include <iostream>
using namespace std;
void swap(int& x, int& y)
{
int z = x;
x =y;
y=z;
}
int main ()
{
int a= 45, b =35;
cout<<" before swap\n";
cout<<"a = " << a << "b = " << b<< "\n";
________________________
cout << "After swap with pass by reference\n";
cout << "a = " << a << " b = " << b << "\n";
}
Write a template function count that returns the number of occurences of value in the array a[0:n-1].
Missing code :
**********************************************
CPP program :
//header files
#include <iostream>
using namespace std;
//swap() method
void swap(int& x, int& y)
{
int z = x;
x =y;
y=z;
}
//main() method
int main ()
{
int a= 45, b =35;//declaring variables
cout<<" before swap\n";
//pritn value of a and b
cout<<"a = " << a << " b = " << b<<
"\n";
//call method swap() and pass a and b
swap(a,b);//function call
//print value of a and b
cout << "After swap with pass by reference\n";
cout << "a = " << a << " b = " << b
<< "\n";
}
*****************************************
Screen for indentation :
=================================
Output :