C
Charles Wilson
I believe that my problem is in how I am doing my C++ strings. But I
am not sure. Can someone point me in the right direction. Thank you
#include <iomanip>
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
struct{int chronum;string pname;int next;}//makes structure box with C
++ style string
plist[50],temp;//give the number of colmns
int n=0,end,maxindex,i;
ifstream fin;
ofstream fout;
fin.open("pres.dat");
fout.open("hw7.dat");
fin>>plist[n].pname;//inputs president name into list
while(!fin.eof())
{
plist[n].chronum=n+1;//assigns chronum to presidents as inputed.
n++;//tracks current president
fin>>plist[n].pname;
}
for(end=n-1;end>0;end--)//it seems to input all on the first past and
than removes one of end each time.
{
maxindex=0;
for(i=1;i<=end;i++)
if(plist.pname>plist[maxindex].pname)
maxindex=i;
temp=plist[maxindex];
plist[maxindex]=plist[end];
plist[end]=temp;
}
//cout.setf(ios::fixed);
//cout.setf(ios::showpoint);
//cout.precision(2);
//cout<<plist.chronum<<plist.pname<<endl;
return 0;
}
am not sure. Can someone point me in the right direction. Thank you
#include <iomanip>
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
struct{int chronum;string pname;int next;}//makes structure box with C
++ style string
plist[50],temp;//give the number of colmns
int n=0,end,maxindex,i;
ifstream fin;
ofstream fout;
fin.open("pres.dat");
fout.open("hw7.dat");
fin>>plist[n].pname;//inputs president name into list
while(!fin.eof())
{
plist[n].chronum=n+1;//assigns chronum to presidents as inputed.
n++;//tracks current president
fin>>plist[n].pname;
}
for(end=n-1;end>0;end--)//it seems to input all on the first past and
than removes one of end each time.
{
maxindex=0;
for(i=1;i<=end;i++)
if(plist.pname>plist[maxindex].pname)
maxindex=i;
temp=plist[maxindex];
plist[maxindex]=plist[end];
plist[end]=temp;
}
//cout.setf(ios::fixed);
//cout.setf(ios::showpoint);
//cout.precision(2);
//cout<<plist.chronum<<plist.pname<<endl;
return 0;
}