AIM:
To implement a simple C++ program to display the name and number
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:
#include <iostream.h>
#include<conio.h>
using namespace std;
class person
{
public:
string name;
int number;
void accept()
{
cin>>name>>number;
}
void display()
{
cout>>name>>number;
}
};
int main()
{
person obj;
obj.accept();
obj.display();
getch();
return 0;
}
SAMPLE OUTPUT:
Enter the Name: SAHANA
Enter the Number: 100
SAHANA: 100
RESULT:
Thus the simple C++ program to display the name and number is implemented successfully.
No comments:
Post a Comment