Topic List |
Page List:
1 |
---|---|
LookANinja 02/12/18 11:20:21 PM #1: |
Write a program that
- defines a class Employee with the following data members: - Name - Address - Title - Salary - Age - Department - defines a function that displays the information stored in an Employee object using the following format on 2 lines on the screen - Name (left,25), Address (left,25), Age (right,5) - Title (left,25), Department (left,25), Salary (right,10) - in main() - instantiate an object of type Employee - prompt the user for the information above (in the above order) and store it in the data members of the object instantiated - call the function to display the Employee information #include<iostream> #include<string> #include<iomanip> using namespace std; class Employee { public: string name; string address; string title; double salary; int age; string department; }; void DisInfo(Employee& emp1) { cout<<emp1.name<<emp1.address<<emp1.age<<endl; cout<<emp1.title<<emp1.department<<emp1.salary<<endl; } int main() { Employee emp1; cout<<"Please enter employee name"; getline(cin,emp1.name); cout<<"Please enter employee address"; getline(cin,emp1.address); cout<<"Please enter employee title"; getline(cin,emp1.title); cout<<"Please enter employee salary"; cin>>emp1.salary; cout<<"Please enter employee age"; cin>>emp1.age; cout<<"Please enter employee department"; getline(cin,emp1.department); void DisInfo(Employee& EmpInfo); } I think i'm close. (i know i gotta set the justification and stuff, but thats easy) --- ... Copied to Clipboard!
|
Johnny_Nutcase 02/12/18 11:21:54 PM #2: |
I took this same class 4 years ago. Looks familiar. Can't help because it went bye bye fast.
--- I've learned that life is one crushing defeat after another... until you just wish Flanders was dead. - Homer Simpson ... Copied to Clipboard!
|
LookANinja 02/12/18 11:42:01 PM #3: |
I think i need a constructor? Is that my issue?
Main is working fine, but my function isn't displaying my entered values. --- ... Copied to Clipboard!
|
Atralis 02/13/18 12:05:47 AM #4: |
You should quit now if this is hard for you. Just being honest.
... Copied to Clipboard!
|
Johnny_Nutcase 02/13/18 12:08:46 AM #5: |
Atralis posted...
You should quit now if this is hard for you. Just being honest. What a dickhead thing to say to someone. He is in the process of LEARNING it. You're one of those neckbeards that understands C++ in a week but doesn't know how to drive a car after 20 years. Just being honest. --- I've learned that life is one crushing defeat after another... until you just wish Flanders was dead. - Homer Simpson ... Copied to Clipboard!
|
ThanksUglyGod 02/13/18 12:11:52 AM #7: |
LookANinja posted...
int main() Get rid of the "void" in main ... Copied to Clipboard!
|
kirbymuncher 02/13/18 12:30:36 AM #8: |
yeah, having void in front of it is declaring the function, not calling it
also why getline sometimes and cin>> other times? --- THIS IS WHAT I HATE A BOUT EVREY WEBSITE!! THERES SO MUCH PEOPLE READING AND POSTING STUIPED STUFF ... Copied to Clipboard!
|
LookANinja 02/13/18 11:31:30 AM #9: |
kirbymuncher posted...
yeah, having void in front of it is declaring the function, not calling it Idk I just thought i had to do with strings. Anyway I was able to get it last night. I'll post the code later. My C++ topics keep getting purged. --- ... Copied to Clipboard!
|
mario2000 02/13/18 11:33:52 AM #10: |
I know the basics of C++ but a lot of the shit involved with it like pointers and stuff flew over my head.
More power to you if you can get good with those things. --- Arrrr the SS Goku, Mighty fine boat... -fatmatt Hope Frieza doesn't chuck an Iceberg at the Goku, otherwise it's all over. -Nekoslash ... Copied to Clipboard!
|
EnragedSlith 02/13/18 11:39:27 AM #11: |
LookANinja posted...
I think i need a constructor? Is that my issue? Classes have a default constructor. You need to create an object when you use one, though. Assigning a name isnt the same thing. Employee emp1 = new Employee(); or something to that effect, its been a while since Ive coded in c++ and I dont remember the syntax on hand Need to put exception handling in there, though --- ... Copied to Clipboard!
|
Topic List |
Page List:
1 |