Thread: PLease Help with Class Implementation

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    44

    Lightbulb PLease Help with Class Implementation

    hey guys,

    I'm stuck with my final project and I would like a little help
    This project is based on class implementation so here's the class that the teacher gave us

    Code:
    #ifndef ENGINEER_H
    #define ENGINEER_H
    
    //engineer class definition
    #include<fstream>
    #include<string>
    
    using namespace std;
    
    class Engineer
    {
    	private:
    	string fName, lName, degree, hireDate;
    	double salary;
    
    	public:
    	//constructor
    	Engineer( string = "", string = "", string = "", string = "", double = 0.0 );
    
    	//accessor functions
    	string FName();
    	string LName();
    	string Degree();
    	string HireDate();
    	double Salary();
    
    	//modifier functions
    	void setFName( string );
    	void setLName( string );
    	void setDegree( string );
    	void setHireDate( string );
    	void setSalary( double );
    	
    	//input functions
    	void getFName( istream& );
    	void getLName( istream& );
    	void getDegree( istream& );
    	void getHireDate( istream& );
    	void getSalary( istream& );
    	
    	//output functions
    	void putFName( ostream& );
    	void putLName( ostream& );
    	void putDegree( ostream& );
    	void putHireDate( ostream& );
    	void putSalary( ostream& );
    };
    
    #endif
    How could I start my implementation file What I need to do is ask the user for the first name, last, degree, hired date, and salary!
    Could you guys just give me some advice thank you

  2. #2
    Registered User stuart_cpp's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    31
    Havn't you learnt about outputs yet?!?
    Code:
    cout << "First Name" << endl;
    cin >> firstname;
    cout << "Last Name" << endl;
    cin >> lastname;
    cout << "Degree" << endl;
    cin >> degree;
    cout << "Hired Date" << endl;
    cin >> hireddate;
    cout << "Salary" << endl;
    cin >> salary;

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    of course I have I'm just stock creating the implementation file which contains all the class definitions but thanks anyway

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Number one... we don't do homework here. So unless you're going to be more specific than "How do I start this", no one's going to be willing to help you. You also might want to read the sticky in the forum dealing with the homework policy.

    Don't reply "Of course I have" to stuart's reply because you didn't give us any reason to believe you knew standard input... after all, you did ask how to get data from the user.

    What you want to do is create a .cpp file, include this library, and just start your method definitions. Take it one at a time.
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    I'm sorry I didn't mean to offend anyone this is just frustrated because I can't figure it out.
    Have a good day guys.

  6. #6
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    I will not write the code for you, but basicly, to use a function within a class like
    SlyMaelstrom said in your ,cpp class inpelent file, you would do somthing like this

    Code:
    #include "dummyClass.h"   // use the class header file
    
    constructor ( // goes here );
    
    void dummyClass::setSalary ( double )
    {
      // all code regarding this function goes here
    }
    in main, call the functions of the class, remember to add the class header file to main, and act on the code in the functiions. It really is that simple, you may want to read a little more into it, I have given you the basic idea - pete

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    if a constructor is define like this in the class
    Engineer( string = "", string = "", string = "", string = "", double = 0.0 );
    How could I initialize all the data members if they are already inizialize? for example in this program
    Code:
    unitvector::unitvector(): x(1), y(1), or(0)
    {
    }

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    if I want to initialize the elements in private could I do this
    Code:
    Engineer::Engineer(): fName(""), lName(""), degree(""), hireDate(""), salary(0.0)
    {
    }

  9. #9
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    I think you can still change the string. Just copy the string from users' input into the private members using the input functions in the class. Same thing with outputting. It's not that hard though. Good luck
    Hello, testing testing. Everthing is running perfectly...for now

  10. #10
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    thank you I'm going to try

  11. #11
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Dilmerv
    if I want to initialize the elements in private could I do this
    Code:
    Engineer::Engineer(): fName(""), lName(""), degree(""), hireDate(""), salary(0.0)
    {
    }
    That would be a default constructor. But to declare that one would be an error because there is already another constructor in your class that takes 5 parameters all of them with default values and that one could be called without parameters too.
    Kurt

  12. #12
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    I'm doing something like this
    Code:
    Engineer r();
    
    	cout <<"Enter First name" << endl;
    	cin >> firstname;
    	r.getFName(cin);
    It is giving me a compile error
    the class implementation look like this
    Code:
    void Engineer::getFName( istream &input)
    {
    	input >> fName;
    }

  13. #13
    Registered User
    Join Date
    Feb 2006
    Posts
    44
    The second line does not applycout cin >> firstname;

    cout <<"Enter First name" << endl;
    r.getFName(cin);

  14. #14
    Computer guy
    Join Date
    Sep 2005
    Location
    I'm lost!!!
    Posts
    200
    why don't you use strcpy() to copy the string into the fName, instead using the istream.
    Hello, testing testing. Everthing is running perfectly...for now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Default class template problem
    By Elysia in forum C++ Programming
    Replies: 5
    Last Post: 07-11-2008, 08:44 AM
  2. class schema implementation doubt
    By newbie007 in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2008, 04:42 PM
  3. Implementation of set class in C++
    By hay_man in forum C++ Programming
    Replies: 10
    Last Post: 09-21-2006, 03:33 PM
  4. Replies: 3
    Last Post: 10-31-2005, 12:05 PM
  5. Hide class implementation from driver?
    By wbeasl in forum C++ Programming
    Replies: 5
    Last Post: 09-13-2004, 05:38 PM