I am new to the C++ so here i have one problem. I am not able to understand what i have to do in the below problem so please help me.
using class Employee, to create a database for the details of the
employee are entered at the time of joining like firstname, lastname, age, etc... For
names, use dynamic allocation of memory and also when they are leaving, this memory
should be recaptured. The program should return the total number of employees and their
details.
2) Then give that class members for firstname, lastname, age, etc.
3) For the names, use dynamically allocated memory
...etc
(if you didn't notice, I'm just reading the paragraph and interpretting each sentence as an individual step in the process. It really doesn't get much simpler than that... the assignment is telling you exactly what to do and how to do it.)
If a particular step is giving you trouble, post the step and why it's confusing you. Show us what you've done so far.
Below is the code but it is not working fine and also i want to know that HOW to implement "For
names, use dynamic allocation of memory and also when they are leaving, this memory
should be recaptured. The program should return the total number of employees and their
details." thing.? and HOW do i delete one employee and redisplay the record.
It creates a pointer to the new object using the new operator. I wouldn't bother using new for basic types. instead of char arrays, just use string - need to #include <string> and do one of these:
1. put std:: before each item that is in the std namespace - this is better than usingnamespace std;
2. put using std::cout; using std::cin; std::string; etc for each thing that is in std namespace, after the #includes then you can use cout, cin, string without qualification.
Each obj created with new should have a corresponding delete, otherwise a memory leak.
I always name my classes with a leading 'C' & capitalise leading letters of words as in CEmployee - just a reminder that it is a class.
There seems to be confusion about set & get functions - you a mixing the 2 together.
Can any one plz provide some example how to implement dynamic memory allocation for employee record above example and how do i delete record from multiple records and how do i use this deleted memory again to reallocate other value.
char[50] is an array of 50 chars - in other words a string that is 50 chars long. So just use string fname = ""; to declare instead. Then you would have an array of the strings (or use a <vector>)
The new operator returns a pointer, so fname & lname are pointers.
When the assignment asked for dynamic memory allocation, they meant for the employee objects, not for the member variables.
There you go, I have given some clues, change you code then post it again if you have any problems