SlideShare a Scribd company logo
1 of 14
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::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 = "";
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;
}
// 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;
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()<<
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
char selection = ' ';
string * months;
months = new string[12]; // dynamic allocation
months[0] = "Jan";
months[1] = "Feb";
months[2] = "Mar";
months[3] = "Apr";
months[4] = "May";
months[5] = "Jun";
months[6] = "Jul";
months[7] = "Aug";
months[8] = "Sep";
months[9] = "Oct";
months[10] = "Noc";
months[11] = "Dev";
Employee * employee1;
employee1 = new Employee(); // dynamic allocation
//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;
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
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
return 0;
}

More Related Content

Similar to In this assignment, you will continue working on your application..docx

Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6Nitay Neeman
 
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdfCounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdfdeepua8
 
Program.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfProgram.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfanandshingavi23
 
This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdfThis code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdfaamousnowov
 
First compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdfFirst compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdfaoneonlinestore1
 
enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docxMichel Valentim
 
Modify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdfModify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdfsaxenaavnish1
 
Java22_1670144363.pptx
Java22_1670144363.pptxJava22_1670144363.pptx
Java22_1670144363.pptxDilanAlmsa
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docxgilbertkpeters11344
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdffeelingspaldi
 
CMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End ReportCMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End ReportMatthew Zackschewski
 
Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfrajkumarm401
 
Salesforce, APEX Concepts
Salesforce, APEX ConceptsSalesforce, APEX Concepts
Salesforce, APEX ConceptsGaurish Goel
 
this is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdfthis is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdfPRATIKSINHA7304
 
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docxQ2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docxamrit47
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdffatoryoutlets
 
Brief Summary Of C++
Brief Summary Of C++Brief Summary Of C++
Brief Summary Of C++Haris Lye
 

Similar to In this assignment, you will continue working on your application..docx (20)

Getting started with ES6
Getting started with ES6Getting started with ES6
Getting started with ES6
 
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdfCounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
CounterTest.javaimport static org.junit.Assert.;import org.jun.pdf
 
Program.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdfProgram.cs class Program { static void Main(string[] args).pdf
Program.cs class Program { static void Main(string[] args).pdf
 
This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdfThis code has nine errors- but I don't know how to solve it- Please gi (1).pdf
This code has nine errors- but I don't know how to solve it- Please gi (1).pdf
 
First compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdfFirst compile all the classes.But to run the program we have to run .pdf
First compile all the classes.But to run the program we have to run .pdf
 
enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docx
 
Modify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdfModify the Date class that was covered in the lecture which overload.pdf
Modify the Date class that was covered in the lecture which overload.pdf
 
Java22_1670144363.pptx
Java22_1670144363.pptxJava22_1670144363.pptx
Java22_1670144363.pptx
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
 
CMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End ReportCMPSC 122 Project 1 Back End Report
CMPSC 122 Project 1 Back End Report
 
Link list
Link listLink list
Link list
 
Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
 
Salesforce, APEX Concepts
Salesforce, APEX ConceptsSalesforce, APEX Concepts
Salesforce, APEX Concepts
 
this is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdfthis is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdf
 
12Structures.pptx
12Structures.pptx12Structures.pptx
12Structures.pptx
 
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docxQ2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
Q2dayOfYear.cppQ2dayOfYear.cpp  Name   Copyright  .docx
 
Lecture 8
Lecture 8Lecture 8
Lecture 8
 
HELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdfHELP IN JAVACreate a main method and use these input files to tes.pdf
HELP IN JAVACreate a main method and use these input files to tes.pdf
 
Brief Summary Of C++
Brief Summary Of C++Brief Summary Of C++
Brief Summary Of C++
 

More from jaggernaoma

Attached is a joint letter to Capitol Hill to advocate for increased.docx
Attached is a joint letter to Capitol Hill to advocate for increased.docxAttached is a joint letter to Capitol Hill to advocate for increased.docx
Attached is a joint letter to Capitol Hill to advocate for increased.docxjaggernaoma
 
Attached is a copy of an interview done with a Tribal member regardi.docx
Attached is a copy of an interview done with a Tribal member regardi.docxAttached is a copy of an interview done with a Tribal member regardi.docx
Attached is a copy of an interview done with a Tribal member regardi.docxjaggernaoma
 
Attached Files Week 5 - trace IP Physical Location.rtf (38..docx
Attached Files Week 5 - trace IP Physical Location.rtf (38..docxAttached Files Week 5 - trace IP Physical Location.rtf (38..docx
Attached Files Week 5 - trace IP Physical Location.rtf (38..docxjaggernaoma
 
Attached here is a psychology article I need to be summarized. Pleas.docx
Attached here is a psychology article I need to be summarized. Pleas.docxAttached here is a psychology article I need to be summarized. Pleas.docx
Attached here is a psychology article I need to be summarized. Pleas.docxjaggernaoma
 
Attached Files News Analysis Sample.docxNews Analysis Sam.docx
Attached Files News Analysis Sample.docxNews Analysis Sam.docxAttached Files News Analysis Sample.docxNews Analysis Sam.docx
Attached Files News Analysis Sample.docxNews Analysis Sam.docxjaggernaoma
 
Attached Files  SOC-220_SOCIAL PROBLEMS PRESENTATION.docx
Attached Files     SOC-220_SOCIAL PROBLEMS PRESENTATION.docxAttached Files     SOC-220_SOCIAL PROBLEMS PRESENTATION.docx
Attached Files  SOC-220_SOCIAL PROBLEMS PRESENTATION.docxjaggernaoma
 
Attached below you will find the series of 4 questions. This assignm.docx
Attached below you will find the series of 4 questions. This assignm.docxAttached below you will find the series of 4 questions. This assignm.docx
Attached below you will find the series of 4 questions. This assignm.docxjaggernaoma
 
Attached below isWEEK 4 As always, include references. As alwa.docx
Attached below isWEEK 4 As always, include references. As alwa.docxAttached below isWEEK 4 As always, include references. As alwa.docx
Attached below isWEEK 4 As always, include references. As alwa.docxjaggernaoma
 
Attached are two articles in one document. Write thoughtful resp.docx
Attached are two articles in one document. Write thoughtful resp.docxAttached are two articles in one document. Write thoughtful resp.docx
Attached are two articles in one document. Write thoughtful resp.docxjaggernaoma
 
Attached are the instructions to the assignment.Written Assign.docx
Attached are the instructions to the assignment.Written Assign.docxAttached are the instructions to the assignment.Written Assign.docx
Attached are the instructions to the assignment.Written Assign.docxjaggernaoma
 
Attached are the instructions and rubric! Research Paper #2.docx
Attached are the instructions and rubric! Research Paper #2.docxAttached are the instructions and rubric! Research Paper #2.docx
Attached are the instructions and rubric! Research Paper #2.docxjaggernaoma
 
Attached are the guidelines for the Expertise Sharing Project. M.docx
Attached are the guidelines for the Expertise Sharing Project. M.docxAttached are the guidelines for the Expertise Sharing Project. M.docx
Attached are the guidelines for the Expertise Sharing Project. M.docxjaggernaoma
 
Attached are the documents needed to complete the assignment. The in.docx
Attached are the documents needed to complete the assignment. The in.docxAttached are the documents needed to complete the assignment. The in.docx
Attached are the documents needed to complete the assignment. The in.docxjaggernaoma
 
Attached are the 3 documents1. Draft copy submitted2. Sam.docx
Attached are the 3 documents1. Draft copy submitted2. Sam.docxAttached are the 3 documents1. Draft copy submitted2. Sam.docx
Attached are the 3 documents1. Draft copy submitted2. Sam.docxjaggernaoma
 
attached are directions needed to complete this essay! Please make s.docx
attached are directions needed to complete this essay! Please make s.docxattached are directions needed to complete this essay! Please make s.docx
attached are directions needed to complete this essay! Please make s.docxjaggernaoma
 
Attach is the checklist For this Assignment, write a 3 and half pa.docx
Attach is the checklist For this Assignment, write a 3 and half pa.docxAttach is the checklist For this Assignment, write a 3 and half pa.docx
Attach is the checklist For this Assignment, write a 3 and half pa.docxjaggernaoma
 
Attach and submit the final draft of your Narrative Essay. Remember .docx
Attach and submit the final draft of your Narrative Essay. Remember .docxAttach and submit the final draft of your Narrative Essay. Remember .docx
Attach and submit the final draft of your Narrative Essay. Remember .docxjaggernaoma
 
Atomic Theory Scientists and Their ContributionsScientist .docx
Atomic Theory Scientists and Their ContributionsScientist .docxAtomic Theory Scientists and Their ContributionsScientist .docx
Atomic Theory Scientists and Their ContributionsScientist .docxjaggernaoma
 
Atomic models are useful because they allow us to picture what is in.docx
Atomic models are useful because they allow us to picture what is in.docxAtomic models are useful because they allow us to picture what is in.docx
Atomic models are useful because they allow us to picture what is in.docxjaggernaoma
 
Atoms and Electrons AssignmentLook at these websites to he.docx
Atoms and Electrons AssignmentLook at these websites to he.docxAtoms and Electrons AssignmentLook at these websites to he.docx
Atoms and Electrons AssignmentLook at these websites to he.docxjaggernaoma
 

More from jaggernaoma (20)

Attached is a joint letter to Capitol Hill to advocate for increased.docx
Attached is a joint letter to Capitol Hill to advocate for increased.docxAttached is a joint letter to Capitol Hill to advocate for increased.docx
Attached is a joint letter to Capitol Hill to advocate for increased.docx
 
Attached is a copy of an interview done with a Tribal member regardi.docx
Attached is a copy of an interview done with a Tribal member regardi.docxAttached is a copy of an interview done with a Tribal member regardi.docx
Attached is a copy of an interview done with a Tribal member regardi.docx
 
Attached Files Week 5 - trace IP Physical Location.rtf (38..docx
Attached Files Week 5 - trace IP Physical Location.rtf (38..docxAttached Files Week 5 - trace IP Physical Location.rtf (38..docx
Attached Files Week 5 - trace IP Physical Location.rtf (38..docx
 
Attached here is a psychology article I need to be summarized. Pleas.docx
Attached here is a psychology article I need to be summarized. Pleas.docxAttached here is a psychology article I need to be summarized. Pleas.docx
Attached here is a psychology article I need to be summarized. Pleas.docx
 
Attached Files News Analysis Sample.docxNews Analysis Sam.docx
Attached Files News Analysis Sample.docxNews Analysis Sam.docxAttached Files News Analysis Sample.docxNews Analysis Sam.docx
Attached Files News Analysis Sample.docxNews Analysis Sam.docx
 
Attached Files  SOC-220_SOCIAL PROBLEMS PRESENTATION.docx
Attached Files     SOC-220_SOCIAL PROBLEMS PRESENTATION.docxAttached Files     SOC-220_SOCIAL PROBLEMS PRESENTATION.docx
Attached Files  SOC-220_SOCIAL PROBLEMS PRESENTATION.docx
 
Attached below you will find the series of 4 questions. This assignm.docx
Attached below you will find the series of 4 questions. This assignm.docxAttached below you will find the series of 4 questions. This assignm.docx
Attached below you will find the series of 4 questions. This assignm.docx
 
Attached below isWEEK 4 As always, include references. As alwa.docx
Attached below isWEEK 4 As always, include references. As alwa.docxAttached below isWEEK 4 As always, include references. As alwa.docx
Attached below isWEEK 4 As always, include references. As alwa.docx
 
Attached are two articles in one document. Write thoughtful resp.docx
Attached are two articles in one document. Write thoughtful resp.docxAttached are two articles in one document. Write thoughtful resp.docx
Attached are two articles in one document. Write thoughtful resp.docx
 
Attached are the instructions to the assignment.Written Assign.docx
Attached are the instructions to the assignment.Written Assign.docxAttached are the instructions to the assignment.Written Assign.docx
Attached are the instructions to the assignment.Written Assign.docx
 
Attached are the instructions and rubric! Research Paper #2.docx
Attached are the instructions and rubric! Research Paper #2.docxAttached are the instructions and rubric! Research Paper #2.docx
Attached are the instructions and rubric! Research Paper #2.docx
 
Attached are the guidelines for the Expertise Sharing Project. M.docx
Attached are the guidelines for the Expertise Sharing Project. M.docxAttached are the guidelines for the Expertise Sharing Project. M.docx
Attached are the guidelines for the Expertise Sharing Project. M.docx
 
Attached are the documents needed to complete the assignment. The in.docx
Attached are the documents needed to complete the assignment. The in.docxAttached are the documents needed to complete the assignment. The in.docx
Attached are the documents needed to complete the assignment. The in.docx
 
Attached are the 3 documents1. Draft copy submitted2. Sam.docx
Attached are the 3 documents1. Draft copy submitted2. Sam.docxAttached are the 3 documents1. Draft copy submitted2. Sam.docx
Attached are the 3 documents1. Draft copy submitted2. Sam.docx
 
attached are directions needed to complete this essay! Please make s.docx
attached are directions needed to complete this essay! Please make s.docxattached are directions needed to complete this essay! Please make s.docx
attached are directions needed to complete this essay! Please make s.docx
 
Attach is the checklist For this Assignment, write a 3 and half pa.docx
Attach is the checklist For this Assignment, write a 3 and half pa.docxAttach is the checklist For this Assignment, write a 3 and half pa.docx
Attach is the checklist For this Assignment, write a 3 and half pa.docx
 
Attach and submit the final draft of your Narrative Essay. Remember .docx
Attach and submit the final draft of your Narrative Essay. Remember .docxAttach and submit the final draft of your Narrative Essay. Remember .docx
Attach and submit the final draft of your Narrative Essay. Remember .docx
 
Atomic Theory Scientists and Their ContributionsScientist .docx
Atomic Theory Scientists and Their ContributionsScientist .docxAtomic Theory Scientists and Their ContributionsScientist .docx
Atomic Theory Scientists and Their ContributionsScientist .docx
 
Atomic models are useful because they allow us to picture what is in.docx
Atomic models are useful because they allow us to picture what is in.docxAtomic models are useful because they allow us to picture what is in.docx
Atomic models are useful because they allow us to picture what is in.docx
 
Atoms and Electrons AssignmentLook at these websites to he.docx
Atoms and Electrons AssignmentLook at these websites to he.docxAtoms and Electrons AssignmentLook at these websites to he.docx
Atoms and Electrons AssignmentLook at these websites to he.docx
 

Recently uploaded

21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use CasesTechSoup
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsPallavi Parmar
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfKartik Tiwari
 

Recently uploaded (20)

21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell Tolls
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
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
  • 10. char selection = ' '; string * months; months = new string[12]; // dynamic allocation months[0] = "Jan"; months[1] = "Feb"; months[2] = "Mar"; months[3] = "Apr"; months[4] = "May"; months[5] = "Jun"; months[6] = "Jul"; months[7] = "Aug"; months[8] = "Sep"; months[9] = "Oct"; months[10] = "Noc"; months[11] = "Dev"; Employee * employee1; employee1 = new Employee(); // dynamic allocation
  • 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