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
Post A Comment:
0 comments: