Design and Develop Classes Scenarios 1) Class name is Employee has the attribute
ID: 3919797 • Letter: D
Question
Design and Develop Classes Scenarios
1) Class name is Employee has the attributes: empID (an integer), first name (a string), last name (a string), hourly pay rate (a decimal), hours worked (a list of seven decimals). The methods should include: a constructor that sets all of the attributes to either 0 or empty string “”, a set function for each attribute, a setAll function that assigns arguments each attribute, a get function for each attribute, a totalHours function that returns the total number of hours worked, a weeklyPay function that returns the total pay for the week.
Create a class diagram
Create the class specification/interface – Define class in C++
Create a class implementation – Define methods in C++
Constructor sets all of the attributes to either 0 or empty string “”
A set function for each attribute
A get function for each attribute that returns the value of the attribute
A totalHours function that returns the total number of hours worked
A weeklyPay function that returns the total pay for the week
Hours past 40 pay at 1.5 times the hourly rate
Add the class interface and implementation to a test driver – Define main driver in C++
Class name is Student has the attributes: studentID (an integer), first name (a string), last name (a string), scores (a list of integers). The methods should include a constructor that accepts and sets the studentID, firstName, lastName, and number of scores, a set function for each attribute, a get function for each attribute, an average function that returns the mean average of the list of scores.
Create a class diagram
Create the class specification/interface
Create a class implementation
Constructor sets all of the attributes to either 0 or empty string “”
A set function for each attribute
The set function for the scores should accept a test position (whichTest) and score value.
A get function for each attribute that returns the value of the attribute
An average function that returns the mean average of the list of scores
Add the class interface and implementation to a test driver
3) Class name is Fraction has the attributes: numerator (an integer) and denominator (an integer). The methods should include a default constructor with default values of 1 for each attribute, a set function for each attribute, a setAll function that sets values for both attributes, a get function for each attribute, a decimalValue function that returns the quotient as a decimal, a ratioValue that returns the ratio (example: 3/7).
Create a class diagram
Create the class specification/interface
Create a class implementation
Constructor sets all of the attributes to 0
A set function for each attribute
The set function for denominator must validate parameter because it can not be 0. If 0, then set denominator to 1
A setAll function that accepts two integer and assigns them to the attributes
A get function for each attribute that returns the value of the attribute
A decimalValue function that returns the quotient as a decimal
A ratio function that returns the reduced ratio of numerator/denominator
Suppose the ratio is 6/14, the function will return the reduced equivalent of 3/7 as a string
Need to use a greatest common divisor algorithm
Add the class interface and implementation to a test driver
4) Class name is StudentModel has the attributes: a list of Student objects, size of the Student list (an integer), active status (a Boolean). The methods should include a constructor that loads the student data into the Student list from a data file, an add function that adds a student to the end of the list, a remove function that sets active status to false, a findPosition function that accepts a position in the list and returns a student’s first and last name at that given position (0 to list size minus 1), a findName function that accepts a last name and displays the full name and list position all of the students with the last name, a listSize function that returns the size of the list, a sort function that organizes the list by either student last name or average score.
Create a class diagram
Create the class specification/interface
Create a class implementation
Constructor loads the Student list from a data file
An add function that adds a student to the end of the list
A remove function that accepts student last name, calls the findName function and prompts the user to select position from the list, then sets active status to false if and only if the student name is found.
A findPosition function that accepts a position in the list and returns a student’s first and last name at that given position (0 to list size minus 1
A findName function that accepts a last name and displays the full name and list position all of the students with the last name
A listSize function that returns the size of the list,
A sort function that organizes the list by either student last name or average score.
Add the class interface and implementation to a test driver
Class Diagram - Employee
Employee
-empID: integer
-firstName: string
-lastName: string
-hourlyPayRate: decimal
-hoursWorked[7]: decimal
+setID(id: integer): void
+setFirst(f: string): void
+setLast(l: string): void
+setRate(r: decimal): void
+setHours(weekdayNumber: integer): void
+setAll(id:integer, f:string, l:string, r:decimal): void
+getID() constant: integer
+getFirst() constant: string
+getLast() constant: string
+getRate() constant: decimal
+getHours() constant: decimal
+totalHours() constant: decimal
+weeklyPay(): decimal
Employee(): constructor
Class Diagram – Student
Class Diagram – Fraction
Class Diagram – Student Model
Class Diagram - Employee
Employee
-empID: integer
-firstName: string
-lastName: string
-hourlyPayRate: decimal
-hoursWorked[7]: decimal
+setID(id: integer): void
+setFirst(f: string): void
+setLast(l: string): void
+setRate(r: decimal): void
+setHours(weekdayNumber: integer): void
+setAll(id:integer, f:string, l:string, r:decimal): void
+getID() constant: integer
+getFirst() constant: string
+getLast() constant: string
+getRate() constant: decimal
+getHours() constant: decimal
+totalHours() constant: decimal
+weeklyPay(): decimal
Employee(): constructor
Explanation / Answer
1)
//Employee.h
#pragma once
#include<iostream>
#include<string>
using namespace std;
class Employee
{
int empID;
string firstName;
string lastName;
double payRate;
double hoursWorked;
public:
Employee();
void set_empID(int id);
void set_firstName(string name);
void set_lastName(string name);
void set_payRate(double rate);
void set_hoursWorked(double hours);
void setAll(int id, string fname, string lname, double rate, double hours);
int get_empID();
string get_firstName();
string get_lastName();
double get_payRate();
double totalHours();
double weeklyPay();
};
---------------------------------------------------------
//Employee.cpp
#include"Jul_27_Emp.h"
Employee::Employee()
{
empID = 0;
firstName = "";
lastName = "";
payRate = 0;
hoursWorked = 0;
}
void Employee::set_empID(int id)
{
empID = id;
}
void Employee::set_firstName(string name)
{
firstName = name;
}
void Employee::set_lastName(string name)
{
lastName = name;
}
void Employee::set_payRate(double rate)
{
payRate = rate;
}
void Employee::set_hoursWorked(double hours)
{
hoursWorked = hours;
}
void Employee::setAll(int id, string fname, string lname, double rate, double hours)
{
empID = id;
firstName = fname;
lastName = lname;
payRate = rate;
hoursWorked = hours;
}
int Employee::get_empID()
{
return empID;
}
string Employee::get_firstName()
{
return firstName;
}
string Employee::get_lastName()
{
return lastName;
}
double Employee::get_payRate()
{
return payRate;
}
double Employee::totalHours()
{
return hoursWorked * 5; //hours worked per day * 5 days of work in a week
}
double Employee::weeklyPay()
{
return payRate * totalHours();
}
---------------------------------------------------------------------------------------------------
//main.cpp
#include"Jul_27_Emp.h"
int main()
{
Employee emp,emp1;
emp.setAll(1234, "John", "Ronald", 20.56, 8);
//test all the indivual set functions
emp1.set_empID(1243);
emp1.set_firstName("Mary");
emp1.set_lastName("Smith");
emp1.set_payRate(24.89);
emp1.set_hoursWorked(8.5);
//now print the info onto screen
cout << "EmpID: " << emp.get_empID() << ", First Name: " << emp.get_firstName() << " ,Last Name: " << emp.get_lastName() << " ,Hourly Rate: " << emp.get_payRate() << ", Total hour worked: " << emp.totalHours() << " , Weekly pay: $" << emp.weeklyPay() << endl;
cout << "EmpID: " << emp1.get_empID() << ", First Name: " << emp1.get_firstName() << " ,Last Name: " << emp1.get_lastName() << " ,Hourly Rate: " << emp1.get_payRate() << ", Total hour worked: " << emp1.totalHours() << " , Weekly pay: $" << emp1.weeklyPay() << endl;
}
/*output
EmpID: 1234, First Name: John ,Last Name: Ronald ,Hourly Rate: 20.56, Total hour worked: 40 , Weekly pay: $822.4
EmpID: 1243, First Name: Mary ,Last Name: Smith ,Hourly Rate: 24.89, Total hour worked: 42.5 , Weekly pay: $1057.83
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.