I've been given a data file that lists Presidents Names, Last name First, Then First Name.
The object is to create a chart that looks like
0 2 Adams,john 22
1 6 Adams,jons_quincy 21
2 21 Arthur,Chester 7
. . .... .
. . .... .
. . .... .
42 1 Washington,George 0
43 28 Wilson,Woodrow 16
The Code I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include<fstream>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
struct Product
{
int chronom;
char pname[25];
int next;
};
Product plist[50];
int temp;
int i;
int rightmost;
int imax;
ifstream fin;
ofstream fout;
fin.open("prez.dat");
fout.open("output.dat");
int n=0;
fin>>plist[n].pname;
while(!fin.eof())
{
plist[n].chronom = n+1;
n++;
fin>>plist[n].pname;
}
for(rightmost=n-1;rightmost>0;rightmost--)
{
imax=0;
for(i=1;i<=rightmost;i++)
if(strcmp(plist [i].pname,plist[imax].pname)>0)
imax=i;
temp = plist[imax];
plist[imax]=plist[rightmost];
plist[rightmost]=temp;
}
cout<<"location\tchronum\tpresident's name\tnext prez"<<endl<<endl;
for (int i = 0; plist[i] != NULL && i < 50; i++) {
cout << n << " " << plist[i].chronom << " " << plist[n].pname << " " << plist[rightmost] << endl;
delete plist[i];
}
return 0;
}
|
It spits out several errors...
error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'main::Product' (or there is no acceptable conversion)
This is for the last for loop.
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'main::Product' (or there is no acceptable conversion)
This is for the last out put command
cout<<....
error C2440: 'delete' : cannot convert from 'main::Product' to 'void *'
this is for the delete function in the last for loop.
My skills of C++ is limited, and I have no idea how to approach these errors without potentially screwing up my code.
Any help is appreciated.