Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   using arrays and functions (http://www.go4expert.com/forums/using-arrays-functions-t22385/)

shyamalan 11Jun2010 20:58

using arrays and functions
 
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).

jimblumberg 12Jun2010 02:06

Re: using arrays and functions
 
The problem is the line
Code:

name = nam;
Check out strcpy() with cstrings.


All times are GMT +5.5. The time now is 23:39.