944,137 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1255
  • C++ RSS
Jun 25th, 2005
0

urgent need help in this code

Expand Post »
I write a C++ program, which stores the information about of the company’s employees.
First I create a class named as Employee having following attributes.
1: id
2:name
3: sal
4: address
Take input of all the four attributes from the user using four different setter functions.
Class has following member functions.
1: display ()
2: checkmanger()
Member function display() will display all the records of employee using four different getter functions. Call all the four getter functions in this member function to display the records of employee.
Make a member function checkmanager() that will find out whether the employee is manager or not if he has salary greater than or equal to 15,000 then he will be considered as a manager and if his salary is less than 15,000 then he will be considered as programmer.
Where employee salary cannot be less than zero.
Write setters and getters for all the four data members to set and get values. Write also constructor for the class.
Also write destructor for the class Firm.
Sample Output
1)
Enter Employee id: 201
Enter Employee name: Akram
Enter Employee salary: 20000
Enter Employee address: Lahore
Employee id: 201
Employee name: Akram
Employee salary: 20000
Employee address: Lahore

The employee is manger.
2)
Enter Employee id: 402
Enter Employee name: Ali
Enter Employee salary: 10000
Enter Employee address: Lahore

Employee id: 402
Employee name: Ali
Employee salary: 10000
Employee address: Lahore

The employee is Programmer.

My program compiles but does not given required results. Please anybody checks, where is my mistake and corrects it. Or write this in a better way. I am new in c++ and not much concept of classes Thanks.

C++ Syntax (Toggle Plain Text)
  1. //Header Files
  2. #include<iostream.h>
  3. #include<conio.c>
  4.  
  5. //class definition
  6. class Employee{
  7. //hidden part of the class Employee
  8. private:
  9.  
  10. int id;
  11.  
  12. char name;
  13.  
  14. int sal;
  15.  
  16. char address;
  17.  
  18. public:
  19.  
  20. void setid(int);
  21. void setname(char);
  22. void setsal(int);
  23. void setaddress(char);
  24.  
  25. int getid();
  26. char getname();
  27. int getsal();
  28. char getaddress();
  29. //to input data
  30. void input();
  31. //to display data values
  32. void display();
  33.  
  34. void checkmanger();
  35.  
  36. int numberCheck(char temp[]);
  37.  
  38. Employee();
  39.  
  40. ~Employee();
  41.  
  42. };
  43.  
  44.  
  45. Employee::Employee()
  46. {
  47. id=0;
  48. name=0;
  49. sal=0;
  50. address=0;
  51. cout<<"\n \t \t constructor called"<<endl;
  52. cout<<"\t \t ===================== \n"<<endl;
  53. }
  54.  
  55.  
  56. Employee::~Employee()
  57. {
  58. cout<<"\t \t The object has been destroyed"<<endl;
  59. cout<<"\t \t ============================ \n"<<endl;
  60. getch();
  61. }
  62.  
  63.  
  64.  
  65. void Employee::display()
  66.  
  67. {
  68. input();
  69.  
  70. cout<<"\t===================================================="<<"\n"<<endl;
  71. cout<<"\t Employee id: "<<getid()<<"\n"<<endl;
  72. cout<<"\t Employee name: "<<getname()<<"\n"<<endl;
  73. cout<<"\t Employee salary: "<<getsal()<<"\n"<<endl;
  74. cout<<"\t Employee address: "<<getaddress()<<"\n"<<endl;
  75.  
  76. }
  77.  
  78.  
  79. void Employee::setid(int r)
  80. {
  81. id=r;
  82. }
  83.  
  84.  
  85. int Employee::getid()
  86. {
  87. return id;
  88. }
  89.  
  90. void Employee::setname(char n)
  91. {
  92. name=n;
  93. }
  94.  
  95. char Employee::getname()
  96. {
  97. return name;
  98. }
  99.  
  100. void Employee::setsal(int s)
  101. {
  102. sal=s;
  103. }
  104.  
  105. int Employee::getsal()
  106. {
  107. return sal;
  108. }
  109.  
  110. void Employee::setaddress(char a)
  111. {
  112. address=a;
  113. }
  114.  
  115.  
  116. char Employee::getaddress()
  117. {
  118. return address;
  119. }
  120.  
  121. void Employee::checkmanger()
  122. {
  123. int salary;
  124. if(salary<=0)
  125. cout<<"\t The employee is programmer"<<"\n"<<endl;
  126. else
  127. cout<<"\t The Employee managerer: "<<salary<<"\n"<<endl;
  128.  
  129. }
  130.  
  131. //main function
  132. void main()
  133. {
  134. // declaring object of the class Employee
  135. Employee Emp;
  136. //calling function display
  137. Emp.display();
  138. //calling function checkmanger
  139. Emp.checkmanger();
  140. }
<< moderator edit: added code tags: [code][/code] >>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shahid is offline Offline
13 posts
since May 2005
Jun 25th, 2005
0

Please some one help me in this code

I write a C++ program, which stores the information about of the company’s employees.
First I create a class named as Employee having following attributes.
1: id
2:name
3: sal
4: address
Take input of all the four attributes from the user using four different setter functions.
Class has following member functions.
1: display ()
2: checkmanger()
Member function display() will display all the records of employee using four different getter functions. Call all the four getter functions in this member function to display the records of employee.
Make a member function checkmanager() that will find out whether the employee is manager or not if he has salary greater than or equal to 15,000 then he will be considered as a manager and if his salary is less than 15,000 then he will be considered as programmer.
Where employee salary cannot be less than zero.
Write setters and getters for all the four data members to set and get values. Write also constructor for the class.
Also write destructor for the class Firm.
Sample Output
1)
Enter Employee id: 201
Enter Employee name: Akram
Enter Employee salary: 20000
Enter Employee address: Lahore
Employee id: 201
Employee name: Akram
Employee salary: 20000
Employee address: Lahore

The employee is manger.
2)
Enter Employee id: 402
Enter Employee name: Ali
Enter Employee salary: 10000
Enter Employee address: Lahore

Employee id: 402
Employee name: Ali
Employee salary: 10000
Employee address: Lahore

The employee is Programmer.

My program compiles but does not given required results. Please anybody checks, where is my mistake and corrects it. Or write this in a better way. I am new in c++ and not much concept of classes Thanks.

C++ Syntax (Toggle Plain Text)
  1. //Header Files
  2. #include<iostream.h>
  3. #include<conio.c>
  4.  
  5. //class definition
  6. class Employee{
  7. //hidden part of the class Employee
  8. private:
  9.  
  10. int id;
  11.  
  12. char name;
  13.  
  14. int sal;
  15.  
  16. char address;
  17.  
  18. public:
  19.  
  20. void setid(int);
  21. void setname(char);
  22. void setsal(int);
  23. void setaddress(char);
  24.  
  25. int getid();
  26. char getname();
  27. int getsal();
  28. char getaddress();
  29. //to input data
  30. void input();
  31. //to display data values
  32. void display();
  33.  
  34. void checkmanger();
  35.  
  36. int numberCheck(char temp[]);
  37.  
  38. Employee();
  39.  
  40. ~Employee();
  41.  
  42. };
  43.  
  44.  
  45. Employee::Employee()
  46. {
  47. id=0;
  48. name=0;
  49. sal=0;
  50. address=0;
  51. cout<<"\n \t \t constructor called"<<endl;
  52. cout<<"\t \t ===================== \n"<<endl;
  53. }
  54.  
  55.  
  56. Employee::~Employee()
  57. {
  58. cout<<"\t \t The object has been destroyed"<<endl;
  59. cout<<"\t \t ============================ \n"<<endl;
  60. getch();
  61. }
  62.  
  63.  
  64.  
  65. void Employee::display()
  66.  
  67. {
  68. input();
  69.  
  70. cout<<"\t===================================================="<<"\n"<<endl;
  71. cout<<"\t Employee id: "<<getid()<<"\n"<<endl;
  72. cout<<"\t Employee name: "<<getname()<<"\n"<<endl;
  73. cout<<"\t Employee salary: "<<getsal()<<"\n"<<endl;
  74. cout<<"\t Employee address: "<<getaddress()<<"\n"<<endl;
  75.  
  76. }
  77.  
  78.  
  79. void Employee::setid(int r)
  80. {
  81. id=r;
  82. }
  83.  
  84.  
  85. int Employee::getid()
  86. {
  87. return id;
  88. }
  89.  
  90. void Employee::setname(char n)
  91. {
  92. name=n;
  93. }
  94.  
  95. char Employee::getname()
  96. {
  97. return name;
  98. }
  99.  
  100. void Employee::setsal(int s)
  101. {
  102. sal=s;
  103. }
  104.  
  105. int Employee::getsal()
  106. {
  107. return sal;
  108. }
  109.  
  110. void Employee::setaddress(char a)
  111. {
  112. address=a;
  113. }
  114.  
  115.  
  116. char Employee::getaddress()
  117. {
  118. return address;
  119. }
  120.  
  121. void Employee::checkmanger()
  122. {
  123. int salary;
  124. if(salary<=0)
  125. cout<<"\t The employee is programmer"<<"\n"<<endl;
  126. else
  127. cout<<"\t The Employee managerer: "<<salary<<"\n"<<endl;
  128.  
  129. }
  130.  
  131. //main function
  132. void main()
  133. {
  134. // declaring object of the class Employee
  135. Employee Emp;
  136. //calling function display
  137. Emp.display();
  138. //calling function checkmanger
  139. Emp.checkmanger();
  140. }
<< moderator edit: added code tags: [code][/code] >>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shahid is offline Offline
13 posts
since May 2005
Jun 25th, 2005
0

Re: urgent need help in this code

Shahid,

Search for the word "Change" in the following code to see my changes. Also, I added a mock definition for the input function.

Take care,
Bruce





C++ Syntax (Toggle Plain Text)
  1. //Header Files
  2. #include<iostream.h>
  3. #include<conio.h> // Changed from conio.c
  4.  
  5. //class definition
  6. class Employee{
  7. //hidden part of the class Employee
  8. private:
  9.  
  10. int id;
  11.  
  12. char name;
  13.  
  14. int sal;
  15.  
  16. char address;
  17.  
  18. public:
  19.  
  20. void setid(int);
  21. void setname(char);
  22. void setsal(int);
  23. void setaddress(char);
  24.  
  25. int getid();
  26. char getname();
  27. int getsal();
  28. char getaddress();
  29. //to input data
  30. void input();
  31. //to display data values
  32. void display();
  33.  
  34. void checkmanger();
  35.  
  36. int numberCheck(char temp[]);
  37.  
  38. Employee();
  39.  
  40. ~Employee();
  41.  
  42. };
  43.  
  44.  
  45. Employee::Employee()
  46. {
  47. id=0;
  48. name=0;
  49. sal=0;
  50. address=0;
  51. cout<<"\n \t \t constructor called"<<endl;
  52. cout<<"\t \t ===================== \n"<<endl;
  53. }
  54.  
  55.  
  56. Employee::~Employee()
  57. {
  58. cout<<"\t \t The object has been destroyed"<<endl;
  59. cout<<"\t \t ============================ \n"<<endl;
  60. getch();
  61. }
  62.  
  63.  
  64.  
  65. void Employee::display()
  66.  
  67. {
  68. //input(); // Changed - omitted line because an input funtion is declared but not defined.
  69.  
  70. cout<<"\t===================================================="<<"\n"<<endl;
  71. cout<<"\t Employee id: "<<getid()<<"\n"<<endl;
  72. cout<<"\t Employee name: "<<getname()<<"\n"<<endl;
  73. cout<<"\t Employee salary: "<<getsal()<<"\n"<<endl;
  74. cout<<"\t Employee address: "<<getaddress()<<"\n"<<endl;
  75.  
  76. }
  77.  
  78.  
  79.  
  80. void Employee::input()
  81.  
  82. {
  83. //input(); // Changed - omitted line because an input funtion is declared but not defined.
  84.  
  85. //cout<<"\t===================================================="<<"\n"<<endl;
  86. setid(100);
  87. setname('G');
  88. setsal(25000);
  89. setaddress('M');
  90.  
  91. }
  92.  
  93.  
  94. void Employee::setid(int r)
  95. {
  96. id=r;
  97. }
  98.  
  99.  
  100. int Employee::getid()
  101. {
  102. return id;
  103. }
  104.  
  105. void Employee::setname(char n)
  106. {
  107. name=n;
  108. }
  109.  
  110. char Employee::getname()
  111. {
  112. return name;
  113. }
  114.  
  115. void Employee::setsal(int s)
  116. {
  117. sal=s;
  118. }
  119.  
  120. int Employee::getsal()
  121. {
  122. return sal;
  123. }
  124.  
  125. void Employee::setaddress(char a)
  126. {
  127. address=a;
  128. }
  129.  
  130.  
  131. char Employee::getaddress()
  132. {
  133. return address;
  134. }
  135.  
  136. void Employee::checkmanger()
  137. {
  138. //int salary; // Changed - omitted this line
  139. if(sal<=0) // Changed - salary to sal
  140. cout<<"\t The employee is programmer"<<"\n"<<endl;
  141. else
  142. cout<<"\t The Employee managerer: "<<sal<<"\n"<<endl; // Changed - salary to sal
  143.  
  144. }
  145.  
  146. //main function
  147. void main()
  148. {
  149. // declaring object of the class Employee
  150. Employee Emp;
  151. //calling function input
  152. Emp.input();
  153. //calling function display
  154. Emp.display();
  155. //calling function checkmanger
  156. Emp.checkmanger();
  157. }
<< moderator edit: added code tags: [code][/code] >>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
BruceWilson512 is offline Offline
19 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Few problems in char and pointers.
Next Thread in C++ Forum Timeline: C++ linked list help??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC