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;
}
#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;
}
Comments
Leave a comment