error C2059: syntax error : 'private'
what would cause this
firstLady.h
Code:
#pragma once private: public: firstLady(void); firstLady(char*, unsigned, unsigned, unsigned, unsigned); ~firstLady(void); const char* getName(); unsigned getFrom(int); unsigned getTo(int); unsigned getBorn(int); unsigned getDied(int); void setName(int, char*); void setFrom(int, unsigned); void setTo(int, unsigned); void setBorn(int, unsigned); void setDied(int, unsigned); void printRecord(int); void printAll();
firstLady.cpp
Code:
#include "firstLady.h"
//dont need data[i]
//default constructor
firstLady_t(){}
//new constructor so we know how new ones should be defined
firstLady_t(char *n, unsigned f, unsigned t, unsigned b, unsigned d)
{
strcpy_s(name, maxNameLen, n);
from=f;
to=t;
born=b;
died=d;
}
//assign new data
void setName(int i, char newname[maxNameLen+1])
{
//strcpy_s(data[i]->name,newname);
}
void setFrom(int i,unsigned newfrom)
{
data[i]->from=newfrom;
}
void setTo(int i,unsigned newto)
{
data[i]->to=newto;
}
void setBorn(int i,unsigned newborn)
{
data[i]->born=newborn;
}
void setDied(int i,unsigned newdied)
{
data[i]->died=newdied;
}
/*
* Retrieve a record (row) from the table.
* Inputs: search-term, name-array
* Return value: returns index of record containing search term, or -1 otherwise
*/
int getRecord(char searchTerm[])
{
int i;
for(i=0; i<size && strcmp(searchTerm,data[i]->name) !=0;i++);
if(i==size)
return -1;
else
return i;
}
/*
* Print one record (row) from the table
*/
//methods to do the printing
string ShowName(int i)
{
return data[i]->name;
}
unsigned ShowFrom(int i)
{
return data[i]->from;
}
unsigned ShowTo(int i)
{
return data[i]->to;
}
unsigned ShowBorn(int i)
{
return data[i]->born;
}
unsigned ShowDied(int i)
{
return data[i]->died;
}
//show records based on return value getRecord
void printRecord(int i)
{
cout<<endl;
cout<<"Name: "<<ShowName(i)<<" From: "<<ShowFrom(i)<<" To: "<<ShowTo(i)<<" Born: "<<ShowBorn(i)<<" Died: "<<ShowDied(i)<<endl;
cout<<endl;
}
/*
* prompt for user entry and return date in
* unsigned format -- mmddyyyy
*/
unsigned getDate(char* prompt)
{
unsigned retval = 0;
cout << "Please enter the " << prompt << "(mmddyyyy): ";
cin.ignore(80,'\n');
cin >> retval;
return retval;
}
void getName(char * prompt, char retval[], int size)
{
cout << "Please enter name: ";
cin.get(retval, maxNameLen, '\n');
}
/* newRecord checks space and returns the index of
* the next free row in the table, or -1 if no
* space is available.
* side-effect: increments size
*/
int newRecord()
{
if(size<numPrez-1)
{
data[size++]=new struct firstLady_t;
return size++;
}
else
{
return -1;
}
}
mytestproj.cpp
Code:
#include "stdafx.h"
#include <string>
#include <iostream>
#include <sstream>
#include "firstLady.cpp"
using namespace std;
const int numPrez=43;
const int maxNameLen=80;
/*
* Table of first ladies
*/
// This time, let's create a structure that holds a single
// row of the table.
// This statement just defines the structure and gives the
// definition a name, firstLady_t.
struct firstLady_t {
char name[80];
unsigned from;
unsigned to;
unsigned born;
unsigned died;
//default constructor
firstLady_t(){}
//new constructor so we know how new ones should be defined
firstLady_t(char *n, unsigned f, unsigned t, unsigned b, unsigned d)
{
strcpy_s(name, maxNameLen, n);
from=f;
to=t;
born=b;
died=d;
}
};
struct firstLady_t *data[numPrez];
int size = 0;
int _tmain(int argc, _TCHAR* argv[])
{
data[size++]= new struct firstLady_t("Washington, Martha",4301789,3041797,6021731,5221802);
data[size++]= new struct firstLady_t("Adams, Abigail",3041979,3041801,11111744,10281818);
data[size++]= new struct firstLady_t("Randolph, Martha",3041801,3041809,9271772,10101836);
data[size++]= new struct firstLady_t("Madison, Dolley",3041809,3041817,5201768,7121849);
data[size++]= new struct firstLady_t("Monroe, Elizabeth",3041817,3041825,6301768,9231830);
data[size++]= new struct firstLady_t("Adams, Louisa",3041825,3041829,2121775,5151852);
char searchTerm[maxNameLen+1] = {'\0'}; // name to search for
char choice = '\0';
int nr = 0; // need to declare, initialize outside the case statement
cout << "Table of U.S. First Ladies\n" << endl;
// main loop -- either add a new entry or search for one
while(choice != 'q')
{
cout << "Enter 's' to search for an entry, 'a' to add one or q to quit: " ;
cin>>choice;
cin.ignore(80, '\n');
switch(choice)
{
case 's':
case 'S':
int target;
getName("Please enter name to search for: ", searchTerm, sizeof(searchTerm));
if((target=getRecord(searchTerm)) == -1)
{
// what happens without ()?
cout << "Data for " << searchTerm << " not found. " << size << " records searched." << endl;
}
else
{
printRecord(target);
}
break;
case 'a':
case 'A':
nr = newRecord();
if(nr < 0)
{
cout << "No space for additonal records." << endl;
continue;
}
else
{
char n[maxNameLen+1];
// collect data for new record
getName("name for new entry", n, sizeof(n));
data[nr]=new firstLady_t(n,getDate("From date "),getDate("To"),getDate("Born"),getDate("Died"));
cout << n << " successfully added." << endl;
}
break;
case 'Q': choice = 'q';
case 'q':
break;
default: cout << choice << " is not a valid option." << endl;
}
}
return 0;
}

