Write a C++ program that has a class named as Human and has related attributes like(Name,Age,Gender,nationality); Assign default values to them using constructor and display on console.
#include <iostream>
#include <string>
using namespace std;
class Human{
string name, nationality;
char gender;
int age;
public:
Human(): name("John"), nationality("German"), gender('M'), age(25){}
void display(){
cout<<"Name: "<<name<<endl;
cout<<"Nationality: "<<nationality<<endl;
cout<<"Gender: "<<gender<<endl;
cout<<"Age: "<<age<<endl;
}
};
int main(){
Human person;
person.display();
return 0;
}
Comments
Leave a comment