The program is supposed to allow the user to create student/staff entries, search by last name, and print all phonebook entries on the screen by using arrays. All of the sections of code are giving me fits debugging and I'm receiving quite a few errors I don't think I should.
Questions:
How come StudentIndividual is not a class nor are my set functions within student "found"?
How come within StaffIndividual.h it says no ";" before using?
And is my declaration of the arrays for my objects correct? I'm getting an error for the "]".
Any other constructive comments or pointers that will help me progress would be greatly appreciated.
Code:
//Phonebook program
#include <iostream>
#include <iomanip>
#include <fstream>
#include "Individual.h"
#include "StudentIndividual.h"
#include "StaffIndividual.h"
using namespace std;
ofstream fileout;
int main()
{
int selection = 0;
StudentIndividual studentInfo[10];
StaffIndividual staffInfo[10];
cout<<"Welcome to your digital phone book!"<<endl;
cout<<"Please choose from one of the following commands"<<endl;
cout<<"1. Create new student entry\n2. Create new staff entry\n3. Search by last name\n4. Display all entries"<<endl;
switch(selection)
{
case 1:
cout<<"Contact Info:\nFirst Name: "<<endl;
cout<<"Last Name: "<<endl;
cout<<"Phone Number: "<<endl;
cout<<"Hours taken: "<<endl;
cout<<"Grade Point Average: "<<endl;
cin>>studentInfo[++];
break;
case 2:
cout<<"Contact Info:\nFirst Name: "<<endl;
cout<<"Last Name: "<<endl;
cout<<"Phone Number: "<<endl;
cout<<"Job title: "<<endl;
cout<<"Year employeed: "<<endl;
cin>>staffInfo[++];
break;
case 3:
cout<<"Please enter the last name of the contact you want to retrieve."<<endl;
//for loop to compare strings
break;
case 4:
cout<<"All entries in phonebook:"<<endl;
//for loop to run through arrays
break;
}
Code:
// Base class
// Individual.h
#ifndef INDIVIDUAL_H
#define INDIVIDUAL_H
#include <string>
using namespace std;
class Individual
{
public:
//constructor
Individual (string, string, string);
//set functions
void setFirstName (string);
void setLastName (string);
void setPhoneNumber (string);
//get functions
string getFirstName();
string getLastName();
string getPhoneNumber();
//overloaded
friend std::istream& operator>> (istream &, Individual &);
friend std::ostream& operator<< (ostream &, Individual &);
protected:
string firstName;
string lastName;
string phoneNumber;
}
#endif
Code:
// Derived class
// StudentIndividual.h
#ifndef STUDENTI_H
#define STUDENT_H
#include <string>
#include "Individual.h"
class StudentIndividual : public Individual
{
public:
//constructor
StudentIndividual::StudentIndividual(double, int);
//set functions
void setGPA (double);
void setHours (int);
//get functions
double getGPA();
int getHours();
private:
double gpa;
int hours;
}
#endif
Code:
// Base class
// Individual.h
#ifndef STAFF_H
#define STAFF_H
#include <string>
#include "Individual.h"
using namespace std;
class StaffIndividual : public Individual
{
public:
//constructor
StaffIndividual::StaffIndividual(string, int);
//set functions
void setPosition(string);
void setYearEmployeed (int);
//get functions
string getPosition();
int getYearEmployeed();
private:
string position;
int yearEmployeed;
}
#endif
Code:
// C++
// Individual.cpp
// Individual class member functions
#include "Individual.h"
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
extern ofstream fileout;
//constructor
Individual::Individual(string first, string last, string number)
{
setFirstName(first);
setLastName (last);
setPhoneNumber(number);
}
//set functions
void Individual::setFirstName(string f)
{
firstName = f;
}
void Individual::setLastName(string l)
{
lastName = l;
}
void Individual::setPhoneNumber (string p)
{
phoneNumber = p;
}
// get functions
string Individual::getFirstName()
{
return firstName;
}
string Individual::getLastName()
{
return lastName;
}
string Individual::getPhoneNumber()
{
return phoneNumber;
}
istream& operator>> (istream &cin, Individual &obj)
{
string f, l, s;
cin >> f >> l >> s;
obj.firstName = f;
obj.lastName = l;
obj.phoneNumber = s;
return cin;
}
ostream& operator<< (ostream &out, Individual &obj)
{
fileout << "\n" << obj.getFirstName() << " " << obj.getLastName() << " " << obj.getPhoneNumber();
return fileout;
}
Code:
// C++
// StudentIndividual.cpp
// StudentIndividual class member functions
#include "StudentIndividual.h"
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
extern ofstream fileout;
//constructor
StudentIndividual::StudentIndividual(double average, int hour)
{
//:Individual (first, last, number);
setGPA(average);
setHours (hour);
}
//set functions
void StudentIndividual::setGPA(double g)
{
gpa = g;
}
void StudentIndividual::setHours(int h)
{
hours = h;
}
// get functions
double StudentIndividual::getGPA()
{
return gpa;
}
int StudentIndividual::getHours()
{
return hours;
}
Code:
// C++
// StaffIndividual.cpp
// StaffIndividual class member functions
#include "StaffIndividual.h"
#include <iostream>
#include <iomanip>
#include <fstream>
extern ofstream fileout;
//constructor
StaffIndividual::StaffIndividual(string pos, int yr)
{
//:Individual (first, last, number);
setPosition(pos);
setYearEmployeed (yr);
}
//set functions
void StaffIndividual::setPosition (string pos)
{
position = pos;
}
void StaffIndividual::setYearEmployeed(int year)
{
yearEmployeed = year;
}
// get functions
string StaffIndividual::getPosition()
{
return position;
}
int StaffIndividual::getYearEmployeed()
{
return yearEmployeed;
}