Class Declaration
- Code: Select all
class voter
{
friend void sortid(voter v1[], int size); <--- this is for sortby id number
friend void sortlastname(voter v1[], int size); <----sort by lastname
private:
int idnumber;
char lastname [25];
char firstname[25];
char party [2];
int birthyear;
int currentage;
public:
voter();
voter(int,char[], char[], char[], int, int);
voter(const voter&);
void Add();
void Edit();
void operator = (const voter&);
void print(int);
void disksave(ofstream& outfile);
~voter();
};
and now here is the code i attempt to use for sorting by lastname. here are errors im getting.
:\Documents and Settings\Admin\Desktop\Project 4\Project4.cpp(322) : error C2664: 'strcmp' : cannot convert parameter 2 from 'bool' to 'const char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Admin\Desktop\Project 4\Project4.cpp(323) : error C2146: syntax error : missing ')' before identifier 'min'
C:\Documents and Settings\Admin\Desktop\Project 4\Project4.cpp(325) : error C2228: left of '.swap' must have class/struct/union type
Error executing cl.exe.
- Code: Select all
void sortArray (voter n[], int size) {
int i, j;
int min;
for ( i=0; i < size -1; i++ ) { //size- 1 because the last element is automaticly in order
min = i; // min is the index of smallest element that compare to the rest.
/*this loop find the smallest element and */
for (j = i+1; j < size; j++)
if ( strcmp(n[j].lastname, n[min].lastname < 0 )
min = j;
/*after this for loop min should be the index of smallest element
n[i].lastname.swap(n[min].lastname);
}
}
