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

#include \"stdafx.h\" #include <iostream> #include <fstream> #include <string> #

ID: 3609046 • Letter: #

Question

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;

class PersonalData
{
public:
int ID;
string Lname;
string Fname;
string number;
double amount;
string email;
PersonalData();
PersonalData(int temp_id,string temp_lname,stringtemp_fname,string temp_phone,double temp_amount);
void Display();
void EmailGenerator();
void set(int temp_id,string temp_lname,stringtemp_fname,string temp_phone,double temp_amount);

};

voidsort(PersonalData *info, int number_used);
    void swap_values(int& v1, int& v2);
    int index_of_smallest(PersonalData *info, intstart_index, int number_used);
//*****************MAIN*************************

int _tmain(int argc,_TCHAR* argv[])
{
ifstream in_stream;
in_stream.open("names.txt");
if(in_stream.fail())
{
   cout << "Data file not found.";
   exit(1);
}

   PersonalData*info[300];
   int i=0,temp_id;
   string temp_lname, temp_fname, temp_phone;
   double temp_amount;

while(in_stream>> temp_id >>temp_lname >>temp_fname >> temp_phone >> temp_amount)
  {
   info[i] = new PersonalData(temp_id, temp_lname,temp_fname, temp_phone, temp_amount);
   i++;
  }

for(int j=0; j<i;j++)
   (*info[j]).EmailGenerator();

  cout<<"Members List"<< endl<<"***********************************"<<endl;

  sort((*info),i);

for(int j=0;j<i;j++)
  (*info[j]).Display();

system("pause");
return 0;
}


//***********function definitions***************

PersonalData::PersonalData()
{
cout<<"You have reached the constructor.";
}

PersonalData::PersonalData(int temp_id,string temp_lname,stringtemp_fname,string temp_phone,double temp_amount)
{
ID=temp_id;
Lname=temp_lname;
Fname=temp_fname;
number=temp_phone;
amount=temp_amount;
}

voidPersonalData::Display()
{
    cout<< ID << " " << Lname << " " << Fname << " "<<number << " " << amount << " "<< email << endl;
}

voidPersonalData::EmailGenerator()
{
char initial;
initial=Fname[0]+32;
email=Lname+initial+"@wit.edu";

}

void sort(PersonalData*info,int number_used)
{
    int index_of_next_smallest;

    for(int index = 0; index < number_used - 1; index++)
    {
        index_of_next_smallest =index_of_smallest(info, index, number_used);

       swap_values(info[index].ID, info[index_of_next_smallest].ID );
     
    }
}

void swap_values(int&v1, int& v2)
{
    int temp;
    temp = v1;
    v1 = v2;
    v2 = temp;
}

intindex_of_smallest(PersonalData *info, int start_index, intnumber_used)
{
    int min = info[start_index].ID,
        index_of_min =start_index;
    for (int index = start_index + 1; index <number_used; index++)
        if (info[index].ID <min)
        {
           min = info[index].ID;
           index_of_min = index;
        }

    returnindex_of_min;
}

Explanation / Answer

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
using namespace std;

class PersonalData
{
public:
int ID;
string Lname;
string Fname;
string number;
double amount;
string email;
PersonalData();
PersonalData(int temp_id,string temp_lname,string temp_fname,stringtemp_phone,double temp_amount);
void Display();
void EmailGenerator();
void set(int temp_id,string temp_lname,string temp_fname,stringtemp_phone,double temp_amount);

};

void sort(PersonalData **info, int number_used);
void swap_values(int& v1, int& v2);
int index_of_smallest(PersonalData **info,int start_index, int number_used);
//*****************MAIN*************************

int _tmain(int argc,_TCHAR* argv[])
{
ifstream in_stream;
in_stream.open("names.txt");
if(in_stream.fail())
{
cout << "Data file not found.";
exit(1);
}

PersonalData*info[300];
int i=0,temp_id;
string temp_lname, temp_fname, temp_phone;
double temp_amount;

while (in_stream>>temp_id >>temp_lname >> temp_fname >>temp_phone >> temp_amount)
{
info[i] = new PersonalData(temp_id, temp_lname, temp_fname,temp_phone, temp_amount);
\cout<<" "<<temp_id<<" "<<temp_lname<<" "<<temp_fname<<" "<<temp_phone<<" "<<temp_amount;
i++;
if(in_stream.eof())
break;

}

for(int j=0; j<i;j++)
(*info[j]).EmailGenerator();

cout<<"MembersList"<< endl<<"***********************************"<<endl;

sort((info),i);

for(int j=0;j<i;j++)
(*info[j]).Display();

system("pause");
return 0;
}


//***********function definitions***************

PersonalData::PersonalData()
{
cout<<"You have reached the constructor.";
}

PersonalData::PersonalData(int temp_id,string temp_lname,stringtemp_fname,string temp_phone,double temp_amount)
{
ID=temp_id;
Lname=temp_lname;
Fname=temp_fname;
number=temp_phone;
amount=temp_amount;
}

voidPersonalData::Display()
{
cout<< ID << " " << Lname<< " " << Fname << " " <<number<< " " << amount << " "<< email << endl;
}

voidPersonalData::EmailGenerator()
{
char initial;
initial=(Fname[0]>='a' && Fname[0] <='z')?Fname[0]:Fname[0]+32;
email=Lname+initial+"@wit.edu";

}

void sort(PersonalData**in,int number_used)
{

intindex_of_next_smallest;

for (int index = 0; index< number_used - 1; index++)
{
PersonalData *info=in[index];
index_of_next_smallest = index_of_smallest(in, index,number_used);

swap_values(info->ID, in[index_of_next_smallest]->ID);
}
}

void swap_values(int&v1, int& v2)
{
int temp;
temp = v1;
v1 = v2;
v2 = temp;
}

intindex_of_smallest(PersonalData **in, int start_index, intnumber_used)
{
PersonalData *info=in[start_index];
int min = info->ID,
index_of_min = start_index;
for (int index = start_index + 1; index < number_used;index++)
{
info=in[index];
if (info->ID < min)
{

min =info->ID;
index_of_min = index;
}
}
return index_of_min;
}