Answer:
Following are the program in the C++ Programming Language:
#include <iostream> //header file
using namespace std; //namespace
class Students //define class
{public: //access modifier
int id,a ; //set variables
string courseStudentsname; //set variables
Students() //set constructor
{
courseStudentsname="Smith"; //initialize the value
a=20; //initialize the value
id=9999; //initialize the value
cout<<endl;
}
void PrintAll() //define function
{
cout << "Name: " <<courseStudentsname<<endl; //print output
cout << "Age: " << a<<endl; //print output
cout << "ID: " << id; //print output
}
};
int main() //define main function
{
Students obj; //set object and call constructor
obj.PrintAll(); // call function through object
return 0;
}
<u></u>
<u>Output</u>:
Name: smith
Age: 20
ID: 9999
Explanation:
Here, we define class "Students" inside it.
- we define two integer type variable "a" for age of the students and "id" for the id of the students and then we set a string type variable "courseStudentsname" for name of the students.
- we set the constructor in which we assign the value to the variables.
- we set the function 'PrintAll()' in which we print all the variables.
Finally, we define the "main()" Function in which we create the object of the class "obj" and call the the "PrintAll()" through the object of the class.