1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

using arrays and functions

Discussion in 'C++' started by shyamalan, Jun 11, 2010.

  1. shyamalan

    shyamalan New Member

    Joined:
    Jun 11, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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);
    [B]  void set_name(char *);[/B]
     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);
     [B] this->set_name(nam);[/B]
     }
    
     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;
     }
     [B]void employee::set_name(char *nam)
     {
      name = nam;
      cout<<nam<<endl<<"in set_name"<<endl;[/B]
     }
    
    
     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 a moderator: Jun 12, 2010
  2. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    The problem is the line
    Code:
     name = nam; 
    Check out strcpy() with cstrings.
     

Share This Page