Learn Object Oriented Programming (OOP) in C++ / সি++ Here
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.
#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(); }
#include
ReplyDeleteusing 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();
}
#include
ReplyDeleteusing 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();
}
//Sumaiya Mariya
ReplyDelete//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();
}