Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ code Please let me know how to write the code without using malloc, sizeof and free Department.h #ifndef SDDS_DEPARTMENT_H_ #define SDDS_DEPARTMENT_H_ namespace sdds {

C++ code

Please let me know how to write the code without using malloc, sizeof and free

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Department.h

#ifndef SDDS_DEPARTMENT_H_ #define SDDS_DEPARTMENT_H_ namespace sdds { const int MAX_TOPIC_LENGTH = 25; struct Project { char m_topic[MAX_TOPIC_LENGTH+1]; double m_cost; };  //class Department does here NEED TO FILL HERE //helper functions - do not belong inside the class void display(const Project& project); void display(const Department& department); } #endif // !SDDS_DEPARTMENT_H_

Department.cpp

#define _CRT_SECURE_NO_WARNINGS #include  #include  #include "Department.h" using namespace std; namespace sdds { //NEED TO FILL HERE //fully provided for students to display details of a project void display(const Project& project) { cout  

main.cpp

#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  

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. - The departments' projects: that is held dynamically by a Project pointer. - Number of Current Projects: that are all held in an integer. ( int ) - Budget of the Department: that is held in a 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. 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 increase the number of the project by one allocate projects with the new size copy all projects from the temp array to projects - wipe out the temp array - 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 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* Department: : 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. This function will Display the details of a department. Tester Program \} 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.55c. **********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.55C. 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.55C$. *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.55C$. 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.45C$. Project Force will cost a total of 6988.45C$. **********Add Project TEST END**********

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

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions

Question

What community placements are available for practica?

Answered: 1 week ago