its a beginner problem. but its too big for me

i have some problem for my final exam on oop. i need a little help if you can. Thanks for your interest.


a)Desing a UML diagram of a class called Employee with id,name and departmant members.The class should have constructors,set,get,prit,info etc.
b)Code the class specified above.
c)Write a drive program to test the objects and the methods of the class.
d)Considering inheritance, redesing the class above such that two new classes of MonthlySalaried and WeeklySalaried can be derived. Use a new member called salary and related member functions for the derived classes.
e)For the above classes, only describe how to implement polymorphism.
These are questions that prospective employers will likely ask you someday, if you seek a career in programming. My advice: read a textbook about oop or at least try to google terms such as polymorphism and oop inheritance. You are going to need to learn this if you want to remember it later during an interview.
Last edited on
Well the first part is easy.

1
2
3
4
5
class Employee
{
  int id;
  string name, dept;
}

i need all code , if you can help, that will be awesome guys.
#include <iostream>
#include <string>
using namespace std;

class Employee
{
private:
int id;
char name[30];
char departmant [30];
public:
void openEmployee(int id1, char n1[], char d1[])
{id=id1;
strcpy(name,n1);
strcpy(departmant,d1);
}

void setId(int id1){id=id1;}
void setName(char *n1){strcpy(name,n1);}
void setDepartmant(char *d1){strcpy(departmant,d1);}
void print()
{
cout<<"id="<<id<<endl;
cout<<"name="<<name<<endl;
cout<<"departmant="<<departmant<<endl;
cout<<" "<<endl;
}
};
int main ()
{
Employee e1;
e1.openEmployee(1234,"Askin Selvi","Bilgisayar Muhendisi");
e1.print();
system("pause");
return 0;
}



1
2
char name[30];
char departmant [30];

use std::string rather than a char array. you have after all included the correct include file(<string>) for this.

Last edited on
Topic archived. No new replies allowed.