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

http://pastebin.com/8EDjHNhB I\'m having trouble with a assignment. I don\'t kno

ID: 3549563 • Letter: H

Question

http://pastebin.com/8EDjHNhB


I'm having trouble with a assignment. I don't know if my teacher wants me to write all astronauts and put it in a file or to read it off a file. The link to the assignment is above.


This is what I have so far. It's been a while since I mess with c++ with arrays and such so if anyone can help me complete this, I gradually appericated it. Also the teacher doesn't like it when we use advanced techniques so I'll be thankful if you can keep it basic since we just started. I'm willing to add more points if someone can get it right. Thank you.


#include<stdio>
#include<stdlib>
#include<iostream>
#include<string>
#include<conio>
#include<fstream>
#include<iomanip>


using namespace std;


class profile

{

char fname[15];
char lname[15];
char id[4];

double height, weight;


public:

void display();
void search();

};

void profile::display()
{
ifstream profile("Astronaut.data");

if(profile.is_open())
{
while(profile>>id>>fname>>lname>>height>>weight)
{
cout<<"-------------------------------------------------------------------------"<<endl;
cout<<"ID First name Last Name Height Weight "<<endl;
cout<<id<<" "<<fname<<" "<<lname<<" "<<height<<" "<<weight<<endl;
cout<<"-------------------------------------------------------------------------"<<endl;
}
}
else
cout<<"The file could not open."<<endl;
}

Explanation / Answer

//this one is Astronaut.data file

1001 John watson

5.9 70.54

1002 steven desuja

5.6 65.79

1003 sarlock homes

6.0 82.64

1004 jhon lock

5.8 76.54

1005 steve jobs

6.2 89.65

1006 mark jonson

5.7 69.54

1008 faruk sanitra

5.2 60.54

1009 kishor singh

5.10 75.64

1010 ratan birla

5.9 72.92

1011 jorge linus

5.8 73.55

1012 steven hocking

5.4 68.77

1013 richard frank

5.8 70.66

1014 arya sansui

5.4 68.99

1015 bhomya singlis

5.7 76.65

1016 srkant optimumprime

6.5 90

//here is your main programme

#include<iostream>

#include<string>

#include<fstream>

#include<iomanip>

using namespace std;


//structure of astronaut

struct ASTRONAUT

{

int idofastro;

struct{

char first[15];

char last[15];

}Name;

struct{

double height;

double weight;

}BODYSTATS;

};


int main()

{

fstream astro,out,netway;

netway.open("NetWay.data",fstream::in);

out.open("Report.out",fstream::out);

astro.open("Astronaut.data",fstream::in);

struct ASTRONAUT temp;

struct ASTRONAUT arr[26];//given maximum 26 astronaut

int count=0;

while(astro>>temp.idofastro>>temp.Name.first>>temp.Name.last>>temp.BODYSTATS.height>>temp.BODYSTATS.weight)

{

count++;

}

int i=0;

astro.clear();

astro.seekg(0,ios::beg);

//1-d array of astronaut

while(i<count)

{

astro>>temp.idofastro>>temp.Name.first>>temp.Name.last>>temp.BODYSTATS.height>>temp.BODYSTATS.weight;

arr[i]=temp;

i++;

}

//printing this array to output file

out<<"Total Astronaut"<<endl;

out<<setw(5)<<"ID"<<setw(15)<<"First Name"<<setw(15)<<"Last Name"<<setw(10)<<"Height"<<setw(10)<<"Weight"<<endl;

i=0;

while(i<count)

{

out<<setw(5)<<arr[i].idofastro<<setw(15)<<arr[i].Name.first<<setw(15)<<arr[i].Name.last<<setw(10)<<arr[i].BODYSTATS.height<<setw(10)<<arr[i].BODYSTATS.weight<<endl;

i++;

}

//processing netway file

out<<" astronauts selected for the special training mission ";

int ID;

while(netway>>ID)

{

for(int i=0;i<count;i++)

{

if(ID==arr[i].idofastro)

{

out<<setw(5)<<arr[i].idofastro<<setw(15)<<arr[i].Name.first<<setw(15)<<arr[i].Name.last<<setw(10)<<arr[i].BODYSTATS.height<<setw(10)<<arr[i].BODYSTATS.weight<<endl;

break;

}

}

}

cout<<"See output in Report.out File ";

astro.close();

netway.close();

out.close();

return 0;

}