Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ul> <li>It looks like you need to do a lot of work to improve your code. First, you should put all your header files on Employee.h. This will be useful wherever you decide to include Employee.h, all of its header files will also be included, so you do not have to included them again. </li> <li>In C++ you can define your variables as pointers or reference. Please learn the difference between pointers (*pointer), double pointers <em>(</em>**doublepointer) also known as array pointer, reference (&amp;reference) and variables (variable). You should also learn about making a dereference to a pointer such as pointer (**pointer).</li> <li>Learn the deference between a class, a function or a variable <strong>Definition</strong> and its <strong>Declaration.</strong> This is important especially with your current assignment problem. </li> <li>You have an Employee class and if you are a starter; Header files are used for constructor, destructor, member variables and member functions definition. Whereas the .cpp files are used for constructor, member functions and non-member functions declaration. Most of the time a declaration for destructor does not include anything much, however this is where you delete pointers. </li> <li>In C++ you have to manage memory, otherwise you will have memory leaks with your pointers. So whenever you define a pointer (*pointer) you should delete it on your destructor. You are missing a destructor in your header file. You need to define one. </li> <li><p>You should define and/or declare the constructor in your header file like this. There is really no point of calling SetFirstName(), setLastName(), setSalary() in your constructor. These methods should be used only in the MAIN class. And to set class member variables, do this.</p> <pre><code>Employee( string FirstName, string LastName, float Salary ) this.FirstName = FirstName; this.LastName = LastName; this.Salary = Salary; </code></pre> <p>}</p></li> <li><p>Include a class destructor</p> <pre><code>~Employee(){ } </code></pre></li> <li><p>Your SET functions are meant to set member variables only and should not return anything. Instead of returning a string they should be void. Like this.</p></li> <li><p>Set functions definition.</p> <p>void setFirstName(string FirstName);<br> void setLastName(string LastName);<br> void setSalary(float Salary);</p></li> <li><p>Define and declare GET functions. </p> <p>string getFirstName() { return FirstName;}<br> string getLastName() { return LastName;}<br> float getSalary() { return Salary;} </p></li> <li><p>In your .cpp files you should declare your set functions among other member functions you have defined so far in your Employee class. Like this. </p> <p>void Employee::setFirstName(string FirstName){<br> FirstName = FirstName;<br> }<br> void Employee::setLastName(string LastName){<br> LastName = LastName;<br> }<br> void Employee::setSalary(float Salary){<br> Salary = Salary;<br> } </p></li> <li><p>This Readfile function reads a file of this format example; first line; John Garry 100.50, next line; Michael Shawn 250.80 etc. And stores it in a vector of Employees. </p> <p>typedef std::vector &lt; Employee > EmployeeType<br> EmployeeType account;</p> <p>void ReadFile(ifstream&amp; MyinFile, string FirstName, string LastName, float Salary) {<br> string st;<br> float n;</p> <p>while(MyinFile >> st) {<br> this.setFirstName(st);<br> this.setLastName(MyinFile >> st);<br> this.setSalary(MyinFile >> n);<br> account.push_back(this);<br> }</p></li> <li><p>Search employee function. It searches by the First Name only.</p></li> <li><p>You should also learn about arrays and array pointers in C++. </p> <p>string Employee::EmployeeSearch(string LastName, string FirstName) { </p> <p>cout &lt;&lt; "Please enter the name of the employee you would like to search." &lt;&lt; endl;<br> cin >> SearchName;<br> string st = "No Such Employee";<br> string s = " ";</p> <p>Employee *employ;</p> <p>for(int i = 0; i &lt; account.size(); i++){<br> employ = account.at(i);<br> if(SearchName == employ->getFirstName()){<br> std::cout &lt;&lt; employ->getFirstName() &lt;&lt; " " &lt;&lt; employ->getLastName() &lt;&lt; " " &lt;&lt; employ->getSalary() &lt;&lt; endl;<br> st = "";</p> <p>st.append(employ.getFirstName());<br> st.append(s);<br> st.append(employ.getLastName());<br> st.append(s); </p> <p>std::ostringstream ss;<br> ss &lt;&lt; employ.getSalary();<br> string so(ss.str());<br> st.append(so);<br> return st;<br> }<br> } return st;</p> <p>}</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload