i have an error and need help fixing it in c++ please show the working code please.
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 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
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill