Create a class; employee with 22 employees (permanent, temporaly)
Class members: First name, IDno, Age, Depertment, salary,No of days, Gender, Marital status.
Class function members are: capturenewemployee(), Displayemployeedetails(), Searchemployee().

Dani AI

Generated

The original task from was to model an Employee class for a small roster (22 people, permanent/temporary) with basic fields and operations. posted a quick C++ example that shows the right idea: one class per employee and simple capture/display/search routines. The sample works as a learning prototype but has a few real problems that would cause trouble in real use and with longer input.

Main issues in the posted implementation: fixed, tiny character buffers for textual fields (these cause truncation and buffer overflows); using formatted extraction (operator>>) so names with spaces are lost; the “search” shown is just printing the current object instead of doing a container-level lookup; the program mixes data and direct I/O which makes testing hard; there is no input validation or unique-ID enforcement. Also the example uses small fixed arrays for the roster instead of the requested 22 or a dynamic container that can be resized safely.

A more robust approach: store text with std::string (std::string) and keep the roster in a standard container such as std::vector (std::vector) sized or reserved for 22 entries. Use an enum for employment type, double for salary, and size_t for counts. Separate the Employee data model from user I/O: write member accessors and non-member functions that accept streams so the class can be unit-tested without interactive input. Implement search as a container operation (linear scan or an std::unordered_map keyed by ID for fast lookup) and return a safe handle (index, pointer, or optional) rather than printing directly.

Practical tips: read full lines with std::getline to preserve spaces, validate numeric input and ranges, enforce unique IDs at insert time, and prefer the rule-of-zero (let default constructors/destructors do their job unless special resource management is needed). Refactoring the posted code along these lines will make it safe, testable, and suitable for a 22-person roster.

hi try this one
#include<iostream>
using namespace std;
class employee
{
int Id_no,No_days,age;
float salary;
char first_name[5],depat[5],gen[4],material[6];
public:
void capturenewemployee();
void employeedetails();
void searchemployee();
};
void employee :: capturenewemployee(void)
{
cout << "enter the firstname" << "\n" ;
cin >> first_name ;
cout << " enter age " << "\n" ;
cin >> age;
cout << " enter the Id_no" << "\n" ;
cin >> Id_no ;
cout << " enter the department " << "\n" ;
cin >> depat ;
cout <<" enter the gender" << "\n" ;
cin >> gen ;
cout << " enter material status" << "\n" ;
cin >> material ;
cout << " enter the No_days " << "\n" ;
cin >> No_days;
cout << " enter the salary" << "\n";
cin >> salary ;
}
void employee :: employeedetails(void)
{
cout <<" display result" << "\n";
cout << first_name << "\n";
cout << age << "\n";
cout << Id_no << "\n";
cout << depat << "\n";
cout << gen << "\n";
cout << material << "\n";
cout << No_days << "\n";
cout << salary << "\n";
}
void employee :: searchemployee(void)
{
cout <<" search result"<< "\n";
cout << first_name << "\n";
cout << age << "\n";
cout << Id_no << "\n";
cout << depat << "\n";
cout << gen << "\n";
cout << material << "\n";
cout << No_days << "\n";
cout << salary << "\n";
}
int main()
{
employee ne[10],ol[10];int i;

for(i=0;i<3;i++)
{
cout <<"enter employee details" << "\n";
ne.capturenewemployee();
}
ne[0].employeedetails();
ne[2].searchemployee();
return 0;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.