Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*Exercise 1: Redesign program ( down code ) to use only void functions and Call-

ID: 3546916 • Letter: #

Question

*Exercise 1:

Redesign program ( down code ) to use only void functions and Call-by-Reference. You should not use any global variables in your program.


#include <iostream>

using namespace std ;

bool multiple(int num1, int num2)

{ if(num1%num2 == 0)

    { return true;  }

    else

    { return false; } }

int main ()

{ int num1, num2;

    while(1)

    {

        cout<< "Enter First number (enter -1 to exit): ";

        cin>> num1;

        if(num1==-1) return 0;

        else

        cout<<"Enter Second number : ";

        cin>> num2;

        

        cout<< "is "<< num1;

        { if(multiple(num1,num2)==false)

            cout<< " not ";   }

        cout<<" a multiple of "<< num2 << endl; }

return 0; }


Explanation / Answer

#include <iostream>

using namespace std ;

void multiple(int num1, int num2, bool *flag)

{ if(num1%num2 == 0)

{ *flag = true; }

else

{ *flag = false; }}

int main ()

{ int num1, num2;
bool isMultiple;

while(1)

{

cout<< "Enter First number (enter -1 to exit): ";

cin>> num1;

if(num1==-1) return 0;

else

cout<<"Enter Second number : ";

cin>> num2;

cout<< "is "<< num1;
multiple(num1,num2,&isMultiple);
{ if(!isMultiple)

cout<< " not "; }

cout<<"a multiple of "<< num2 << endl; }

return 0; }