Question
(main.cpp) #include #include #include Date.h #include Person.h #include DateException.h #include PersonExceptions.h int main() { std::string firstName; std::string lastName; int birthMonth; int birthDay; int birthYear; float
(main.cpp)
#include
#include "Date.h" #include "Person.h" #include "DateException.h" #include "PersonExceptions.h"
int main() { std::string firstName; std::string lastName; int birthMonth; int birthDay; int birthYear; float height; float weight; char answer = 'y';
std::vector<:person> personDatabase; // vector of Person Objects
// input person objects // You must catch exceptions properly while (toupper(answer) == 'Y') { std::cin >> firstName; std::cin >> lastName; std::cin >> birthMonth; std::cin >> birthDay; std::cin >> birthYear; std::cin >> weight; std::cin >> height;
// place person objects into vector // ENTER CODE HERE
std::cin >> answer; }
// output the person objects // ENTER CODE HERE return 0; }
(Date.cpp)
#include "Date.h" #include "DateException.h" #include
namespace CIST2362 {
Date::Date() { // ENTER CODE HERE }
Date::Date(int m, int d, int y) { // ENTER CODE HERE }
void Date::setNames() { names[0] = "January"; names[1] = "Febraury"; names[2] = "March"; names[3] = "April"; names[4] = "May"; names[5] = "June"; names[6] = "July"; names[7] = "August"; names[8] = "September"; names[9] = "October"; names[10] = "November"; names[11] = "December"; }
void Date::setMonth(int m) { // ENTER CODE HERE }
void Date::setDay(int d) { // ENTER CODE HERE }
void Date::setYear(int y) { // ENTER CODE HERE }
std::string Date::getDateShort() { // ENTER CODE HERE return "M/D/Y"; }
std::string Date::getDateLong() { // ENTER CODE HERE
return "Month Day, Year"; }
} // CIST2362
(Date.h)
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H #define LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H #include
namespace CIST2362 {
// Constants const int NUM_MONTHS = 12;
class Date { private: int month; int day; int year;
// An array of strings to hold // the names of the months std::string names[NUM_MONTHS];
// Private member function to assign // the month names to the names array void setNames();
public: // Constructors Date(); Date(int, int, int);
// Mutators void setMonth(int m); void setDay(int d); void setYear(int y);
// Functions to print the date std::string getDateShort(); std::string getDateLong(); };
} // CIST2362
#endif //LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H
(DateException.cpp)
#include "DateException.h"
namespace CIST2362 {
// ENTER CODE HERE
} // CIST2362
(DateException.h)
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_DATEEXCEPTION_H #define LESSON_5_PROGRAMMING_ASSIGNMENT_DATEEXCEPTION_H #include
namespace CIST2362 {
// Exception classes class InvalidDay: public std::exception { public: // ENTER CODE HERE };
class InvalidMonth: public std::exception { public: // ENTER CODE HERE };
class InvalidYear: public std::exception { public: // ENTER CODE HERE };
} // CIST2362
#endif //LESSON_5_PROGRAMMING_ASSIGNMENT_DATEEXCEPTION_H
(Person.cpp)
#include
#include "Person.h" #include "PersonExceptions.h"
namespace CIST2362 { const std::string &Person::getFirstName() const { // ENTER CODE HERE }
void Person::setFirstName(const std::string &firstName) { // ENTER CODE HERE }
const std::string &Person::getLastName() const { // ENTER CODE HERE }
void Person::setLastName(const std::string &lastName) { // ENTER CODE HERE }
const Date &Person::getBirthdate() const { // ENTER CODE HERE }
void Person::setBirthdate(const Date &birthdate) { // ENTER CODE HERE }
float Person::getHeight() const { // ENTER CODE HERE }
void Person::setHeight(float height) { // ENTER CODE HERE }
float Person::getWeight() const { // ENTER CODE HERE }
void Person::setWeight(float weight) {
// ENTER CODE HERE }
Person::Person(const std::string &firstName, const std::string &lastName, int birthday, int birthmonth, int birthyear, float height, float weight) : firstName(firstName), lastName(lastName), birthdate(birthday, birthmonth, birthyear) { // ENTER CODE HERE }
std::string Person::toString() {
// ENTER CODE HERE
return "string of Person Data"; } } // CIST2362
(Person.h)
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_PERSON_H #define LESSON_5_PROGRAMMING_ASSIGNMENT_PERSON_H
#include
namespace CIST2362 {
class Person { private: std::string firstName; std::string lastName; Date birthdate; float height; float weight;
public: Person(const std::string &firstName, const std::string &lastName, int birthday, int birthmonth, int birthyear, float height, float weight);
const std::string &getFirstName() const;
void setFirstName(const std::string &firstName);
const std::string &getLastName() const;
void setLastName(const std::string &lastName);
const Date &getBirthdate() const;
void setBirthdate(const Date &birthdate);
float getHeight() const;
void setHeight(float height);
float getWeight() const;
void setWeight(float weight);
std::string toString(); };
} // CIST2362
#endif //LESSON_5_PROGRAMMING_ASSIGNMENT_PERSON_H
(PersonExceptions.cpp)
#include "PersonExceptions.h"
namespace CIST2362 {
// ENTER CODE HERE } // CIST2362
(PersonExceptions.h)
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_PERSONEXCEPTIONS_H #define LESSON_5_PROGRAMMING_ASSIGNMENT_PERSONEXCEPTIONS_H
#include
namespace CIST2362 {
class badHeight: public std::exception { public: // ENTER CODE HERE };
class badWeight: public std::exception { public: // ENTER CODE HERE };
} // CIST2362
#endif //LESSON_5_PROGRAMMING_ASSIGNMENT_PERSONEXCEPTIONS_H
14.16 CIST2362 Programming Project: Processing a Vector of People This program allows users to input person data, storing that data in a vector. Then after the last person the program outputs the person data. The data collected for each person is first and last name, date of birth as month, day, and year, and the weight and height. Ex: if input is: the output is: |Anne|Niebuhr|Febraury 15, 19965.7 feet|104.9 lbs| |Jesse|Choi|December 4, 1962| 5.1 feet|161.9 lbs| This is what will happen if all the data is entered correctly. However, your program should use exceptions to potential input errors: - if the month is out of range 1 to 12 , your exception should produce the message: Invalid Month assigned - must be 1 to 12 - if the day is out of range of 1 to 31, your exception should produce the message: Invalid Day assigned - must be 1 to 31 - if the year is a negative value, your exception should produce the message: Invalid Year assigned - must be a positive number - if the height is negative, your exception should produce the message: Invalid Height assigned - must be a positive number - if the weight is negative, your exception should produce the message: Invalid Weight assigned - must be a positive number In order to get this program working properly, you will need to insert missing code in all of the files. There are quite a few files, but take it one at a time. Remember, there are quite a few unit tests to test your classes before you need to get the main working. Take advantage of this to incrementally build and test your classes. Also, remember that you can build stubs that will allow you to compile the program until you are able to completely fill in the code. Note that this program makes use of Namespaces. You are expected to explicitly use the namespaces versus employing the "using" statement. This means you will have code like std: : cin that says you are referencing cin from the standard namespace. The other namespace you will have in this program is the CIST2362 namespace. All of the classes in your program belong to this namespace, and so you will see CIST2362: : Person referring to the Person class in the CIST2362 namespace. Namespaces are covered in Chapter 9 if you need to refer back
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started