Question

Hi, for the below output the run is: x : 1 | y : 1 x...

Hi, for the below output the run is:

x : 1 | y : 1
x : 0 | y : 2
x : 0 | y : 0
x : 2 | y : 1
x : 1 | y : 8

Also compare your output output should not be wrong, run on "Xcode" to see the about output.

Thanks

int x = 1, y = -1;

void swapplus1(int n1, int n2) {
         int temp = n1 + 1;

         n1 = n2 - 1;
         n2 = temp;
         x = x + n1;

}
void swapplus2(int& n1, int& n2) {

         int temp = n1 + 1;
         n1 = n2 - 1;
        n2 = temp;
}

void swapplus3(const int& n1, const int& n2) {
         int n1val, n2val, temp = n1 + 1;
         n1val = n2 - 1;
        n2val = temp;

        y -= n2;
}
void swapplus4(int* p1, int* p2) {

         int temp = *p1 + 1;
         *p1 = *p2 + 1;
         *p2 = temp;
         x = *p1 + y;
}

void swapplus5(int* &p1, int* &p2) {
        int* temp = p1 + 1;
        p1 = p2 - 1;
        p2 = temp;

}
void print(const int& x, const int& y) {

         cout << "\n x: " << x << " |y: " << y;
}


int main() {
       int arr[]{ 2, 4, 6, 8, 10, 12, 14 };
       y = arr[3] / size(arr);
      

       swapplus1(x,y);         print(x, y);
       swapplus2(x,y);         print(x, y);
       swapplus3(x,y);         print(x, y);
       swapplus4(&x,&y);    print(x, y);

       int *px = &x, *py = &y;
       (*px)--;
       (*py) -= -7;
       swapplus5(px,py);         print(x, y);
      
return 0;
}

      

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Basically after executing the code the output will produce

x: 0 |y: 0

x: - 1|y: 1

x: - 1|y: 0

x: 1|y: 0

x: 0|y:7

Compare the given output along with question is fully mismatch. For first line output bot x and y having 0 but guven 1

Fir second line output x is - 1 and y is 1 but given 0 and 2.

Similarly other line output is mismatch

Add a comment
Know the answer?
Add Answer to:
Hi, for the below output the run is: x : 1 | y : 1 x...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Study the c++ code below and answer the question on templates after // A polymorphic swap...

    Study the c++ code below and answer the question on templates after // A polymorphic swap function for any type of object (an example) template<typename T> void MySwap( T& x, T& y) { T temp; temp = x; x = y; y = temp; } // A polymorphic class holding an [x,y] position of any type template<class T> class Position { public: Position(T x=0, T y=0) : x_(x), y_(y) {} friend std::ostream& operator<<(std::ostream& os, const Position& p) { return os...

  • howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE]...

    howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8};    int index;    index=0;    res = values[index];    for (int j=1; j<SIZE; j++)    {        if (values[j] > res)        {            res = values[j];            index = j;        cout << index << res << endl;        }    }    cout <<...

  • Find Output. Just output. No explanation needed.. #include <iostream> #include <string> using namespace std; class baseClass...

    Find Output. Just output. No explanation needed.. #include <iostream> #include <string> using namespace std; class baseClass { public: void print() const; baseClass(string s = " ", int a = 0); //Postcondition: str = s; x = a; protected: int x; private: string str; }; class derivedClass: public baseClass { public: void print() const; derivedClass(string s = "", int a = 0, int b = 0); //Postcondition: str = s; x = a; y = b; private: int y; }; int...

  • How would I be able to get a Merge Sort to run in this code? MY...

    How would I be able to get a Merge Sort to run in this code? MY CODE: #include <iostream> #include <fstream> #include <stdlib.h> #include <stdio.h> #include <time.h> using namespace std; class mergersorter { private:    float array[1000] ;    int n = 1000;    int i=0; public:    void fillArray()    {        for(i=1;i<=n;i++)        {            array[i-1]= ( rand() % ( 1000) )+1;        }    }    void arrayout ()    {   ...

  • In JAVA Thank You What is the exact output produced by running the method test? /**...

    In JAVA Thank You What is the exact output produced by running the method test? /** * TestSwap.java * Demonstrates parameter passing involving arrays and integers, * scope of variables, flow of control, and overloaded methods. */ public class TestSwap { public void swap (int x, int y) { int temp; temp = x; x = y; y = temp; System.out.println("Inside swap version 1:"); System.out.println("x = " + x); System.out.println("y = " + y); } public void swap (int[] a,...

  • Add and subtract polynomials using linked lists: The output should look like the following: The code...

    Add and subtract polynomials using linked lists: The output should look like the following: The code for the header file, Polynomial.h, is given as such: ***********HEADER************* #include <iostream> #include <cstdlib> using namespace std; class polyll { //this is class POLYLL, but all lower case private: struct polynode { float coeff; int exp; polynode* link; } * p; public: polyll(); void poly_append(float c, int e); void display_poly(); void poly_add(polyll& l1, polyll& l2); void poly_subtract(polyll& l1, polyll& l2); ~polyll(); }; polyll::polyll() {...

  • Hello, I need help with my code. The code needs to display random number from 1...

    Hello, I need help with my code. The code needs to display random number from 1 to 50 every time the program runs but the program displays the same random numbers every time. Thanks #include #include using namespace std; void dynAlloc(int size, int *&arr); void displayArray(int *arr, int n); void insertionSort(int *arr, int n, int *temp); void linear_search(int *arr, int n, int key); void binary_search(int *arr, int n, int key); int main() {   const int n = 50; int *arr,...

  • I have a problem with merging the two linked lists together. In the function AscendMerge, I...

    I have a problem with merging the two linked lists together. In the function AscendMerge, I am trying to compare the values of each node in the two lists and output them into one list in ascended order. Everything works except for the one function. Can someone tell me what im doing wrong, when I run it it skips over values. #include <iostream> #include <cassert> using namespace std; struct nodeType {    int info;    nodeType *link;    nodeType *current;...

  • Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting...

    Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting at index 0 void exchange(int x, int y) { int temp:= x; x:= y; y:= temp; } main(){ for (j = 0; j < 5; j++) arr[j]:= j; i:= 1; exchange(i, arr[i+1]); output(i, arr[2]); //print i and arr[2] } What is the output of the code if both parameters in function swapping are passed by: a- value? b- reference? c- value-result?

  • Why is the assertion failing? what code can fix the problem and where should that code...

    Why is the assertion failing? what code can fix the problem and where should that code be located at? class Point { public: Point() { myX = myY = 0; } Point(int n, int y) { myx = x; myy = y; } int getX() const { return myX; } int getY() const { return myY; } virtual void read(istream& in) { in >> myX >> myY; } private: int myx, myY; }; class Point3D : Public Point { public:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT