using arrays and functions

shyamalan's Avatar, Join Date: Jun 2010
Newbie Member
Code:
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
//#include<sstring.h>
class employee
{
 private:
  int empno;
  char name[20];
  void set_no(int);
  void set_name(char *);
 public:
  void set_emp_info();
  void display_info();
 };

 void employee::set_emp_info()
 {
  int n;
  char nam[20];
  cout<<"enter the name"<<endl;
  cin>>nam;
  cout<<"enter the no"<<endl;
  cin>>n;
  this->set_no(n);
  this->set_name(nam);
 }

 void employee::display_info()
 {
    cout<<this->name<<"with pointer"<<endl;
    cout<<this->empno<<"with pointer"<<endl;
    cout<<name<<"w/o pointer"<<endl;
    cout<<empno<<"w/o pointer"<<endl;
 }

 void employee::set_no(int n)
 {
  empno=n;
 }
 void employee::set_name(char *nam)
 {
  name = nam;
  cout<<nam<<endl<<"in set_name"<<endl;
 }


 void main()
 {
  clrscr();
  employee e;
  e.set_emp_info();
  e.display_info();
  getchar();
  return;
 }

i have two doubts....
1)one regarding the above program
The program is intended to just display the name and empno.I am not getting the output . Error is :Lvalue required error.(in the above bold code ).

2)Is there any substitute for getchar(),clrscr() in C++.(As i think they are not part of C++ code).

Last edited by shabbir; 12Jun2010 at 10:23.. Reason: Code blocks
0
jimblumberg's Avatar
Ambitious contributor
The problem is the line
Code:
 name = nam;
Check out strcpy() with cstrings.