searching an array of type class - c++

I am working on this C++ program that controls student information. I have been able to add and display the information of the student. I need to search the the array for a specific student by his ID, but it seems there is a problem assigning the array of type class to int variable in order to search for the ID?
#include <iostream>
#include <string>
#include <array>
#include <iomanip>
using namespace std;
class student{
private:
int id, age;
std::string fname, lname;
string cob;
char s;
public:
student()
{
id=age=0;
fname=lname=cob="";
}
void setid(int);
void setage(int);
void setfname(string);
void setlname(string);
void setsex(char);
void setcob(string);
int getid();
int getage();
string getfname();
string getlname();
string getcob();
char getsex();
};
void student::setfname(string n)
{ fname=n;}
void student::setlname(string n)
{ lname=n;}
void student::setcob(string n)
{ cob=n;}
void student::setid(int n)
{ id=n;}
void student::setage(int n)
{ age=n;}
void student::setsex(char n)
{ s=n;}
string student::getfname()
{ return fname;}
string student::getlname()
{ return lname;}
string student::getcob()
{ return cob;}
int student::getid()
{ return id;}
int student::getage()
{ return age;}
char student::getsex()
{ return s;}
std::array<student, 100> studentlist;
void addstd()
{
int id, age;
string fname, lname;
string cob;
char s;
for(int i=0;i<3;i++)
{
cout<<"Enter ID Number"<<endl;
cin>>id;
studentlist[i].setid(id);
cout<<"Enter First Name"<<endl;
cin>>fname;
studentlist[i].setfname(fname);
cout<<"Enter last Name"<<endl;
cin>>lname;
studentlist[i].setlname(lname);
cout<<"Enter age"<<endl;
cin>>age;
studentlist[i].setage(age);
cout<<"Enter student's Sex(F or M) "<<endl;
cin>>s;
studentlist[i].setsex(s);
cout<<"Enter Country of birth"<<endl;
cin>>cob;
studentlist[i].setcob(cob);
}
}
void displayinfo()
{
for(int i=0;i<3;i++)
{
cout<<"Student ID: "<<studentlist[i].getid()<<endl;
cout<<"First Name: "<<studentlist[i].getfname()<<endl;
cout<<"Last Name: "<<studentlist[i].getlname()<<endl;
cout<<"Student Age: "<<studentlist[i].getage()<<endl;
cout<<"Student Gender: "<<studentlist[i].getsex()<<endl;
cout<<"Student Birth City: "<<studentlist[i].getcob()<<endl;
cout<< "\n";
}
}
void searchstd()
{
int num;
cout<<"Enter ID of Student "<<endl;
cin>>num;
int temp;
for(int i=0;i<3;i++)
{
studentlist[i]=temp; // here is the problem!!
if(temp==num)
{
}
}
}
/*std::array<student, 100> studentlist;*/
void main()
{
/*
student s;
student std[100];
*/
student s;
int choice;
do{
cout << "-----------Menu------------" << endl;
cout << " 1. Add a student " << endl;
cout << " 2. Search for student by ID " << endl;
cout << " 3. Display all students information " << endl;
cout << " 4. Remove a students " << endl;
cout << " 5. Display students aged between 34 - 50 " << endl;
cout << " 6. Modify a student's information " << endl;
cout << " 7. Exit " << endl;
cout << " Enter your choice 1, 2, 3, 4 ,5,6,7 " << endl;
cin>>choice;
switch(choice) {
case 1:
addstd();
break;
case 2:
searchstd();
break;
case 3:
displayinfo();
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
exit(0);
break;
default:
cout << "Please enter 1, 2, 3, 4, 5, 6 or 7 : " << endl << endl;
}
}while(choice!=8);
}

studentlist[i]=temp; // here is the problem!!
studentlist[] is an array of objects of the class student, and temp is a variable of type int. This is invalid. You are trying to assign an uninitialized int, which could have any value, to an array of students.
I believe, by looking at your implementation, that you are looking for something like this (although this search could be improved):
int num;
cout<<"Enter ID of Student "<<endl;
cin>>num;
for(int i=0;i<3;i++)
{
if(studentlist[i].getid() == num)
{
// found student with id == num
}
}

Related

To find max salary using friend function of a class having employee details(name,ID, position,salary) and print max salary details

#include <iostream.h>
#include <conio.h>
class Employee{
int Id;
string Name;
string Post;
public:
long int Salary;
void GetDetails();
void DisplayDetails();
friend void MaxSalary();
};
void Employee::GetDetails(){
cout << "\nEnter Employee Id : ";
cin >> Id;
cout << "\nEnter Employee Name : ";
cin.ignore();
getline(cin,Name);
cout << "\nEnter Employee Post : ";
cin.ignore();
getline(cin,Post);
cout << "\nEnter Employee Salary : ";
cin >> Salary;
}
void Employee::DisplayDetails(){
cout << "\nEmployee Id : " << Id;
cout << "\nEmployee Name : " << Name;
cout << "\nEmployee Post : " << Post;
cout << "\nEmployee Salary : " << Salary;
}
void MaxSalary(Employee a[], int x){
long int max;
for(int j=0; j<x; j++){
if(a[j].Salary>a[j+1].Salary)
max=a[j].Salary;
}
cout<<"Maximum Salary = "<<max<<endl;
}
int main()
{
int n, i;
cout<<"Enter Number of Employees : ";
cin>>n;
Employee E[n];
cout<<"\n\n----------ENTER DETAILS OF EMPLOYEES----------\n\n";
for(i=0;i<n;i++){
cout<<"\n\n Enter details of Employee "<<i+1<<endl;
E[i].GetDetails();
}
cout<<"\n\n----------DETAILS OF EMPLOYEES----------\n\n";
for(i=0;i<n;i++){
cout<<"\n\n Details of Employee "<<i+1<<endl;
E[i].DisplayDetails();
}
MaxSalary(E[n], n );
return 0;
}
There are lots of defects in the given code:
The variable length arrays (VLAs) are not allowed in C++. In other words, the syntax:
cin >> x;
Employee emp[x];
is invalid. Note that C99 is an exception in this case.
In the For loop of MaxSalary(), a[j + 1] is given, it will access out-of-bounds array, which invokes an undefined behavior.
Declaring a variable in a class as public breaks the rule of OOP:
public:
long int Salary; // Not a good idea
You do not need to pass [n] as the function argument:
MaxSalary(E[n], n);
The refined code would look like:
#include <iostream>
#include <limits>
#include <vector>
// Using this statement in order to reduce the spam of 'std::' here
using namespace std;
class Employee {
int ID;
string name;
string post;
long int salary;
public:
Employee() {}
// Initializing the class object
void initEmployee(int id, string varName, string varPost, long sal) {
ID = id, \
name = varName, \
post = varPost, \
salary = sal;
}
// 'salary' getter
long getSalary() {
return salary;
}
// The friend function
friend void maxSalary(vector<Employee> data) {
int max = 0;
for (size_t i{1}, len = data.size(); i < len; i++)
// Comparison
if (data[i].getSalary() > data[i - 1].getSalary())
max = data[i].getSalary();
// After the loop execution, prints the maximum salary
std::cout << "Maximum salary: " << max << endl;
}
};
int main(void) {
int total;
cout << "Enter the total number of employees: ";
cin >> total;
vector<Employee> emp(total);
for (int i{}; i < total; i++) {
// Temporary variables to store data in each iteration
Employee temp;
string tempName;
string tempPost;
int tempID;
long int tempSal;
cout << "Name of the employee " << i + 1 << ": ";
getline(cin, tempName);
// Clearing the 'cin' in order to prevent the getline skips
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Post of the employee: ";
getline(cin, tempPost);
cout << "Employee ID: ";
cin >> tempID;
cout << "Total salary: ";
cin >> tempSal;
// Initializing the temporary object
temp.initEmployee(tempID, tempName, tempPost, tempSal);
// Pushing the object into the main vector
emp.push_back(temp);
}
// Comparing the vector elements (note: it is a friend function)
maxSalary(emp);
return 0;
}
As a test case:
Enter the total number of employees: 2 // Number of employees
Name of the employee 1: John Doe // Employee 1
Post of the employee: Manager
Employee ID: 100
Total salary: 15000
Name of the employee 2: Max Ville // Employee 2
Post of the employee: Assitant Manager
Employee ID: 102
Total salary: 50000
Maximum salary: 50000 // Maximum salary

Deleting a record from a file in c++

I have wriiten a code to add , delete and dispaly a record of employees consisting of employee ID ,name,age and location.
But I am unable to code the delete function
My code is as follows:
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class Document
{
public:
int Add();
void Delete();
void Display();
int No_of_lines();
int empno();
private:
fstream document;
fstream newdocument;
string data;
int age;
int emp_id;
int idtodelete;
char name[100],loc[100];
};
int Document::No_of_lines()
{
int number = 0;
document.open("document.txt");
while (getline(document, data))
{
++number;
}
return number;
}
int Document::Add()
{
Document d1;
document.open ( "document.txt",ios::app);
int x = d1.No_of_lines();
int emp_id = ++x;
cout << "The employee ID is: " << emp_id;
document <<emp_id;
cout<< "\n Ënter Name:" ;
cin>>name;
document <<"\t Name:"<< name;
cout<<"Enter Age:";
cin>> age;
document << "\t Age:"<< age;
cout<< "Enter location:";
cin>> loc;
document << "\t Location:"<< loc;
document << "\n";
document.close();
return 0;
}
void Document::Delete()
{
Document d2;
d2.Display();
int num;
char line[1000];
document.open("document.txt");
newdocument.open("newdocument.txt");
cout << "Enter the ID to delete \n";
cin >> idtodelete;
while (document.good())
{
const int maxchar = 1000;
const int maxtokens = 10;
char* token[maxtokens] = {};
char split[maxchar];
document.getline(split, maxchar);
int n = 0;
token[0] = strtok(split, " ");
istringstream(token[0]) >> num;
if (num != idtodelete)
{
document >> emp_id >> name >> age >> loc;
newdocument << emp_id<< name<< age<< loc;
}
else
{
}
}
document.close();
newdocument.close();
remove("document.txt");
rename("newdocument.txt", "document.txt");
}
void Document::Display()
{
document.open("document.txt");
while (!document.eof())
{
getline(document,data);
cout<<data<<endl;
}
document.close();
}
int main()
{
Document d;
char ans;
int ch;
do
{
system ( "cls");
cout<< "Enter your choice \n";
cout << "\t1. Add Data \n " << "\t2. Delete Data \n" << "\t3. Display Data \n";
cout<< "\t4. Exit\n";
cout<< " Enter Choice \n ";
cin >> ch;
switch(ch)
{
case 1:
cout << " Adding Data : \n";
d.Add();
break;
case 2:
//cout << "Deleting data : \n";
d.Delete();
break;
case 3:
cout << "Displaying data : \n";
d.Display();
break;
case 4:
cout << "Exit";
break;
default :
cout << "Invalid Input \n";
break;
}
cout<< " click y to quit or any other key to continue " ;
cin>>ans;
}
while (ans != 'y');
return 0;
}
The simple way is to remove by employee ID. You just ask for the employee ID, to know what employee to remove.
Then, you cannot remove lines in the middle of a sequential file, so you just
rename the file as document.back
create a new document.txt
read document.back and copy all employees to document.txt except the one you want to delete
close both files
remove document.back
That's all ... except for the usual test for IO errors, backup file existing, and so on...
I tested your code. First, you forgot to close document in method int Document::No_of_lines(). Next on my MSVC2008, I have to explicitely call document.clear() after reaching end of file. You also do not test document immediately after a getline, meaning that you execute the code after a bad read.
I removed newdocument from Document class, because IMHO it is useless. Here is a possible implementation of Delete:
void Document::Delete()
{
Document d2;
Display();
int num;
document.open("document.txt");
document.clear();
d2.document.open("newdocument.txt", ios::out | ios::trunc);
cout << "Enter the ID to delete \n";
cin >> idtodelete;
while (document.good())
{
getline(document, data);
if (document) {
int n = 0;
istringstream(data) >> num;
if (num != idtodelete)
{
d2.document << data << endl;
}
}
}
document.close();
d2.document.close();
remove("document.txt");
rename("newdocument.txt", "document.txt");
}

How clear the screen and return to menu

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
struct student
{
string firstname;
string lastname;
int age;
string gender;
string course;
string year;
string section;
int studno;
};
int menu(int &menuChoice);
void userInfo(student user[], int size, int const track);
void listUser(student user[], int size, int const track);
int main(int argc, char** argv) {
int menuChoice;
int static track = 0;
student user[30];
do {
menu(menuChoice);
switch(menuChoice) {
case 3:
userInfo(user, 30, track);
track++;
break;
case 4:
listUser(user, 30, track);
break;
}
} while(menuChoice != 5);
return 0;
}
int menu(int &menuChoice)
{
do {
cout<< "\n\t\t==========================================="
<< "\n\t\t|\tSimple Student Record Program\t |"
<< "\n\t\t==========================================="
<< "\n\n\t\t\t\t [MAIN MENU]"
<< "\n\n\n[1] - Search Student\n[2] - Best Students\n[3] - Add New Student\n[4] - View Students\n[5] - Delete Student"
<< "\n\nEnter a choice: ";
cin>> menuChoice;
if (menuChoice>5||menuChoice<1)
{
cout<< "Please select an existing option!";
}
}
while (menuChoice>5||menuChoice<1);
return menuChoice;
}
void userInfo(student user[], int size, int const track)
{
cout<< "\n\n\t\t\t\t[Add a student]";
cout<< "\n\nEnter student's first name: ";
cin>> user[track].firstname;
cout<< "\nEnter student's last name: ";
cin>> user[track].lastname;
cout<< "\nAge: ";
cin>> user[track].age;
cout<< "\nGender: ";
cin>> user[track].gender;
cout<< "\nCourse: ";
cin>> user[track].course;
cout<< "\nYear: ";
cin>> user[track].year;
cout<< "\nSection: ";
cin>> user[track].section;
cout<< "\nStudent No.: ";
cin>> user[track].studno;
return;
}
void listUser(student user[], int size, int const track)
{
int list;
cout<< "\n\tName|||Age|||Gender|||Course|||Year|||Section|||Student No.\n";
for (list=0; list<track; list++)
{
cout<< "\n\n" << user[list].firstname <<" " << user[list].lastname <<"\t\t" << user[list].age <<"\t" << user[list].gender << "\t" << user[list].course << "\t" << user[list].year << "\t" << user[list].section << " " << user[list].studno <<"\n";
}
return;
}
My previous question was about a student record program got on hold for being broad, so, taking the advice and answers from some users there, I started to search and take action, I'll be specific this time.
So here's the whole code so far. My question is: how to clear the screen so that when you choose an option on the menu, you are then taken to that specific 'place' in the code and once you are done with that part of the program, clear the screen again and go back to the menu?
This is impossible to do with standard C++, which has no notion of a screen at all. You'd have to use a 3rd party library (e.g. the Windows API if you're on Windows). Since I assume that this is an exercise where only standard, platform-independent C++ is allowed, you cannot meet the requirement.
What I can tell you, again, is that you are not supposed to use arrays for such basic programming. Use std::vector.

c++ array of type " class student" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i have this c++ assignment....and iam having a bit of a problem since iam used more to c#
i created a class student in order to create an array with different elements...the problem is how can i see the array in the functions in the class part...inorder to fill it with students details and display it..here is the code:
#include <iostream>
#include <string>
#include <array>
#include <iomanip>
using namespace std;
class student{
private:
int id, age;
string fname, lname, cob;
char s;
int stdcount;
public:
void addstd();
void searchstd(int n);
void displayinfo();
void deletestd(int n);
void displayrange();
void modifyinfo(int n);
};
void student::addstd()
{
cout<<"Enter ID Number"<<endl;
cin>>id;
cout<<"Enter First Name"<<endl;
cin>>fname;
cout<<"Enter last Name"<<endl;
cin>>lname;
cout<<"Enter age"<<endl;
cin>>age;
cout<<"Enter student's Sex(F or M) "<<endl;
cin>>s;
cout<<"Enter Country of birth"<<endl;
cin>>cob;
}
void student::displayinfo()
{
for(int i=0;i<100;i++)
{
cout<<ar[i];
}
}
void student::searchstd(int m)
{
}
void main()
{
student s;
student std[100];
int choice;
do{
cout << "-----------Menu------------" << endl;
cout << " 1. Add a student " << endl;
cout << " 2. Search for student by ID " << endl;
cout << " 3. Display all students information " << endl;
cout << " 4. Remove a students " << endl;
cout << " 5. Display students aged between 34 - 50 " << endl;
cout << " 6. Modify a student's information " << endl;
cout << " 7. Exit " << endl;
cout << " Enter your choice 1, 2, 3, 4 ,5,6,7 " << endl;
cin>>choice;
switch(choice) {
case 1:
for(int i=0;i<3;i++)
{
std[i].addstd();
}
break;
case 2:
int numid;
cout <<"enter id "<<endl;
cin>>numid;
s.searchstd(numid);
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
default:
cout << "Please enter 1, 2, 3, 4, 5, 6 or 7 : " << endl << endl;
}
}while(choice!=7);
}
Your problem has very little to do with C++ and everything to do with proper design. Even if you used C#, you would have very little, if any justification for creating a student object as the way you did for C++.
First, as others have mentioned, a student should only know about themself (first name, last name). It isn't a student's responsibility to keep track of other students. A very rough design would look like this:
#include <string>
class student {
private:
int id, age;
std::string fname, lname, cob;
char s;
public:
student() {}
void setId(int n) { id = n; }
void setFirstName(const std::string& s) { fname = s; }
void setLastName(const std::string& s) { lname = s; }
//etc..
int getId() const { return id; }
std::string getFirstName() const { return fname; }
std::string getLastName() const { return lname; }
// etc...
};
That is all a student should have. Setting and getting the student's information. Nothing more, nothing less. You can embellish this by adding a constructor to easily create an entire student in one call (if you want to do this). But this is the basic gist of what a student class should look like.
Now you create an array of these students:
typedef std::array<student, 100> StudentList; // creates an array of 100 students.
or preferably, a vector< student >, so that it becomes a lot easier to handle:
#include <vector>
//..
typedef std::vector<student> StudentList;
Then you use StudentList as your array / vector of students.
It then becomes trivial when it comes to display the students -- just go through the array one by one and display the students information.
Modify your displayInfo function to take an input
void student::displayInfo(student ar[], int numStudents)
{
for(int i=0;i<numStudents;i++)
{
cout<<ar[i]; // if you have << operator defined
}
}
Then in main you could say:
student std[100];
displayInfo (std, 100); // this is passing your array in (you need to populate it though)

How to pass variables to a class

I have been working on this code for quite some time now and I had posted it before but then after fixing that problem another problem arose so I created a new post with the name of this problem. Ok the problem is that I am obviously not passing the variables to the Administrator class the right way. I have tried two ways which is all my book shows and both have given me an error that says error C2512: 'SalariedEmployee' : no appropriate default constructor available". I have tried
//Lynette Wilkins
//Week 12
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
class SalariedEmployee
{
private:
double wageRate;
int hours;
protected:
string name;
string ssn;
double netPay;
string department;
public:
SalariedEmployee(string n, string s, double np, double w, int h, string d);
~SalariedEmployee() {cout<<endl;}
string Getname(); //returns name
string Getssn(); // returns social security number
double GetnetPay(); //returns netPay
string Getdepartment(); // returns department
double GetwageRate(); //returns wage rate
int Gethours(); //returns hours
void Setname(string); //sets name
void Setssn(string); //sets ssn
void SetnetPay(double); //sets net pay
void Setdepartment(string); //sets department
void SetwageRate(double); //sets wage rate
void Sethours(int); //sets hours
};
SalariedEmployee::SalariedEmployee(string n, string s, double np, double w, int h, string d) : name(n),
ssn(s),
netPay(np),
wageRate(w),
hours(h),
department(d)
{}
string SalariedEmployee::Getname()
{
return name;
}
string SalariedEmployee::Getssn()
{
return ssn;
}
double SalariedEmployee::GetnetPay()
{
return netPay;
}
double SalariedEmployee::GetwageRate()
{
return wageRate;
}
int SalariedEmployee::Gethours()
{
return hours;
}
void SalariedEmployee::Setname(string n)
{
name = n;
}
void SalariedEmployee::Setssn(string s)
{
ssn = s;
}
void SalariedEmployee::SetnetPay(double np)
{
netPay = np;
}
void SalariedEmployee::Setdepartment(string d)
{
department = d;
}
void SalariedEmployee::SetwageRate(double w)
{
wageRate = w;
}
void SalariedEmployee::Sethours(int h)
{
hours = h;
}
class Administrator : public SalariedEmployee
{
protected:
string title;
string responsi;
string super;
double salary;
public:
Administrator(string t, string r, string s, double sa);
~Administrator();
string Gettitle();
string Getresponsi();
string Getsuper();
double Getsalary();
void Settitle(string);
void Setresponsi(string);
void Setsuper(string);
void Setsalary(double);
void print();
};
Administrator::Administrator(string t, string r, string s, double sa) : title(t), responsi(r), super(s), salary(sa)
{
}
Administrator::~Administrator()
{
cout<<endl;
}
string Administrator::Gettitle()
{
return title;
}
string Administrator::Getresponsi()
{
return responsi;
}
string Administrator::Getsuper()
{
return super;
}
double Administrator::Getsalary()
{
return salary;
}
void Administrator::Settitle(string ti)
{
title = ti;
}
void Administrator::Setresponsi(string re)
{
responsi = re;
}
void Administrator::Setsuper(string su)
{
super=su;
}
void Administrator::Setsalary(double sa)
{
salary= sa;
}
void Administrator::print( )
{
cout << "\n_______________________________________________\n";
cout << "Pay to the order of " << name<< endl;
cout << "The sum of " << netPay << " Dollars\n";
cout << "_________________________________________________\n";
cout <<endl<<endl;
cout << "Employee Number: " << ssn << endl;
cout << "Salaried Employee. Regular Pay: "
<< salary << endl;
cout << "_________________________________________________\n";
}
int main()
{
string name;
string soc;
double net = 0;
double wage = 0;
int hrs = 0;
string dept;
string admtitle;
string resp;
string sup;
double sal = 0;
int response = 0;
string date = "January 12, 2013";
cout<<setprecision(2)
<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint);
SalariedEmployee emp1(name, soc,net, wage, hrs, dept);
Administrator adm1(admtitle, resp, sup, sal);
while(response != 4){
cout<<"Employee and Administrator Salary Program "<<endl;
cout<<"(You will have to enter data first before you do anything else)"<<endl<<endl;
cout<<"Enter Employee Data, Enter 1"<<endl;
cout<<"Change data, Enter 2"<<endl;
cout<<"Print Check, Enter 3"<<endl;
cout<<"End Program, Enter 4"<<endl<<endl;
cout<<"Please make your selection"<<endl;
cin>> response;
switch (response)
{
case 1:
cout <<"The employee's data will be entered here: "<<endl<<endl;
cout<<"Enter the employees name: ";
cin.ignore();
getline(cin, name);
cout<<"Enter the employees social security number: ";
cin.ignore();
getline(cin, soc);
cout<<"Enter the employees net pay: ";
cin>>net;
cout<<"Enter the employees wage rate: ";
cin>>wage;
cout<<"Enter the number of hours the employer worked: ";
cin>>hrs;
cout<<"Enter the employees title: ";
cin.ignore();
getline(cin,admtitle);
cout<<"Enter the employees area responsibility: ";
cin.ignore();
getline(cin, resp);
cout<<"Enter the employees salary: ";
cin>>sal;
cout<<endl<<endl<<endl;
break;
case 2:
cout<<"Please change the data you entered previously here. " <<endl<<endl;
cout<<"Enter the employees name: ";
cin.ignore();
getline(cin, name);
cout<<"Enter the employees social security number: ";
cin.ignore();
getline(cin, soc);
cout<<"Enter the employees net pay: ";
cin>>net;
cout<<"Enter the employees wage rate: ";
cin>>wage;
cout<<"Enter the number of hours the employer worked: ";
cin>>hrs;
cout<<"Enter the employees title: ";
cin.ignore();
getline(cin,admtitle);
cout<<"Enter the employees area responsibility: ";
cin.ignore();
getline(cin, resp);
cout<<"Enter the employees salary: ";
cin>>sal;
cout<<endl<<endl<<endl;
break;
case 3:
cout <<"Information Printed"<<endl<<endl;
cout<<"_____________________________"<<date<<endl;
&Administrator::print;
break;
default:
cout<<endl<<endl
<<"Invalid Selection! Try Again"<<endl;
exit(1);
}
}
system("PAUSE");
return 0;
}
Administrator(string t, string r, string s, double sa); will attempt to call the default constructor of the base class if you don't specify another. (a default constructor is one that can be called without any arguments)
The base class doesn't have a default constructor, ergo the error.
To call another constructor of the base class:
Administrator::Administrator(string t, string r, string s, double sa) :
SalariedEmployee(<args>), //base constructor call
title(t), responsi(r), super(s), salary(sa) //members
{
}