Menu

Question: in c++creat a class with following characteristics Two private member variables name & designation of string type. Parameterized constructor which takes 2 parameters to initialized name & designation. Method solution with no input parameter and void return type. A method should print the member variable values in new lines. Input John Snow

  • in c++creat a class with following characteristics
    Two private member variables name & designation of string type.
    Parameterized constructor which takes 2 parameters to initialized name & designation.
    Method solution with no input parameter and void return type. A method should print the member variable values in new lines.
    Input
    John Snow
    Warrior
    where,
    First line represents a name.
    Second line represents a designation.
    Output
    John Snow
    Warrior
    #include
    #include
    #include
    using namespace std;
    int main ()
    {
    string name, designation;
    getline(cin, name);
    getline(cin, designation);
    }
  • Chegg Logo

    There are 2 steps to solve this one.

    Expert-verified
    100% (1 rating)
    Step 1

    Below is a C++ program that defines a class with the specified characteristics:

    #include <iostream>
    #include <string>

    using namespace std;

    class Employee {
    private:
    string name;
    string designation;

    public:
    // Parameterized constructor
    Employee(string empName, string empDesignation) {
    name = empName;
    designation = empDesignation;
    }

    // Method to print member variable values
    void displayDetails() {
    cout << name << endl;
    cout << designation << endl;
    }
    };

    int main() {
    // Input
    string name, designation;
    getline(cin, name);
    getline(cin, designation);

    // Create an instance of the Employee class
    Employee employee(name, designation);

    // Call the displayDetails method to print member variable values
    employee.displayDetails();

    return 0;
    }

    Explanation:

OR