Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When I run my program it prints this How do I make the program print out just this output? |Anne|Niebuhr|Febraury 15, 1996| 5.7 feet|104.9 lbs|

When I run my program it prints this image text in transcribed

How do I make the program print out just this output?

|Anne|Niebuhr|Febraury 15, 1996| 5.7 feet|104.9 lbs|

--my code--

--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 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 CIST2362::Person data(firstName,lastName,birthDay,birthMonth,birthYear,height,weight); personDatabase.push_back(data);

std::cin >> answer; }

// output the person objects for(int i=0;i

Date.cpp

#include "Date.h" #include "DateException.h" #include

namespace CIST2362 {

Date::Date() {

setNames(); setDay(0); setMonth(0); setYear(1900);

} Date::Date(int m, int d, int y) {

setNames(); setDay(d); setMonth(m); setYear(y); } void Date::setNames() { names[1] = "January"; names[2] = "Febraury"; names[3] = "March"; names[4] = "April"; names[5] = "May"; names[6] = "June"; names[7] = "July"; names[8] = "August"; names[9] = "September"; names[10] = "October"; names[11] = "November"; names[12] = "December"; } void Date::setMonth(int m) {

try{

if(m12 ){

InvalidMonth w; throw w; }else{

month=m; }

} catch(std::exception& e) { std::cout

try{

if(d 31 ){ // throws char InvalidDay w; throw w; }else{

day=d; }

}

catch(std::exception& e) { std::cout

void Date::setYear(int y) { try{

if(y

year=y; }

} catch(std::exception& e) { std::cout

dd

std::string s=mm.str()+"/"+dd.str()+"/"+yy.str(); return s; }

std::string Date::getDateLong() {

std::stringstream dd, mm, yy; //gets dd, mm, yy

dd

return s; }

}

Date.h picture to save space

image text in transcribed

DateException.cpp

#include "DateException.h"

namespace CIST2362 { const char * InvalidDay::what() const throw(){ return"Invalid Day assigned - must be 1 to 31 ";

}

const char * InvalidMonth::what() const throw(){

return "Invalid Month assigned - must be 1 to 12 "; }

const char * InvalidYear::what() const throw(){

return "Invalid Year assigned - must be a positive number "; }

}

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: const char * what() const throw(); };

class InvalidMonth: public std::exception { public:

const char * what() const throw() ; };

class InvalidYear: public std::exception { public: const char * what() const throw(); };

}

Person.cpp

#endif

#include #include

#include "Person.h" #include "PersonExceptions.h"

namespace CIST2362 { const std::string &Person::getFirstName() const { return firstName; }

void Person::setFirstName(const std::string &firstName) { this->firstName = firstName; }

const std::string &Person::getLastName() const { return lastName; }

void Person::setLastName(const std::string &lastName) { this->lastName = lastName; }

const Date &Person::getBirthdate() const { return this->birthdate; }

void Person::setBirthdate(const Date &birthdate) { this->birthdate=birthdate; }

float Person::getHeight() const { return this->height; }

void Person::setHeight(float height) { try{ if(height

badHeight w; throw w;

} else{ this->height = height;

}

} catch(std::exception& e){ std::cout

float Person::getWeight() const { return this->weight; }

void Person::setWeight(float weight) {

try{ if(weight

badWeight w; throw w;

} else{ this->weight = weight;

}

} catch(std::exception& e){ std::cout

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) { this->setFirstName(firstName); this->setLastName(lastName); this->setHeight(height); this->setWeight(weight); this->birthdate.setDay(birthday); this->birthdate.setMonth(birthmonth); this->birthdate.setYear(birthyear); }

std::string Person::toString() {

std::stringstream hh,ww; hh

std::string s="|"+firstName+"|"+lastName+"|"+birthdate.getDateLong()+"|"+hh.str()+" feet|"+ww.str()+" lbs| "; return s;

} }

Person.h picture to save space

image text in transcribed

PersonExceptions.h picture to save space

image text in transcribed

PersonExceptions.cpp

#include "PersonExceptions.h"

namespace CIST2362 {

const char * badHeight::what() const throw() {

return "Invalid Height assigned - must be a positive number "; }

const char * badWeight::what() const throw(){ return "Invalid Weight assigned - must be a positive number "; }

}

Anne Niebuhr 2151996104.95.7n Invalid Month assigned - must be 1 to 12 |Anne|Niebuhr |Febraury 15,19965.7 feet|104.9 Ibs| Iffdef LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H define LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H tinclude tinclude lamespace CIST2362 \{ // Constants const int NUM_MONTHS = 13; class Date \{ private: int month; int day; int year; // An array of strings to hold // the names of the months std: :string names[NUM_MONTH]; // 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); I/ Functions to print the date std: :string getDateShort(); std::string getDateLong(); Iffdef LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H define LESSON_5_PROGRAMMING_ASSIGNMENT_DATE_H tinclude tinclude lamespace CIST2362 \{ // Constants const int NUM_MONTHS = 13; class Date \{ private: int month; int day; int year; // An array of strings to hold // the names of the months std: :string names[NUM_MONTH]; // 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); I/ Functions to print the date std: :string getDateShort(); std::string getDateLong()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions