Question
i have an error and need help fixing it in c++ please show the working code please. Main.cpp #include #include #include Date.h #include Person.h int
i have an error and need help fixing it in c++ please show the working code please.
Main.cpp
#include
#include
#include "Date.h"
#include "Person.h"
int main() {
std::string firstName;
std::string lastName;
int month;
int day;
int year;
float height;
float weight;
char answer = 'y';
std::vector
while (toupper(answer) == 'Y') {
std::cin >> firstName >> lastName >> month >> day >> year >> weight >> height;
CIST2362::Person person(firstName, lastName, month, day, year, height, weight);
personDatabase.push_back(person);
std::cin >> answer;
}
// Output person objects
for (const auto &person : personDatabase) {
std::cout << person.toString() << std::endl;
}
return 0;
}
Person.cpp
#include
#include "Person.h"
#include "PersonExceptions.h"
namespace CIST2362 {
Person::Person(const std::string& firstName, const std::string& lastName, int month, int day, int year, float height, float weight)
: firstName(firstName), lastName(lastName), birthdate(month, day, year) {
// Validate height and weight
if (height <= 0) {
throw badHeight();
}
if (weight <= 0) {
throw badWeight();
}
this->height = height;
this->weight = weight;
}
std::string Person::toString() const {
std::stringstream ss;
ss << "|" << firstName << "|" << lastName << "|" << birthdate.getMonthName() << " " << birthdate.getDay() << ", " << birthdate.getYear() << "|" << height << "feet |" << weight << " lbs|";
return ss.str();
}
}
Person.h
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_PERSON_H
#define LESSON_5_PROGRAMMING_ASSIGNMENT_PERSON_H
#include
#include "Date.h"
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 month, int day, int year, float height, float weight);
std::string toString() const;
};
} // CIST2362
#endif // LESSON_5_PROGRAMMING_ASSIGNMENT_PERSON_H
Data.cpp
#include "Date.h"
namespace CIST2362 {
Date::Date() {
// Initialize the Date class as needed
}
Date::Date(int month, int day, int year) : month(month), day(day), year(year) {
// Validate and set month, day, and year
}
void Date::setMonth(int month) {
// Validate and set month
}
void Date::setDay(int day) {
// Validate and set day
}
void Date::setYear(int year) {
// Validate and set year
}
std::string Date::getMonthName() const {
return names[month - 1];
}
int Date::getDay() const {
return day;
}
int Date::getYear() const {
return year;
}
} // CIST2362
Data.h
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H
#define LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H
#include
namespace CIST2362 {
const int NUM_MONTHS = 12;
class Date {
private:
int month;
int day;
int year;
std::string names[NUM_MONTHS] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
public:
Date();
Date(int month, int day, int year);
void setMonth(int month);
void setDay(int day);
void setYear(int year);
std::string getMonthName() const;
int getDay() const;
int getYear() const;
};
} // CIST2362
#endif // LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H
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:
const char *what() const noexcept override {
return "Invalid Height assigned - must be a positive number";
}
};
class badWeight : public std::exception {
public:
const char *what() const noexcept override {
return "Invalid Weight assigned - must be a positive number";
}
};
} // CIST2362
#endif // LESSON_5_PROGRAMMING_ASSIGNMENT_PERSONEXCEPTIONS_H
DateException.h
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_DATEEXCEPTION_H
#define LESSON_5_PROGRAMMING_ASSIGNMENT_DATEEXCEPTION_H
#include
namespace CIST2362 {
class InvalidDay : public std::exception {
public:
const char *what() const noexcept override {
return "Invalid Day assigned - must be 1 to 31";
}
};
class InvalidMonth : public std::exception {
public:
const char *what() const noexcept override {
return "Invalid Month assigned - must be 1 to 12";
}
};
class InvalidYear : public std::exception {
public:
const char *what() const noexcept override {
return "Invalid Year assigned - must be a positive number";
}
};
} // CIST2362
#endif // LESSON_5_PROGRAMMING_ASSIGNMENT_DATEEXCEPTION_H
PersonExceptions.cpp
Person.h
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_PERSON_H
#define LESSON_5_PROGRAMMING_ASSIGNMENT_PERSON_H
#include
#include "Date.h"
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 month, int day, int year, float height, float weight);
std::string toString() const;
};
} // CIST2362
#endif // LESSON_5_PROGRAMMING_ASSIGNMENT_PERSON_H
Data.cpp
#include "Date.h"
namespace CIST2362 {
Date::Date() {
// Initialize the Date class as needed
}
Date::Date(int month, int day, int year) : month(month), day(day), year(year) {
// Validate and set month, day, and year
}
void Date::setMonth(int month) {
// Validate and set month
}
void Date::setDay(int day) {
// Validate and set day
}
void Date::setYear(int year) {
// Validate and set year
}
std::string Date::getMonthName() const {
return names[month - 1];
}
int Date::getDay() const {
return day;
}
int Date::getYear() const {
return year;
}
} // CIST2362
Data.h
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H
#define LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H
#include
namespace CIST2362 {
const int NUM_MONTHS = 12;
class Date {
private:
int month;
int day;
int year;
std::string names[NUM_MONTHS] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
public:
Date();
Date(int month, int day, int year);
void setMonth(int month);
void setDay(int day);
void setYear(int year);
std::string getMonthName() const;
int getDay() const;
int getYear() const;
};
} // CIST2362
#endif // LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H
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:
const char *what() const noexcept override {
return "Invalid Height assigned - must be a positive number";
}
};
class badWeight : public std::exception {
public:
const char *what() const noexcept override {
return "Invalid Weight assigned - must be a positive number";
}
};
} // CIST2362
#endif // LESSON_5_PROGRAMMING_ASSIGNMENT_PERSONEXCEPTIONS_H
DateException.h
#ifndef LESSON_5_PROGRAMMING_ASSIGNMENT_DATEEXCEPTION_H
#define LESSON_5_PROGRAMMING_ASSIGNMENT_DATEEXCEPTION_H
#include
namespace CIST2362 {
class InvalidDay : public std::exception {
public:
const char *what() const noexcept override {
return "Invalid Day assigned - must be 1 to 31";
}
};
class InvalidMonth : public std::exception {
public:
const char *what() const noexcept override {
return "Invalid Month assigned - must be 1 to 12";
}
};
class InvalidYear : public std::exception {
public:
const char *what() const noexcept override {
return "Invalid Year assigned - must be a positive number";
}
};
} // CIST2362
#endif // LESSON_5_PROGRAMMING_ASSIGNMENT_DATEEXCEPTION_H
PersonExceptions.cpp
#include "PersonExceptions.h"
namespace CIST2362 {
const char* badHeight::what() const noexcept {
return "Invalid Height assigned - must be a positive number";
}
const char* badWeight::what() const noexcept {
return "Invalid Weight assigned - must be a positive number";
}
} // CIST2362
DateException.cpp
#include "DateException.h"
namespace CIST2362 {
const char* InvalidDay::what() const noexcept {
return "Invalid Day assigned - must be 1 to 31";
}
const char* InvalidMonth::what() const noexcept {
return "Invalid Month assigned - must be 1 to 12";
}
const char* InvalidYear::what() const noexcept {
return "Invalid Year assigned - must be a positive number";
}
} // CIST2362
Above is my code below is the error
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: Anne Niebuhr 2 15 1996 104.9 5.7 y Jesse Choi 12 4 1962 161.9 5.11 n the output is: | Anne | Niebuhr | Febraury 15, 1996] 5.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"
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