Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do i fix this line: Appointment a1(dd, tt, nn); of code in main below so i don't receive this error: /tmp/ccCH7Ffz.o: In function `main':

How do i fix this line: Appointment a1(dd, tt, nn);

of code in main below so i don't receive this error:

/tmp/ccCH7Ffz.o: In function `main': hw5-pr2.cpp:(.text+0x378): undefined reference to `Chrono::Appointment::Appointment(Chrono::Date, Chrono::Time, std::__cxx11::basic_string, std::allocator >)' collect2: error: ld returned 1 exit status

Below is main, chrono.cpp and chrono.h

I am trying to create an appointment with a user defined date time and name but the compiler wont let me.

----------------------------------------------------------------------------main---------------------------------------------------------------------------

int main() { vectorDatebook; /*string fileName; string line; cout<<"Please name a file to store Datebook into: "; cin>>fileName; ofstream file; file.open(fileName); if(file.is_open()) { while(getline(file,line)) { cout<>d>>m>>y; cout<>d>>m>>y; cout<>choice; while(choice != "1" || choice != "1" ||choice != "3"){ //Loop until user inputs a valid choice if(choice == "1"){ //User chose 1, default constructor is called with d1 Date d1; cout<>choice; } }*/ //--------------------------------------------------------------Time Code----------------------------------------------------------------------------- int h, min, s, a; //hour, minute, second and ampm ints cout<<" Please enter an hour (0-23), a minute (0-59), a second (0-59) and a value for AM (1) or PM (2): "; cin>>h>>min>>s>>a; cout<>h>>min>>s>>a; cout<>nn; cout<

...}

-----------------------------------------------------------------------------chrono.cpp-----------------------------------------------------------

#include "Chrono.h"

namespace Chrono {

// member function definitions:

//------------------------------------------------------------------------------

Date::Date(int yy, Month mm, int dd) : y(yy), m(mm), d(dd) { if (!is_date(yy,mm,dd)) throw Invalid(); }

Date::Date(Month mm, int dd, int yy) //New date member function with : y(yy), m(mm), d(dd) //switched parameters { if (!is_date(yy,mm,dd)) throw Invalid(); }

//------------------------------------------------------------------------------

const Date& default_date() { static const Date dd(2001,Date::jan,1); // start of 21st century return dd; }

//------------------------------------------------------------------------------

Date::Date() :y(default_date().year()), m(default_date().month()), d(default_date().day()) { }

Time::Time(int hh, int mm, int ss) //Time member function for 24-hour format : h(hh), m(mm), s(ss) { if(!is_time(hh,mm,ss)) throw Invalid(); }

Time::Time(int hh, int mm, int ss, AmPm aa) //Time member function for 12-hour format : h(hh), m(mm), s(ss), a(aa) { if(!is_time(hh,mm,ss,aa)) throw Invalid(); }

const Time& default_time() //default time { static const Time tt(0,0,0,Time::AM); return tt; }

Time::Time() //define default time :h(default_time().hour()), m(default_time().minute()), s(default_time().second()), a(default_time().ampm())

Appointment::Appointment(Date dd, Time tt, string nn) : d(dd), t(tt), n(nn) { //if(!is_appointment(dd,tt,nn)) throw Invalid(); }

...}

--------------------------------------------------------------------chrono.h---------------------------------------------------------------

#include

using namespace std;

//------------------------------------------------------------------------------

namespace Chrono {

//------------------------------------------------------------------------------

class Date { public: enum Month { jan=1, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec };

class Invalid { }; // to throw as exception

Date(int y, Month m, int d); // check for valid date and initialize Date(Month mm, int dd, int yy); //ADDED CONSTRUCTOR Date(); // default constructor // the default copy operations are fine // non-modifying operations: int day() const { return d; } Month month() const { return m; } int year() const { return y; } // modifying operations: void add_day(int n); void add_month(int n); void add_year(int n); private: int y; Month m; int d; };

class Time { public: enum AmPm { AM=1, PM }; class Invalid { }; Time(int h, int m, int s); //constructor for 24 hour format Time(int h, int m, int s, AmPm a); //constructor for 12 hour formant Time(); //default constructor int hour() const { return h; } //non-modifying operations int minute()const { return m; } int second() const { return s; } AmPm ampm() const { return a; } private: int h; int m; int s; AmPm a; };

class Appointment { public: class Invalid { }; Appointment(Date d, Time t, string n); Appointment(); Date date() const { return d; } Time time() const { return t; } string name() const { return n; }

Date d; Time t; string n;

};

//------------------------------------------------------------------------------

bool is_date(int y, Date::Month m, int d); // true for valid date bool is_time(int h, int m, int s, Time::AmPm a); // true for valid time bool is_time(int h, int m, int s); Time correct_ampm(Time tt); // Turns 24 hour format into 12 hour format with appropriate am or pm

//------------------------------------------------------------------------------

bool leapyear(int y); // true if y is a leap year

//------------------------------------------------------------------------------

bool operator==(const Date& a, const Date& b); bool operator!=(const Date& a, const Date& b); bool operator==(const Time& a, const Time& b); //overloads == operator to compare times bool operator!=(const Time& a, const Time& b); //overloads != operator to compare times

//------------------------------------------------------------------------------ ostream& operator<<(ostream& os, const Time& t); //overloads << to print times ostream& operator<<(ostream& os, const Date& d); ostream& operator<<(ostream& os, const Appointment& a); istream& operator>>(istream& is, Date& dd);

//------------------------------------------------------------------------------

} // Chrono

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

Recommended Textbook for

Introduction To Database And Knowledge Base Systems

Authors: S Krishna

1st Edition

9810206208, 978-9810206208

More Books

Students also viewed these Databases questions