Answer to Question #198859 in C++ for Ali raza

Question #198859

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.



1
Expert's answer
2021-05-26T06:23:51-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog