Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE I NEED HELP WITH THIS I NEED THE CODE FOR Department.cpp, Department.h Part 1 - LAB (50%) Constants const int MAX_TOPIC_LENGTH Provided for you

PLEASE I NEED HELP WITH THIS

I NEED THE CODE FOR Department.cpp, Department.h

Part 1 - LAB (50%)

Constants

const int MAX_TOPIC_LENGTH

Provided for you in the department.h. It represents the maximum number of characters in a project's topic.

Struct Project

This struct is provided for you in department.h. It represents a project which a department can work on. A project will have a topic represented by a C string that can hold a max of 25 characters. A project also has double that represents its cost.

Your task for part one of workshop 3 is to create a class called "Department" that encapsulates a Project. (in Department.h and Department.cpp).

Attributes

The Department class must keep the following information:

The departments' name: that is held dynamically in a C string. (char *)

The departments' projects: that is held dynamically by a Project pointer. (Project *)

Number of Current Projects: that are all held in an integer. (int)

Budget of the Department: that is held in a double (double). Should have an initial value of 15345.99.

Public methods

The Department class has the following Public functions:

void updateName(const char* newname)

If the provided name is valid (exists and is not empty), this function will set the name of the department. If the department is already set, it will deallocate the name. It will create enough memory for the name of the department to match the new name and then copies the data of the new name. If the new name is not valid, the department's current name will not change.

void updateBudget(double change)

This function will update the budget of the department by adding a new change to it.

bool addProject(Project& newproject)

This function will add a new project to the department as long as the total cost does not exceed the allocated budget. If the new project cost in addition to the total cost of the current project does not exceed the budget this function will add the new project to the department list of projects by doing the following steps:

if there are no projects currently in progress:

creates a new Project and saves the data inside it

if there are projects currently in progress:

allocates a temp array of projects with new size = old size + 1.

copy all projects from the old array to the new one

add new data to the last position of the temp array

wipe out the old array

set old array pointer to point to where temp points

in both cases

increase the number of the project by one

This function will eventually return true if a project was added to the department, and false otherwise.

void createDepartment(const char* newname, Project& newproject, double change);

This function will use functions updateName, addProject and updateBudget to set the name of the department, add a project to it and update its budget.

Project* fetchProjects() const

This function will return the list of projects a department is currently working on.

int fetchNumProjects() const;

This function will return the number of projects a department is currently working on.

double fetchBudget() const

This function will return the current budget of a department.

char* fetchName() const

This function will return the name of a department.

double totalexpenses()

This function will calculate and return the expenses of a department. The total expenses of a department is the total cost of all its current projects.

double remainingBudget()

This function will calculate and return the remaining budget of a department by subtracting the total expenses from the budget.

void clearDepartment()

This function will clear all the dynamic memory allocation in a department.

Helper Functions

These functions are fully provided for you, make sure you review them and understand how they work:

 void display(const Project& project)

This function will Display the details of a project.

 void display(const Department& department)

This function will Display the details of a department.

Tester Program

/*********************************************************************** // OOP244 Workshop # p1: tester program // // File main.cpp // Version 1.0 // Date October 7, 2022 // Author Mohammad Shamas // Description // // Revision History // ----------------------------------------------------------- // Name Date Reason // ///////////////////////////////////////////////////////////////// ***********************************************************************/ #include  #include "Department.h" using namespace std; using namespace sdds; int main() { Project testProject = { "Base",551.55 }; Project myprojects[5] = { {"Synergy", 5041.55}, {"Mecha", 2925.99}, {"Chroma", 3995.45}, {"Force", 6988.45}, {"Oculus", 7441.22} }; Department SDDS{}; //Test1 cout << "**********Create Department TEST START**********" << endl; SDDS.createDepartment("School of Software development", testProject, 1); display(SDDS); cout << "**********Create Department TEST END**********" << endl; //Test2 cout << endl << "**********Update Name TEST Start**********" << endl; SDDS.updateName("School of Software development and design"); display(SDDS); cout << "**********Update Name TEST END**********" << endl; //Test3 cout << endl << "**********Update Budget TEST Start**********" << endl; SDDS.updateBudget(5555.99); display(SDDS); cout << "**********Update Budget TEST END**********" << endl; //Test4 cout << endl << "**********Expenses and Remaining Budget TEST Start**********" << endl; cout << "Our current total Expenses are: " << SDDS.totalexpenses() << endl; cout << "Our remaining budget is: " << SDDS.remainingBudget() << endl; cout << "**********Expenses and Remaining Budget TEST END**********" << endl; //Test5 cout << endl << "**********Add Project TEST START**********" << endl; for (int i = 0; i < 5 && SDDS.addProject(myprojects[i]); i++); display(SDDS); cout << "**********Add Project TEST END**********" << endl; SDDS.clearDepartment(); return 0; }

Execution Sample

**********Create Department TEST START********** Department School of Software development details: Budget: 15347 and the number of projects in progress is: 1 Below are the details of the projects we are currently working on: Project Base will cost a total of 551.55 C$. **********Create Department TEST END********** **********Update Name TEST Start********** Department School of Software development and design details: Budget: 15347 and the number of projects in progress is: 1 Below are the details of the projects we are currently working on: Project Base will cost a total of 551.55 C$. **********Update Name TEST END********** **********Update Budget TEST Start********** Department School of Software development and design details: Budget: 20903 and the number of projects in progress is: 1 Below are the details of the projects we are currently working on: Project Base will cost a total of 551.55 C$. **********Update Budget TEST END********** **********Expenses and Remaining Budget TEST Start********** Our current total Expenses are: 551.55 Our remaining budget is: 20351.4 **********Expenses and Remaining Budget TEST END********** **********Add Project TEST START********** Department School of Software development and design details: Budget: 20903 and the number of projects in progress is: 5 Below are the details of the projects we are currently working on: Project Base will cost a total of 551.55 C$. Project Synergy will cost a total of 5041.55 C$. Project Mecha will cost a total of 2925.99 C$. Project Chroma will cost a total of 3995.45 C$. Project Force will cost a total of 6988.45 C$. **********Add Project TEST END********** 

LAB Submission (part 1)

Files to submit:

Department.cpp Department.h

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions