I am working on a program for my Data Structures and Algorithms in C++ class.
Define function isNull () & writeNullToFile () in classes Personal and Student. Then define function remove ( ) in Database (very similar to modify ()). which locates the position of the record to be deleted and overwrites it with the null record. After a session in finished, a Database destructor should be invoked, which copies nonnull records to a new data file, deletes the old data file, and renames the new data file with the name of the old file.
Personal::Personal() : nameLen(10), cityLen(10) {
name = new char[nameLen+1];
city = new char[cityLen+1];
}
Personal::Personal(char *ssn, char *n, char *c, int y, long s) :
nameLen(10), cityLen(10) {
name = new char[nameLen+1];
city = new char[cityLen+1];
strcpy(SSN,ssn);
strcpy(name,n);
strcpy(city,c);
year = y;
salary = s;
}
Student::Student() : majorLen(10) {
Personal();
major = new char[majorLen+1];
}
Student::Student(char *ssn, char *n, char *c, int y, long s, char *m) :
majorLen(11) {
Personal(ssn,n,c,y,s);
major = new char[majorLen+1];
strcpy(major,m);
}
I am fairly new to programming so I will not be offended if you expert programmers talk down to me. I have my C++ for dummies for all the questions that is over my head. The steps I have completed so far follows. I will appreciate any guidance in the right direction for the other steps. Also I am getting the following error.
error LNK2019: unresolved external symbol "public: void __thiscall Personal::writeNullToFile(class std::basic_fstream<char,struct std::char_traits<char> > &)const " (?writeNullToFile@Personal@@QBEXAAV?$basic_fstream@DU?$char_traits@D@std@@@std@@@Z) referenced in function "private: void __thiscall Database<class Personal>::remove(class Personal const &)" (?remove@?$Database@VPersonal@@@@AAEXABVPersonal@@@Z)
Thanks in advance
1. Add an option to remove file form database:
else if (*option == '4') {
rec.readKey();
remove(rec);
}
2. Define Function isNull( ) in class Personal to determine the record is null.
class Personal {
public:
Personal();
Personal(char*,char*,char*,int,long);
void writeToFile(fstream&) const;
void readFromFile(fstream&);
void readKey();
void isNull();
int size() const {
return 9 + nameLen + cityLen + sizeof(year) + sizeof(salary);
}
3. Define Function isNull( ) in class Student to determine the record is null.
class Student : public Personal {
public:
Student();
Student(char*,char*,char*,int,long,char*);
void writeToFile(fstream&) const;
void readFromFile(fstream&);
void isNull();
int size() const {
return Personal::size() + majorLen;
}
4. Define Function writeToFile ( ) in class Personal to overwrite a record to be deleted by a null record.
class Student : public Personal {
public:
Student();
Student(char*,char*,char*,int,long,char*);
void writeToFile(fstream&) const;
void writeNullToFile(fstream&) const;
void readFromFile(fstream&);
void isNull();
int size() const {
return Personal::size() + majorLen;
}
5. Define Function writeToFile ( ) in class Student to overwrite a record to be deleted by a null record.
class Student : public Personal {
public:
Student();
Student(char*,char*,char*,int,long,char*);
void writeToFile(fstream&) const;
void writeNullToFile(fstream&) const;
void readFromFile(fstream&);
void isNull();
int size() const {
return Personal::size() + majorLen;
}
6. Define Function remove( ) in database which locates the position of a record to be deleted and overwrites it with the null record.
}
database.close();
cout << "The record to be deleted is not in the database\n";
8. After a session in finished, a Database destructor should be involked, which copies nonnull records to a new data file, deletes the old data file, and renames the new data file with the name of the old file.