Question: Please help me to soleve this milstone: The ProjectMilestone 1 Before we start developing the application,... The ProjectMilestone 1 Before we start developing the application,
Please help me to soleve this milstone: The ProjectMilestone 1 Before we start developing the application,...
The ProjectMilestone 1
Before we start developing the application, we need to have a few classes developed to help us with the dates in the system, handling state of the object (error handling), Menus and also a mock-up of the user interface of the application. Also, we need to get familiarized with the Utils module.
The Utils moduleUtils.h
namespace sdds { // Testing date values for application testing and debugging // these values must not change at submission time. const int sdds_testYear = 2022; const int sdds_testMon = 03; const int sdds_testDay = 31; class Utils { bool m_testMode = false; public: // this function will be used to get the current system date or the test date if m_testMode is true void getSystemDate(int* year = nullptr, int* mon = nullptr, int* day = nullptr); // this function will return the number of days in a month based on the year // 1<=mon<=12 year: four digit number (example: 2021) int daysOfMon(int mon, int year)const; // Puts the system date in test mode, where getSystemDate() function will return 2022, 03, 31 // or whatever the three constant test dates are set to void testMode(bool testmode = true); }; extern Utils ut; // provides global access to the ut instance in the Utils.cpp file }
Utils.cpp
#define _CRT_SECURE_NO_WARNINGS #include
The above Utils module is provided with the application. You may add any of your own methods as needed to the Utils class, to be used in the application or add any stand-alone helper functions. (having the functions as Utils member-functions are preferred)
Recommended methods for Utils
The following are recommended methods that if you develop, it is going to ease the development of the rest of the project since the tasks these functions provide will be needed several times in the project:
void Utils::alocpy(char*& destination, const char* source);
Safely allocates memory in destination and copies the source into it.
- deletes the destination dynamic array and sets it to null
- if the source is not null Allocates memory in the destination to the size of the source and copies the source into it.
int Utils::getint(const char* prompt = nullptr)
If the prompt is not null, it will display it. Then it performs a foolproof entry of an integer. If the user enters an invalid integer it will display "Invalid Integer, retry: " and will not let the user leave the function until a valid integer is entered.
int Utils::getint(int min, int max, const char* prompt=nullptr, const char* errMes=nullptr);
If the prompt is not null it will be displayed before getting a valid integer.(reuse the previous getint()) If the entered integer is not within the acceptable range (min and max) then an error message is displayed and it will not let the user leave the function until an acceptable value is entered. When printing the error message, if the errMes argument is not null it will be displayed followed by ", retry: " otherwise the general error message "Value out of range [min<=val<=max]: " is displayed (replacing min and max with their values)
Note: Implementation of the above functions are optional. You can use your own way to implement the requirements of the application if you like. As we advance through the implementation of the project, more suggestions for Utils function may follow
Milestone 1 OverviewStatus Class
A class to keep track of the state of an object by holding the description of the state and an optional status code. For example Error desc: "Invalid Range", Error code: 101
Date Class
A class that encapsulates year, month and day values for date stamping, validation, comparison and date IO purposes.
The Status class
This class encapsulates two values:
- A dynamic CString for the description of the status of an object.
- An integer for an optional status Code.
Construction
A Status object can be constructed with or without a CString as a description.
- If the description is provided, a dynamic copy of it will be kept in the class description.
- If the description is not provided, the class description will be set to null.
- In both cases the Code will be zero.
Rule of three
A Status object should be safely copied from or assigned to another Status object and when going out of scope there should be no memory leak.
Assignment operator overloads
A Status object should be able to be assigned to an integer or a CString. The results of the assignments should set the code or the description dynamically (with no memory leak).
Type Conversion Overloads
- Casting a Status object to an integer should return the code
- Casting a Status object to a constant character pointer should return the description.
- Casting a Status object to a boolean should return true if the description is null and false if it is not. Which means if the Status has no description, the owner class is in a valid state. (No news is good news.)
The clear() method
Create a method called clear() that safely deallocates the description and sets the code to zero. This method will return a reference to the current object at the end.
Helper insertion operator overload
Overload the insertion operator to be able to print a Status object using ostream. This operator overload should print the Status only if it is in an invalid state. See type conversion(bool overload)
When printing the status object the code is printed only if it is not zero as follows `"ERR#???: " where ??? replaced with the code. Then the description of the Status object is printed.
Status Tester program
/* ------------------------------------------------------ Final project Milestone 1 Module: Status Filename: StatusTester.cpp Version 1.0 Author: Fardad Soleimanloo 2022-02-28 Revision History ----------------------------------------------------------- Date Reason -----------------------------------------------------------*/ #include
Status tester output
Enter following values : abc 123 -123 12 > abc Container: (Invalid Integer) Error #: 0 Problem: Invalid Integer > 123 Container: (ERR#1: value too high) Error #: 1 Problem: value too high > -123 Container: (ERR#-1: value too low) Error #: -1 Problem: value too low > 12 Container: (12) The Date ClassConstant values
Create a constant value indicating the largest acceptable value for a year and set it to 2030. (referred as the "maximum year value* here)
Attributes
The date class encapsulates the following:
- Year; an integer between the current year the maximum year value.
- Month; an integer between 1 and 12
- Day; an integer between 1 and the number of days in the month based on the year.
- State; a Status object that holds the validity status of date.
- Formatted; a boolean value that is set to true to print the date as YYYY/MM/DD or false to print it as YYMMDD.
Private Methodsvalidate
Does not receive any arguments and returns a boolean.
This function validates the year, month and day, kept in the object in the following order (and validation stops if an invalid value is found):
- If the year value is invalid (less than the current year or more than the maximum year value), the State is set to "Invalid year in date" and then set to the code 1.
- If the month value is invalid (less than 1or more than 12), the State is set to "Invalid month in date" and then set to the code 2.
- If the day value is invalid(less than one or more than the maximum number of days in the month based on the year), the State is set to "Invalid day in date" and then set to the code 3.
- The State is cleared if everything is valid.
In the end, if the date is valid the function returns true or false if any of the validations have failed.
unique date value
Create a method to return a unique integer value tied to the date. Use this value to compare two dates. Use the following formula to obtain the unique integer value:
year * 372 + mon * 31 + day Construction
A Date is created either with all three values or no value provided.
- If all three values are provided, the year and month and day will be set to the corresponding values and then they are validated.
- If no initial value is provided, the Date is set to the current system date.
operator overloads for comparison.
Overload all the six comparison operators: ==, !=, <, >, <=, >=
Use the private method, unique date value for the comparison.
state accessor
Create an accessor method called state that returns a constant reference to the State of the Date.
formatted modifier
Create a modifier method called formatted to set the Formatted flag (attribute) of the Date. This method should return the reference of the current object.
bool conversion overload
If the Date object is casted to a boolean, the state of the date object is returned.
write method
Create a method called write that receives and returns a reference of the ostream object in which it inserts the date value as follows:
- If the Formatted attribute is true, it will print the date in the following format: YYYY/MM/DD, month and day are printed in 2 spaces padded with zero.
- If the Formatted attribute is false it will print the date in the following format: YYMMDD, month and day are printed in 2 spaces padded with zero.
read method
Create a method called read that receives and returns a reference of the istream object from which it extracts the date value as follows:
The date is entered as one integer value.
- If the value is a four digits integer then the Date is read as: MMDD and the year is set to the current system year.
- If the value is a six digits integer then the date is read as: YYMMDD.
Then the data is validated and if the validation fails the istream object is set to a fail state. istream::setstate(ios::badbit);
Example: 0221 will be read as Year: 2022, Month: 2, Day: 21 230315 will be read as Year: 2023, Month: 3, Day: 15 190101 will be read as Year: 2019, Month: 1, Day 1, which will be an invalid date.
Helper insertion and extraction operator overloads
Overload the insertion and extraction operators to write and read a date object through ostream and istream respectively. (cout and cin)
Date Tester program:
/* ------------------------------------------------------ Final project Milestone 1 Module: Date Filename: DateTester.cpp Version 1.0 Author: Fardad Soleimanloo 2022-02-28 Revision History ----------------------------------------------------------- Date Reason -----------------------------------------------------------*/ #include
Date Tester output
The first line will change base on the date of execution
Currect Date: 2022/03/02 Test mode: Current Date formatted (C): 2022/03/31 Current Date unformatted (C): 220331 Future Date formatted (F): 2022/05/25 Future Date unformatted (F): 220525 The current date is NOT the same as the future date The current date is the same as the current date The current date is Less than or equal to the future date The current date is Less than or equal to the current date The current date is Less than the future date The future date is greater than or equal to the current date The future date is greater than or equal to the future date The future date is greater than the current date -------------- Assigning the Current date to the future date! Now both of the dates are the same! Enter the following: 1- abc 2- 12 3- 1212 4- 121212 5- 221312 6- 220229 7- 220228 > abc Invalid date value > 12 ERR#2: Invalid month in date > 1212 Date enterd: 2022/12/12 > 121212 ERR#1: Invalid year in date > 221312 ERR#2: Invalid month in date > 220229 ERR#3: Invalid day in date > 220228 Date enterd: 2022/02/28 MS1 Submission
Make sure that all the debugging code and debugging comments are removed before submission.
Milestone 1 tester program
The tester program for milestone one includes the two testers of Status and Date and the source code is in main.cpp
Files to submit
Utils.cpp Utils.h Status.cpp Status.h Date.cpp Date.h main.cpp Upload your source codes and the tester program to your matrix account. Compile and run your code using the g++ compiler as shown in the introduction and make sure that everything works properly.
Back to milestonesMilestone 2The User interface
Now that the Status and Date classes are developed we can create the user interface of the system. To accomplish this we need to create two classes; Menu and AidMan (Aid Management)
The Menu Module.
Create a class called Menu. This class has two attributes.
- A dynamically allocated text that contains the list of options the user can select from.
- An unsigned integer that holds the number of available options.
For example, if a menu offers three types of drink:
1- Orange Juice 2- Water 3- Apple Juice The text the menu holds will be: "1- Orange Juicen2- Watern3- Apple Juicen". In this project we will call this text, the menu content. Also, the number of options will be 3.
Construction
A Menu is created using an unsigned integer and a CString. The unsigned integer is used to initialize the number of options and a dynamic copy of the CString is held in the menu content. The maximum number of options is 15, if the number of options is more than 15 or if the CString is null, then the menu is rendered invalid.
Rule of three.
A Menu cannot be copied or assigned to another Menu. When going out of scope the menu content is deallocated to prevent a memory leak.
Methods
The menu has only one public method called run().
run()
This method receives nothing and returns an unsigned integer and will not change the state of the Menu object.
The run method will first display the menu content and then prints "0- Exit" and goes to newline. Then it will display "> " as a prompt and waits for the user to enter an integer between 0 and the number of options. This integer entry is foolproof. The user can not exit this stage unless a valid integer number with a valid value is entered.
- If the user enters a non-integer value the error message should be: "Invalid Integer, retry: ".
- If the user enters an invalid integer then the error message should be: "Value out of range [0<=val<=X]: ". Where X is the number of options.
In the end, the selected number will be returned.
Execution sample
Using the previous example's data an execution sample of the run method will be as follows:
1- Orange Juice 2- Water 3- Apple Juice 0- Exit > abc Invalid Integer, retry: 10 Value out of range [0<=val<=3]: 3 3 will be returned by the run function.
Additional methods
The Menu class with the above capabilities supports what we need from a Menu up to this part of the application. There is no "need" for any additional methods or attributes. However, you are free to add any other functionality needed to make the work easier for you.
The AidMan Module
The AidMan Module is the controller of the whole system. We will design it as if the application is complete but with respect to functionality, it will be completely hollow. Essentially at this stage of the development AidMan is only a prototype for the system.
When all the pieces of the system are developed, we will put them together by adding their role into the AidMan Class.
Development
Create a class called AidMan that offers a Menu with the list of tasks needed to be done to manage the preparation of products to be shipped to places in need.
Attributesfile name
Dynamically holding the name of a data file holding the aid and product information.
main menu
A Menu object.
Private Methods
For now, there is only one private method, but as we advance in the development of the system new methods may be added.
menu()
This function receives nothing and returns an unsigned integer that is the user's selection of an option in the main menu of the system. The menu function will not change the state of the AidMan class.
The Menu will first print the title of the application, current date and the data file name.
Aid Management System Version 0.1 Date: YYYY/MM/DD Data file: filename.csv --------------------------------- If the filename attribute is null, it will print "No file" instead of the file name.
Then it will run the main menu and return the selection made by the user.
Construction
The AidMan has only one default constructor that initializes the main menu with 7 for the number of options and the following text as the menu content:
"1- List Itemsn" "2- Add Itemn" "3- Remove Itemn" "4- Update Quantityn" "5- Sortn" "6- Ship Itemsn" "7- New/Open Aid Databasen" "---------------------------------n" The file name attribute is also initialized to nullptr.
Rule Of Three
- An AidMan object can neither be copied nor assigned to another AinMan object.
- When going out of scope the destructor makes sure there is no memory leak.
the public method run()
run() receives and returns nothing and runs the whole application.
In a loop, the run function will keep displaying the menu by calling the menu() function and awaits the user's entry. Then after each selection, based on the user's entry, it will execute the task chosen from the menu.
The run function exits when the user selects 0, at which point it will print "Exiting Program!"
For now, when a task is selected just print the task name as follows:
MS2 Submission
Make sure that all the debugging code and debugging comments are removed before submission.
Milestone 2 tester program
The tester program for milestone 2 can be found here: main.cpp
Tester output
Enter the following: abc 1 2 3 4 5 6 7 8 0 -------- Aid Management System Version 0.1 Date: 2022/03/31 Data file: No file --------------------------------- 1- List Items 2- Add Item 3- Remove Item 4- Update Quantity 5- Sort 6- Ship Items 7- New/Open Aid Database --------------------------------- 0- Exit > abc Invalid Integer, retry: 1 ****List Items**** Aid Management System Version 0.1 Date: 2022/03/31 Data file: No file --------------------------------- 1- List Items 2- Add Item 3- Remove Item 4- Update Quantity 5- Sort 6- Ship Items 7- New/Open Aid Database --------------------------------- 0- Exit > 2 ****Add Item**** Aid Management System Version 0.1 Date: 2022/03/31 Data file: No file --------------------------------- 1- List Items 2- Add Item 3- Remove Item 4- Update Quantity 5- Sort 6- Ship Items 7- New/Open Aid Database --------------------------------- 0- Exit > 3 ****Remove Item**** Aid Management System Version 0.1 Date: 2022/03/31 Data file: No file --------------------------------- 1- List Items 2- Add Item 3- Remove Item 4- Update Quantity 5- Sort 6- Ship Items 7- New/Open Aid Database --------------------------------- 0- Exit > 4 ****Update Quantity**** Aid Management System Version 0.1 Date: 2022/03/31 Data file: No file --------------------------------- 1- List Items 2- Add Item 3- Remove Item 4- Update Quantity 5- Sort 6- Ship Items 7- New/Open Aid Database --------------------------------- 0- Exit > 5 ****Sort**** Aid Management System Version 0.1 Date: 2022/03/31 Data file: No file --------------------------------- 1- List Items 2- Add Item 3- Remove Item 4- Update Quantity 5- Sort 6- Ship Items 7- New/Open Aid Database --------------------------------- 0- Exit > 6 ****Ship Items**** Aid Management System Version 0.1 Date: 2022/03/31 Data file: No file --------------------------------- 1- List Items 2- Add Item 3- Remove Item 4- Update Quantity 5- Sort 6- Ship Items 7- New/Open Aid Database --------------------------------- 0- Exit > 7 ****New/Open Aid Database**** Aid Management System Version 0.1 Date: 2022/03/31 Data file: No file --------------------------------- 1- List Items 2- Add Item 3- Remove Item 4- Update Quantity 5- Sort 6- Ship Items 7- New/Open Aid Database --------------------------------- 0- Exit > 8 Value out of range [0<=val<=7]: 0 Exiting Program!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
