Question

Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...

Write a code in C++ by considering the following conditions :-

Tasks :-

1. Create a class Employee (with member variables: char * name, int id, and double age).
2. Create a constructor that should be able to take arguments and initialize the member
variables.
3. Create a copy constructor for employee class to ensure deep copy.
4. Create a destructor and de allocate the dynamic memory.
5. Overload the assignment operator to prevent shallow copy and ensure deep copy.
6. Overload the stream insertion operator << to print the values of member variables.
7. Use of constant reference parameters is mandatory
8. Test the functionality of class in main function.
Note : Use of this pointer is mandatory where required. You are not allowed to use any cin and cout
in implementation of functions except in task 6.

USE strcpy_s instead of strcpy because the second one is not working in my case.

-> The class definition for the code is probably as under. Please follow the desired pattern :-

class Employee
{
private:
int id = 0;
double age = 0;
char* name;
public:
Employee(char * name, int id, double age); // This is constructor.
Employee(const Employee&); // This is Overloaded constructor.
~Employee(); // This is Destructor.
// Overload assignment operator here.
// Overload " << " here to print Employee.
};

*** Apply all proper Testing cases or Checks in each case.

Test the destructor also. All the tests must be present in the main.

Thanks in Advance.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream.h>

struct Employee
{
int Id;
char Name[25];
int Age;
long Salary;
};

void main()
{

Employee E; //Statement 1

cout << "\nEnter Employee Id : ";
cin >> E.Id;

cout << "\nEnter Employee Name : ";
cin >> E.Name;

cout << "\nEnter Employee Age : ";
cin >> E.Age;

cout << "\nEnter Employee Salary : ";
cin >> E.Salary;

cout << "\n\nEmployee Id : " << E.Id;
cout << "\nEmployee Name : " << E.Name;
cout << "\nEmployee Age : " << E.Age;
cout << "\nEmployee Salary : " << E.Salary;


}

Output :

Enter Employee Id : 1
Enter Employee Name : Kumar
Enter Employee Age : 29
Enter Employee Salary : 45000

Employee Id : 1
Employee Name : Kumar
Employee Age : 29
Employee Salary : 45000

Add a comment
Know the answer?
Add Answer to:
Write a code in C++ by considering the following conditions :- Tasks :- 1. Create a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • c++ please need help with this question Consider a class Employee with data members: age(an integer),...

    c++ please need help with this question Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee {        private:             int age;             int id;             float salary;        public:             Employee( ); // default constructor: age=0, id=0, and salary=0             Employee(Employee &x);   // copy constructor           Employee& operator = (Employee &x); // equal sign operator             void setAge(int x);    // let age = x...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • Write a program

    1. Write a program which have a class named as “Student”, while the data members of the class are,a. char name[10],b. int age;c. string color;d. string gender;e. double cgpa;and the member function “print()”,  is just to display these information.1. You need to create 3 objects of the “Student” class.2. Initialize one object by the default constructor having some static values.3. Initialize the second object by the parameterized constructor, while you need to pass values for initialization.4. Initialize the third object...

  • Write a MyString class that stores a (null-terminated) char* and a length and implements all of...

    Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator: prints "Move assignment" and endl in addition...

  • I want the full code for this part and Its needs to be done in C++...

    I want the full code for this part and Its needs to be done in C++ Use a linked list to implement the following skeleton of an unsorted list typedef int ItemType: struct NodeType ItemType item; NodeType "next; class List List(); // default constructor List( const List &x); I copy constructor: deep copy is required List & operator = (const List &x); // assignment operator: deep copy. 1s required bool IsThere(ItemType x); identify if x is in the list void...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

  • C++ Write a MyString class that stores a (null-terminated) char* and a length and implements all...

    C++ Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Submit your completed source (.cpp) file. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator:...

  • C++ program to implement inheritance with following requirements, Classes :- Animal.cpp, bird.cpp, canine.cpp, main.cpp (to test...

    C++ program to implement inheritance with following requirements, Classes :- Animal.cpp, bird.cpp, canine.cpp, main.cpp (to test it) :- -You may need getters and setters also. 1. Declare and define an animal base class: animal stores an age (int), a unique long ID (a boolean that is true if it is alive, and a location (a pair of double). animal requires a default constructor and a 3 parameter constructor. Both constructors should set the unique ID automatically. They should also set...

  • Create a c++ code and answer number 1 Homework Ch. 13 - Employee Class 30 points...

    Create a c++ code and answer number 1 Homework Ch. 13 - Employee Class 30 points Design a class named Employee that has the following attributes: * Name ID Number- (Employee's] Identification Number " Department-the name of the department where the employee works " Position-the employee's job title The class should have the following constructors: A constructor that accepts values for all the member data as arguments A constructor that accepts the following values as arguments and assigns them to...

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT