We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>

Looking For Something at vustudents.ning.com? Click Here to Search

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More


Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion

How to Add New Discussion in Study Group ? Step By Step Guide Click Here.

Assignment No. 02
Semester: Spring 2015

CS304: Object Oriented Programming

Total Marks: 20

 

Due Date: 08/06/2015

 

Instructions:

 

Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:

 

  • The assignment is submitted after due date.
  • The submitted assignment does not open or file is corrupt.
  • Assignment is copied(partial or full) from any source (websites, forums, students, etc)

 

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Microsoft Word Document) or .txt files or .exe file, no reward will be given in any case.

 

 

Objective:

 

The objective of this assignment is to provide hands on experience of:

 

  • Classes and objects
  • Constructors and destructors
  • Setter and Getter functions
  • Static data member
  • Member initializer list
  • Copy constructor and deep copy

 

 

Guidelines:

 

  • Code should be properly indented and well commented.
  • Follow C/C++ guide lines while writing variable names, function names etc
  • Use only dev-C++ for this assignment.

 

 

 

For any query about the assignment, contact at cs304@vu.edu.pk

 

 

 

 ASSIGNMENT

Problem Statement:  

  

In this assignment you will be creating a class named Employee.

 

Employee class has the following data members:

  • Employee ID.
  • Employee Name
  • Department
  • Employee Salary
  • Static data member which will hold the value of total no. of employees

 

 

Employee class must have the following member functions:

 

Function

Description

Employee()

Default constructor for Employee class, which will set employee id  to 0, employee name to NULL, employee department to NULL and salary to 0.0

Employee(int, char *, char *, float);

It will take employee id, employee name, department and salary as arguments and initialize their values using member initializer list

Employee(Employee &); 

Copy constructor which will initialize one object with another object using deep copy

Setter functions

You have to define setter function for each data member which will take a value as an argument and set their values

Getter functions

You have to define getter function for each data member which will return the values of their data members

calcNetPay()

This function will calculate the net pay of an employee based on his salary

display()

This function will display the values of all data members of class

~Employee()

Destructor of Employee class which will decrement the value of static data member of class

 

 

calcNetPay():  This function will calculate net pay of an employee based on his salary as:

If salary is less than and equal to 10,000 then tax is 0.

If salary is greater than 10,000 and less than equal to 20,000 then tax is 5%.

If salary is greater than 20,000 and less than equal to 30,000 then tax is 7%.

The tax on the salary greater than 30,000 is 10%.

Note: On creation of each object, the value of static data member should be incremented.

 

 

 

 

 

Within main() function, create an array of 5 objects of class Employee. Second object should be initialized with the first object.

 

Now, use for loop to call calcNetPay() and display() functions for each object.

 

You can create objects as follow:

Employee emp1(5, "Ahmad", "Accounts", 20000 );

Employee emp2(emp1) ;

Employee emp3(10, "Ayesha", "Accounts", 25000);

Employee emp4(3, "Hassan", "Administration", 10000);

Employee emp5(6,  "Arsalan", "Administration", 35000);

 

Sample output of the program:

 

 

 

 

 

 

 

 

 

 

+ How to Follow the New Added Discussions at Your Mail Address?

+ How to Join Subject Study Groups & Get Helping Material?

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 7349

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

Replies to This Discussion

jb ki assignment details upload hui hain bht martaba p-rh chuki hu nai smjh ai to hi yaha comment kr k puchna chaha hai.

Basically i need this to be told me verbally.... aap bta do aapne bhi to prhi hai na 

 i've studied this assignment with my opened eyes.....

help meeeee in short.....

by the way leave it mene krli hai...

wese bhi jb tk yaha kisi ne help krni thi tb tk date hi nikal jani thi .......

es assignment me koi rocket science nahi he, just ye krne k bad ap ko class ki basic ka pta chal jay ga, like constructor, destructor, getter setter wagera ko use krna,

constructor use hoga objects on initilized krne k lie, then getter function se value de ge hum objects k data meber me or getter le utha len ge value, main me objects/ instances bnay ge...........

itna sunane k baad btane ki kya zaroorat thi pehle araam se to btaya nai gya aap se...

yeah.... you are right ye rocket science nai hai aap k liye but remember..... Sir, everyone consider something rocket science for himself/herself and this time this assignment was a rocket science in a way for me...

But thanks to someone who helped me to understand the phenomenon but still i'm also thankful to you for your precious time that you gave

Regards

Sayyeda Snober 

thanks  Double Diamond bhai

#include <iostream>
#include <string.h>
using namespace std;
class Employee
{
private:
int employeeID;
char* employeeName;
char* department;
float employeeSalary;
static int totalNoOfEmployees;
public:
Employee()
{
employeeID = 0;
employeeName = NULL;
department = NULL;
employeeSalary = 0.0;
}

Employee(int _employeeID, char const * _employeeName, char const * _department, float _employeeSalary): employeeID(0), employeeName(NULL), department(NULL), employeeSalary(0.0)
{
employeeID =_employeeID;
employeeName = new char[strlen(_employeeName)+1];
strcpy(employeeName,_employeeName);
department = new char[strlen(_department)+1];
strcpy(department,_department);
employeeSalary = _employeeSalary;
++totalNoOfEmployees;
}

Employee(Employee& emp)
{
employeeID = emp.employeeID;
employeeName = new char[strlen(emp.employeeName)+1];
strcpy(employeeName,emp.employeeName);
department = new char[strlen(emp.department)+1];
strcpy(department,emp.department);
employeeSalary = emp.employeeSalary;
++totalNoOfEmployees;
}

void setEmployeeID(int _employeeID)
{
if(_employeeID > 0)
{
employeeID = _employeeID;
}
}
int getEmployeeID()
{
return employeeID;
}

void setEmployeeName(char* _employeeName)
{
if (strlen(_employeeName) > 0)
{
employeeName = new char[strlen(_employeeName)];
strcpy(employeeName, _employeeName);
}
}
char* getEmployeeName()
{
return employeeName;
}

void setDepartment(char* _department)
{
if (strlen(_department) > 0)
{
department = new char[strlen(_department)];
strcpy(department, _department);
}
}
char* getDepartment()
{
return department;
}

void setEmployeeSalary(int _employeeSalary)
{
if(_employeeSalary > 0)
{
employeeSalary = _employeeSalary;
}
}
int getEmployeeSalary()
{
return employeeSalary;
}

float calcNetPay()
{
if (employeeSalary>=0 && employeeSalary<=10000)
{
employeeSalary = employeeSalary;
}
else if(employeeSalary>10000 && employeeSalary<=20000)
{
employeeSalary -= employeeSalary * (0.05);
}
else if(employeeSalary>20000 && employeeSalary<=30000)
{
employeeSalary -= employeeSalary * (0.07);
}
else if(employeeSalary>30000)
{
employeeSalary -= employeeSalary * (0.10);
}
}

void display()
{
coutgetEmployeeID()"\t"getEmployeeName()"\t\t"getDepartment()"\t"getEmployeeSalary()endl;
}

~Employee()
{
delete []employeeName;
delete []department;
--totalNoOfEmployees;
}
};
int Employee::totalNoOfEmployees=0;
main()
{
Employee employee[4];
Employee emp1(5, "Ahmad", "Accounts", 20000.0 );
Employee emp2(emp1) ;
Employee emp3(10, "Ayesha", "Accounts", 25000.0);
Employee emp4(3, "Hassan", "Administration", 10000.0);
Employee emp5(6, "Arsalan", "Administration", 35000.0);

employee[0] = emp1;
employee[1] = emp2;
employee[2] = emp3;
employee[3] = emp4;
employee[4] = emp5;

cout"ID""\t""EmloyeeName""\t""Department""\t""EmployeeSalary"endl;
for (int i = 0; i < 5; i++)
{
employee[i].calcNetPay();
employee[i].display();
}
}

you used the member initializer list but you passed default values to list instead of argument's value. then you pass the argument value to data member inside the constructor.

but the requirement is:

Employee(int, char *, char *, float);
It will take employee id, employee name, department and salary as arguments and initialize their values using member initializer list

#include
#include
#include
using namespace std;
class Employee
{
private:
int employeeID;
char *employeeName;
char *department;
float employeeSalary;
static int NoOfEmployees;
public:
Employee() {
employeeID = 0;
employeeName = "";
department = "";
employeeSalary = 0.0; }
Employee(int empId, char *empName, char *depot, float empSalary) {
employeeID = empId;
employeeName = new char[strlen(empName)+1];
strcpy(employeeName,empName);
department = new char[strlen(depot)+1];
strcpy(department, depot);
employeeSalary = empSalary;
NoOfEmployees++; }
void setEmpID(int empId) {
employeeID = empId; }
int getEmpID() {
return employeeID; }
void setEmpName(int empId) {
employeeID = empId; }
char *getEmpName() {
return employeeName; }
void setDepot(char *depot) {
department = depot; }
char *getDepot() {
return department; }
void setEmpSalary(int empSalary) {
employeeSalary = empSalary; }
float getEmpSalary() {
return employeeSalary; }
float calcNetPay() {
if ( employeeSalary >= 0 && employeeSalary <= 10000 ) { employeeSalary = employeeSalary; } else if ( employeeSalary > 10000 && employeeSalary <= 20000) { employeeSalary = employeeSalary - (0.05 * employeeSalary); } else if ( employeeSalary > 20000 && employeeSalary <= 30000) { employeeSalary = employeeSalary - (0.07 * employeeSalary); } else { employeeSalary = employeeSalary - (0.1 * employeeSalary); } } void print() { cout getEmpID() "\t" /p>

Attachments:

you guys are not using member initializer list.
See this
Employee(int, char *, char *, float);
It will take employee id, employee name, department and salary as arguments and initialize their values using member initializer list

remove operator after return statement.

it should be return employeeSalary;

program is correct check cpp file too

RSS

Latest Activity

Aisha RD left a comment for M_Asim
5 minutes ago
zuha shah joined + M.Tariq Malik's group
17 minutes ago
+ ! ❤️ ░S░I░N░G░E░R replied to + ! ! ! ! ! ! ! ! ! ! ! ! ! ! !'s discussion 100 Instructions from the Quran
20 minutes ago
+ ! ❤️ ░S░I░N░G░E░R liked + ! ! ! ! ! ! ! ! ! ! ! ! ! ! !'s discussion 100 Instructions from the Quran
20 minutes ago
+ ! ❤️ ░S░I░N░G░E░R liked + !! "AS" !!'s discussion Jis Tarah ..
21 minutes ago
+ ! ❤️ ░S░I░N░G░E░R liked + !! "AS" !!'s discussion Baat Karna ...
21 minutes ago
+ ! ❤️ ░S░I░N░G░E░R liked + !! "AS" !!'s discussion Yaha Har Cheez ..
21 minutes ago
+ ! ❤️ ░S░I░N░G░E░R liked + !! "AS" !!'s discussion Alfaaz Ki Nisbat..
21 minutes ago
+ ! ❤️ ░S░I░N░G░E░R liked ٥ دن's discussion Gunahon ki gehrai
22 minutes ago
+ ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! replied to + "αяsαℓ " Ќąƶµяɨ •"'s discussion Happy Marriage to "Zee" & " Nomi weds Noor"....!
31 minutes ago
Qaisar nadeem replied to + M.Tariq Malik's discussion ENG201 Business and Technical English Writing Assignment No 01 Fall 2019 Solution & Discussion in the group ENG201 Business and Technical English Writing
32 minutes ago
Profile IconQaisar nadeem and Isha Chuhdary joined + M.Tariq Malik's group
32 minutes ago
+ ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! posted a discussion
44 minutes ago
+ !! "AS" !! replied to + !! "AS" !!'s discussion Jis Tarah ..
58 minutes ago
+ !! "AS" !! replied to + !! "AS" !!'s discussion Baat Karna ...
59 minutes ago
+ !! "AS" !! replied to + !! "AS" !!'s discussion Ghalti...
1 hour ago
+ !! "AS" !! replied to + !! "AS" !!'s discussion Yaha Har Cheez ..
1 hour ago
+ !! "AS" !! replied to + !! "AS" !!'s discussion Alfaaz Ki Nisbat..
1 hour ago
Profile IconSafdar Mehmood, Shayaan, Hafiz muhammad sufyan and 28 more joined Virtual University of Pakistan
1 hour ago
+ ! ! ! ! ! ! ReBeL replied to ٥ دن's discussion Gunahon ki gehrai
1 hour ago

© 2019   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service