In this assignment, you will continue working on your application. In Week 4, you used 2 arrays to represent the list of products and their quantities. Memory needs were determined before program execution. This week, you will use dynamic allocation so the memory needs are determined during runtime. The functionality of the program is not expected to change. You may use the sample code
as the template.
Create a new C++ empty project titled "CS115_IP5_YourName" in the IDE.
For the quantities, use a pointer to the first item of an array of int. An example of the declaration code may look like the following:
For the products, use an array of pointers to strings, and dynamically allocate space for each of the strings. An example of the declaration code may look like the following:
To fill in the products array, read one product name from the user, check the length, and then allocate memory based on the length of the entered word. The following code is provided as an example:
Use the previous structure to provide the same functionality that was provided in Week 4.
Complete the following in your code:
Provide a list of available products
Ask the customer to select products and quantities
Save the provided details in the new data structure
Read from the arrays to print the order summary; that is, the products, quantities, and the total price for each product
Calculate and print the total price for the order
Release the allocated memory
Compile and run the application to demonstrate a working program.
Insert the screenshots into a Word document, and add a short explanation on each screenshot.
Finally, save your Word document as “yourname_IP4.docx”. Click the “Edit” button on this submission node to submit the saved document.
// Use of Classes and dynamic allocation
#include <iostream>
using namespace std;
// Employee class definition
class Employee
{
private:
string empName;
string empAddress;
string empEmail;
int vacationMonths;
int * empVacationDays; // hold vacation days taken for every month
public:
void setEmpName(string);
string getEmpName();
void setEmpAddress(string);
string getEmpAddress();
void setEmpEmail(string);
string getEmpEmail();
void setEmpVacationDays(int, int); // sets vacation days for a specific month
int getEmpVacationDays(int); //gets vacation days taken in a specific month
int getTotalEmpVacationDays(); //gets the total vacation days
// Constructor
Employee();
Employee(int); // this constructor sets up the size of the emplyee vacation array
// Destructor
~Employee();
};
//definition of set/get member functions of Employee class
void Employee::setEmpName(string name)
{
empName=name;
}
void Employee::setEmpAddress(string address)
{
empAddress=address;
}
void Employee::setEmpVacationDays(int month, int vDays)
{
empVacationDays[month-1]=vDays;
}
void Employee::setEmpEmail(string email)
{
empEmail=email;
}
string Employee::g.
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
In this assignment, you will continue working on your application..docx
1. In this assignment, you will continue working on your
application. In Week 4, you used 2 arrays to represent the list of
products and their quantities. Memory needs were determined
before program execution. This week, you will use dynamic
allocation so the memory needs are determined during runtime.
The functionality of the program is not expected to change. You
may use the sample code
as the template.
Create a new C++ empty project titled "CS115_IP5_YourName"
in the IDE.
For the quantities, use a pointer to the first item of an array of
int. An example of the declaration code may look like the
following:
For the products, use an array of pointers to strings, and
dynamically allocate space for each of the strings. An example
of the declaration code may look like the following:
To fill in the products array, read one product name from the
user, check the length, and then allocate memory based on the
length of the entered word. The following code is provided as
an example:
Use the previous structure to provide the same functionality that
was provided in Week 4.
Complete the following in your code:
Provide a list of available products
Ask the customer to select products and quantities
Save the provided details in the new data structure
Read from the arrays to print the order summary; that is, the
products, quantities, and the total price for each product
Calculate and print the total price for the order
Release the allocated memory
Compile and run the application to demonstrate a working
2. program.
Insert the screenshots into a Word document, and add a short
explanation on each screenshot.
Finally, save your Word document as “yourname_IP4.docx”.
Click the “Edit” button on this submission node to submit the
saved document.
// Use of Classes and dynamic allocation
#include <iostream>
using namespace std;
// Employee class definition
class Employee
{
private:
string empName;
string empAddress;
string empEmail;
int vacationMonths;
3. int * empVacationDays; // hold vacation days taken
for every month
public:
void setEmpName(string);
string getEmpName();
void setEmpAddress(string);
string getEmpAddress();
void setEmpEmail(string);
string getEmpEmail();
void setEmpVacationDays(int, int); // sets vacation
days for a specific month
int getEmpVacationDays(int); //gets vacation days
taken in a specific month
int getTotalEmpVacationDays(); //gets the total
vacation days
// Constructor
Employee();
Employee(int); // this constructor sets up the size of
the emplyee vacation array
// Destructor
~Employee();
4. };
//definition of set/get member functions of Employee class
void Employee::setEmpName(string name)
{
empName=name;
}
void Employee::setEmpAddress(string address)
{
empAddress=address;
}
void Employee::setEmpVacationDays(int month, int vDays)
{
empVacationDays[month-1]=vDays;
}
void Employee::setEmpEmail(string email)
{
empEmail=email;
5. }
string Employee::getEmpName() { return empName; }
string Employee::getEmpAddress() { return empAddress; }
string Employee::getEmpEmail() { return empEmail; }
int Employee::getEmpVacationDays(int month) { return
empVacationDays[month-1]; }
int Employee::getTotalEmpVacationDays()
{
int sum = 0;
for (int i=0; i<12; i++)
sum += empVacationDays[i];
return sum;
}
// Constructor 1 definition
Employee::Employee()
{
empName = "";
6. empAddress = "";
empEmail="";
vacationMonths = 12;
empVacationDays = new int [vacationMonths];
for (int i=0; i<vacationMonths; i++)
empVacationDays[i] = 0;
}
// Constructor 2 definition
Employee::Employee(int months)
{
empName = "";
empAddress = "";
empEmail="";
vacationMonths = months;
empVacationDays = new int [months];
for (int i=0; i<vacationMonths; i++)
empVacationDays[i] = 0;
7. }
// Destructor definition
Employee::~Employee()
{
delete [] empVacationDays; // de-allocating the array space
before object is deleted
}
void displayMenu(Employee *emp)
{
cout << emp->getEmpName() << ", please select an action
from the menu below" << endl;
cout<<"My Menu";
cout<<"========" << endl;
cout<<"1 - View My Address" << endl;
cout<<"2 - View My Email Address" << endl;
8. cout<<"3 - View Total Vacation Days Taken" << endl;
cout<<"4 - View Vacation Days Taken in Specific Month"
<< endl;
cout<<"X - Exit " <<endl<<endl;
}
// View address for <name>
void viewAddress(Employee *emp)
{
cout << "Name: " << emp->getEmpName() << endl;
cout << "Address: " << emp->getEmpAddress() << endl;
}
// View email address for <name>
void viewEmail(Employee *emp)
{
cout << "Name: " << emp->getEmpName() << endl;
cout << "Email Address: " << emp->getEmpEmail()<<
9. endl;
}
// returns total vacation days taken for <name>
int totalVacationDays(Employee *emp)
{
return emp->getTotalEmpVacationDays();
}
// returns vacation days taken for a specific month for <name>
int vacationDaysMonth(Employee *emp, int month)
{
return emp->getEmpVacationDays(month);
}
int main(void)
{
// variable declaration section
11. //Initialize employee1 members
employee1->setEmpName("John Smith");
employee1->setEmpAddress("1235 Main Street");
employee1->setEmpEmail("[email protected]");
employee1->setEmpVacationDays(1, 2); // 2 vacation days
taken in the month of January
employee1->setEmpVacationDays(7, 8); // 8 vacation days
taken in the month of July
//display employee name
cout << "Hello "+ employee1->getEmpName() << endl;
do
{
// display menu
displayMenu(employee1);
// read user selection
cin>>selection;
12. switch(selection)
{
case '1':
cout<< "View My Address is selected" << endl;
viewAddress(employee1);
break;
case '2':
cout<< "View My Email Address is selected" <<
endl;
viewEmail(employee1);
break;
case '3':
cout<< "View Total Vacation Days Taken is
selected" << endl;
cout << "You have taken " <<
totalVacationDays(employee1) << " days!!" << endl;
break;
case '4':
cout<< "View Total Vacation Days Taken for
13. Specific Month is selected" << endl;
cout << "Enter month => ";
int month;
cin >> month;
cout << "You have taken " <<
vacationDaysMonth(employee1, month) << " days in month of "
<< months[month-1] << endl;
break; case 'X' :
case 'x':
cout<<"Thank you!!!" << endl;
break;
// other than 1, 2, 3 and X...
default : cout<<"Invalid selection. Please try again";
// no break in the default case
}
cout<<endl<<endl;
} while (selection!= 'X' && selection != 'x');
delete [] months; // release allocated memory for array
months