Answer to Question #246008 in C++ for roe

Question #246008

List the output of the following program segment. If an error is contained in the program,please mark and explain the error. For the rest of the program, assume that all lines with an error are removed from the program.

#include<iostream.h>

class Node{

public: double data

private: Node *next;

};

int main(void){

double *px,*py;

double x,y;

Node *p,*q,*r;

x=9.5;

y=-2.0;

px=8.6;

*px=10.0;

*x=*px;

x=*px;

py=&y;

p=new Node();q=new Node();r=new Node();

p->data=1.0;

q->data=2.0;

r->data=3.0;

p->next=q;

q->next=r;

r->next=p;

cout<<*px<<endl;

cout<<x<<endl;

cout<<*py<<endl;

cout<<q->next;

cout<<p->next->next->next->next->data<<endl;

delete q;

cout<<p->next->next->next->next->data<<endl;

return 0;

}


1
Expert's answer
2021-10-05T15:45:42-0400
#include <iostream>

using namespace std;

class Node
{
public:
    double data;
    Node *next;
};


int main(void)
{


    double *px, *py;
    double x, y;
    Node *p, *q, *r;
    x = 9.5;
    y = -2.0;
    *px = 8.6;
    *px = 10.0;
    x = *px;
    x = *px;
    py = &y;
    p = new Node();
    q = new Node();
    r = new Node();
    p->data = 1.0;
    q->data = 2.0;
    r->data = 3.0;
    p->next = q;
    q->next = r;
    r->next = p;
    cout << *px << endl;
    cout << x << endl;
    cout << *py << endl;
    cout << q->next;
    cout << p->next->next->next->next->data << endl;
    delete q;
    cout << p->next->next->next->next->data << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS