i have this c++ problem plz help! . In function main declare three integers a, b
ID: 657521 • Letter: I
Question
i have this c++ problem plz help!
. In function main declare three integers a, b, and c. Call a function randomNumbers to assign a random number between 1 and 50 to each and return using pointer parameters. Print the integers and their addresses in a function printNumbers.
Then call the function order to place the integers in numerical order using pass by address. Function order should have three parameters: int *aPtr, int *bPtr, and int *cPtr. The purpose of function order is to place the three integers in order so that a<b<c. (It is not necessary to implement a complicated sorting algorithm. The values can be placed in order using three comparisons.)
The integers should be printed in order with addresses from printNumbers. When the steps of the function order have been completed the smallest value will be stored in a, the middle in b, and the largest in c.
Explanation / Answer
#include <iostream>
#include <conio.h>
using namespace std;
void randomnumber(int *, int *, int*);
void printnumber(int *, int *, int*);
void order(int *,int *, int *);
int main()
{
int a,b,c;
randomnumber(&a, &b, &c);
printnumber(&a, &b, &c);
order(&a,&b,&c);
printnumber(&a, &b, &c);
return 0;
}
void randomnumber(int *s, int *t, int *u)
{
cout<<"Enter the value between 0-50 for a";
cin>>*s;
cout<<"Enter the value between 0-50 for b";
cin>>*t;
cout<<"Enter the value between 0-50 for c";
cin>>*u;
}
void printnumber(int *v, int *w, int *x)
{
cout<<"value of a="<<*v <<"address of a="<<v<<" ";
cout<<"value of b="<<*w <<"address of b="<<w<<" ";
cout<<"value of c="<<*x <<"address of c="<<x<<" ";
}
void order(int *aPtr, int *bPtr, int *cPtr)
{
int d,e,f;
if(*aPtr>*bPtr)
{ if(*aPtr>*cPtr)
{ if(*bPtr>*cPtr)
{
f=*aPtr;
e=*bPtr;
d=*cPtr;
}
else
{ f=*aPtr;
e=*cPtr;
d=*bPtr;
}
}
else
{
e=*aPtr;
d=*bPtr;
f=*cPtr;
}
}
else
{ if(*bPtr>*cPtr)
{
d=*aPtr;
f=*bPtr;
e=*cPtr;
}
else
{ d=*aPtr;
f=*cPtr;
e=*bPtr;
}
}
*aPtr=d;
*bPtr=e;
*cPtr=f;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.