Â
The Code given below can be used in TURBO C++ Compilers: -
#include<iostream.h>
#include<string.h>
#include<conio.h>
class Name
{
private:
char *name[50];
public:
void setname(char *s[50])
{
strcpy(name[50],s[50]);
}
void printname()
{
cout << "My Name is " << *name;
}
};
void main()
{
clrscr();
Name obj1;
char *a[50];
cin >> a[50];
obj1.setname(&a[50]);
obj1.printname();
getch();
}
//.......Coded by SAHIL SHAIKH
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
class Name
{
private:
string name;
public:
void setname(string s)
{
name = s;
}
void printname()
{
cout << "My Name is " << name;
}
};
int main()
{
Name obj1;
obj1.setname("Rohan");
obj1.printname();
return 0;
}
//.......Coded by SAHIL SHAIKH
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP