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

Question 1: using namespace std; Question 2: Could you help me define this: plan

ID: 3631054 • Letter: Q

Question

Question 1: using namespace std;
Question 2: Could you help me define this: planet *generatePlanet(fstream &);
what is *

Question 3: fstream fin("input.txt",ios::in); what is ios::in

Question 4:

void reportPlanet()
{
int i=0,size;
fstream fin("input.txt",ios::in);
planet p[10],*ptr;
fin>>size;
while(!fin.eof()&&i<size)
{
planet *ptr=generatePlanet(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++;
}


What is os !fin.eof
What is ptr
What is mean of size and i

The following is the source code:


#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;

typedef struct planet
{
int id;
int x;
int y;
int z;
public:
planet()
{}
//parameterised planet
planet(int id, int x, int y, int z)
{
this->id = id;
this->x = x;
this->y =y;
this->z = z;
}
};
//generatePlanet prototype
planet *generatePlanet(fstream &);
void reportPlanet();
int main()
{
//Open file in input mode
fstream fin("input.txt",ios::in);
//Dispaly and exit if file doesnot exist
if(fin.fail())
{
cout<<"cannot open file";
exit(0);
}
//read data from "input.txt" file
reportPlanet();
//To pause the output
system("pause");
return 0;
}
void reportPlanet()
{
int i=0,size;
fstream fin("input.txt",ios::in);
planet p[10],*ptr;
fin>>size;
while(!fin.eof()&&i<size)
{
planet *ptr=generatePlanet(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++;
}
}
/*This generatePlanet returns new created planet pointer */
planet *generatePlanet(fstream &fin)
{
int id,x,y,z;
//Reading data from the file
fin>>id>>x>>y>>z;
//return planet data
return new planet(id,x,y,z);
}

Explanation / Answer

Dear, 1) using namespace std;     In order to include standard input and output from class iostream need place the statement 2) The function prototype  *generatePlanet(fstream &); states that it returns a pointer of type planet 3)  ios::in means open the file for input 4) !fin.eof   check whether end of file reached or not      ptr represents pointer of type planet      mean of size of i is the number of characters mean in file Hope this will help you


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote