9.3.21

Spring 2021 c++ : hw-3

C++ OOP to display name and age


You have to read name and age of a person and display them on the output screen. Here, you will learn how to read string (name) with spaces in C++ language?

Here, you have to  declare a string (character array) variable named name that will store name of the person and integer variable named age that will store the age of the person.

Use Constructor, Destructor and Method in C++

3 comments:

  1. #include
    using namespace std;
    class B
    {
    public:
    char name[10];
    int age;
    void person()
    {
    cout<<"Enter the name : ";
    cin.getline(name,10);
    cout<<"Enter age : ";
    cin>>age;
    cout<<"Name: "<<name<<endl;
    cout<<"Age: "<<age<<endl;
    }
    };
    int main()
    {
    B obj;
    obj.person();
    }

    ReplyDelete
  2. #include
    using namespace std;
    class B
    {
    public:
    char NAME[10];
    int AGE;
    void inp()
    {
    cout<<"ENTER NAME : ";

    cin>>NAME;

    cout<<"ENTER AGE : ";

    cin>>AGE;

    cout<<"NAME: "<<NAME<<endl;

    cout<<"AGE: "<<AGE<<endl;
    }
    };
    int main()
    {
    B obj;
    obj.inp();
    }

    ReplyDelete
  3. //Sumaiya Mariya
    //ID:201520785
    #include
    using namespace std;
    class B
    {
    public:
    char name[10];
    int age;
    void inp()
    {
    cout<<"ENTER name : ";

    cin>>name;

    cout<<"ENTER age : ";

    cin>>age;

    cout<<"name: "<<name<<endl;

    cout<<"age: "<<age<<endl;
    }
    };
    int main()
    {
    B obj;
    obj.inp();
    }

    ReplyDelete

Comment Here