Write a simple C++ program to display the name and number of a person.




Program Algorithm:
Step 1: Include the header files
Step 2: Declare the class as person with data members name and number
Step 3: Create an object for the class person
Step 4: Get the name and number as input
Step 5: Access the data member using object and display the output.




Program Code in C++:
#include <iostream.h>
#include<conio.h>
using namespace std;
class person
{
public:
string name;
int number;
};
int main()
{
person obj;
cout<<"Enter the Name :";
cin>>obj.name;
cout<<"Enter the Number :";
cin>>obj.number;
cout << obj.name << ": " << obj.number << endl;
getch();
return 0;
}




Program Output:
Enter the Name: Mukesh
Enter the Number: 500
Mukesh: 500
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: