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 characteristicsTwo 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.InputJohn SnowWarriorwhere,First line represents a name.Second line represents a designation.OutputJohn SnowWarrior#include#include#includeusing namespace std;int main (){string name, designation;getline(cin, name);getline(cin, designation);}
-
There are 2 steps to solve this one.Expert-verified100% (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