Using C/C++, declare three integer variables (e.g. A, B, C) in main() and assign
ID: 3813597 • Letter: U
Question
Using C/C++, declare three integer variables (e.g. A, B, C) in main() and assign their values from standard input (cin). Then call a function swap 1() to swap their values through pointers (e.g. A, B. C are 4, 5 and 6. after calling swap(). A has B's value 5, B has C's value 6, and C has As value 4). and output A, B, and C; finally, define another function swap 2 to swap A, B, C one more time using references Using C/C++, define an integer pointer in main(), and use this pointer to dynamically allocate an integer array with 50 elements; assign the array with random numbers in range [0, 999]. Then, pass the array as parameters) to a function prime_count() which counts the number of the integers that are prime, and prints those integers, after the function call, print the "counter" result; finally, use delete to deallocate the array memories. Note that you need to define a Boolean function prime() which tells whether an integer is prime or not. This function will be called and used by prime_count() to tell whether the numbers in the array are prime or not. Redo programs of 1 and 2 by using separate header and source files: declaring the functions in header files, and implementing functions in source files.Explanation / Answer
Hi, I am attaching First part.
For another parts, you can send different question requests.
Please avoid asking multiple questions at a time.
Thank you
#include<iostream.h>
//using namespace std;
void swap1(int *num1, int *num2, int *num3)
{
int temp;
temp = *num1;
*num1 = *num2;
*num2 = *num3;
*num3 = temp;
}
void swap2(int &a, int &b, int&c)
{
int temp;
temp=a;
a=b;
b=c;
c=a;
}
int main()
{
int a,b,c;
cout<<“ Enter the value of A: ”;
cin>>a;
cout<<“ Enter the value of B: ”;
cin>>b;
cout<<“ Enter the value of C: ”;
cin>>c;
swap1(&a,&b,&c);
swap2(a,b,c);
cout<<“ After Swapping:”;
cout<<“ A,B,C: ”<<a<<“ ”<<b<<“ ”<<c;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.