Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<iostream.h> #include<fstream.h> #include<iomanip.h> #include<stdlib.h>

ID: 3631101 • Letter: #

Question

#include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
#include<stdlib.h>

//using namespace std;

class planet
{
private:

int id;
int x;
int y;
int z;

public:

planet(int,int,int,int);
};

planet(int id,int x,int y,int z)
{
this->id = id;
this->x = x;
this->y = y;
this->z = z;
}
planet *function(fstream &);//function prototype//

void report_planet();
int main()
{
fstream fin("input.txt",ios::in);//Open file in input mode//

if(fin.fail()) //Dispaly and exit if file doesnot exist//
{
count<<"cannot open file";
exit (0);
}

report_planet(); //read data from "input.txt" file//
system("pause"); //To pause the output//
return 0;
}

void report_planet()
{
int i,size;
i=0;
fstream fin("input.txt",ios::in);//open file for input//

planet the_planet[10],*ptr;
fin>>size;//get the number from file//
while(!fin.eof()&&i<size) //if not at end of file, continue reading numbers//
{
planet *ptr=function(fin);
cout<<"Planet Id "<<ptr->id<<endl;
cout<<"Planet x-position "<<ptr->x<<endl;
cout<<"Planet y-position "<<ptr->y<<endl;
cout<<"Planet z-position "<<ptr->z<<endl;
i++;
}
}

planet *function(fstream &fin)
{
int id,x,y,z;
fin>>id>>x>>y>>z; //Reading data from the file//
return new planet(id,x,y,z);//Return planet data//

}

Explanation / Answer

#include #include #include #include //using namespace std; class planet { public : int id; int x; int y; int z; public: friend planet(int,int,int,int) planet(int id,int x,int y,int z) { this->id = id; this->x = x; this->y = y; this->z = z; } planet *function(fstream &);//function prototype// void report_planet(); }; int main() { fstream fin("input.txt",ios::in);//Open file in input mode// if(fin.fail()) //Dispaly and exit if file doesnot exist// { coutsize;//get the number from file// while(!fin.eof()&&i