c++ - How do I get variables from a class and put it into another class, and put it into a constructor? -


i'm having bit of problem here. have assignment in class made 3 header files(.h files) , 3 .cpp files. assignments person date , time.

i display them see.

person.h

#include <iostream> using  namespace std; #ifndef person #define person  class person { private:     string firstname;     string lastname; public:     person();     person(string,string);     void displayperson(); }; #endif 

person.cpp

#include <iostream> #include "person.h" using namespace std;  person::person() { firstname=" "; lastname=" "; } person::person(string fn, string ln) { firstname=fn; lastname=ln; } void person::displayperson() { cout<<firstname<<", "<<lastname; } 

date.h

#include <iostream> using namespace std;  #ifndef date #define date class date { private:     string month;     string day;     string year; public:     date();     date(string,string,string);     void displaydate(); }; #endif // date 

date.cpp

#include <iostream> #include "date.h" using namespace std;  date::date() {     month="01";     day="01";     year="2013"; } date::date(string m,string d, string y) {     month=m;     day=d;     year=y; } void date::displaydate() {     cout<<month<<"/"<<day<<"/"<<year; } 

time.h

#include <iostream> using namespace std;  #ifndef time #define time class time { private:     static const int maxmin=59;     static const int minmin=0;     static const int maxhour=24;     static const int minhour=0;     int militaryhours;     int militaryminutes;     int standardhours;     int standardminutes;     string ampm; public:     time(int);     time(int,int);     void displaytime();     void displaytime1(); }; #endif // time 

time.cpp

#include <iostream> #include "time.h" using namespace std;  time::time(int mh) {     string zero="0";     militaryhours=mh;  if (militaryhours>maxhour || militaryhours<minhour) {     militaryhours=maxhour;     standardhours=12; } else if(militaryhours>12 && militaryhours<maxhour) {     standardhours=militaryhours-12;     ampm="p.m."; } else if(militaryhours<12 && militaryhours>=minhour) {     standardhours=militaryhours;     ampm="a.m."; }  cout<<"military time: "<<militaryhours<<":"<<zero<<zero<<" "<<ampm; cout<<"\nstandard time: "<<standardhours<<":"<<zero<<zero<<" "<<ampm; }  time::time(int mh,int mm) {      string zero="0";      militaryhours=mh;      militaryminutes=mm;  if (militaryhours>maxhour || militaryhours<minhour) {     militaryhours=maxhour;     standardhours=12; } else if(militaryhours>12 && militaryhours<=maxhour) {     standardhours=militaryhours-12;     ampm="p.m."; } else if(militaryhours<12 && militaryhours>=minhour) {     standardhours=militaryhours;     ampm="a.m."; } if(militaryminutes>maxmin && militaryminutes<minmin) {     militaryminutes=maxmin; } else if(militaryminutes<maxmin && militaryminutes>minmin) {     standardminutes=0;     standardminutes=militaryminutes; } if(militaryminutes<10 && militaryminutes>=minmin) {     standardminutes=0;     standardminutes=militaryminutes;     cout<<"military time: "<< militaryhours<<":"<<zero<<standardminutes<<" "     <<ampm;     cout<<"\nstandard time: "<<standardhours<<":"<<zero<<standardminutes<<"     "<<ampm; } else {     cout<<"military time: "<< militaryhours<<":"<<standardminutes<<" "<<ampm;     cout<<"\nstandard time: "<<standardhours<<":"<<standardminutes<<" "<<ampm; } } 

ok person first name , last name of person date date...month day year time ask user time , output military , standard time.

now our teacher wants make fourth class... named dentalappointment.

this assignment says

"create class named dentalappointment. include fields patient data(using existing person class), date(using existing class), time(using existing time class), , duration of appointment in minutes. also, include field contains ending time appointment - field calculated based on start time , duration using time class function adds minutes time object. dentalappointment constructor requires first , last name, month,day, , year, , hour , minute appointment. allow dentalapppointment constructed or without , additional argument duration , force duration 30 minutes when no argument supplied. constructor should not allow appointment on 240 minutes. constructor calculate appointment ending time base on start time , duration. create display function dentalappointment class. write main() function loops @ least 3 times prompting user dentalappointment data , displaying information. use initialization list constructor."

ok here confused.

so have pass values person,date, time dentalappointment.

so first made dentalappointment class.

dentalappointment.h

#include <iostream> #include "person.h" #include "date.h" #include "time.h" using  namespace std;  class dentalappointment { private:  public:  }; 

i dont know put in private , public parts. do?

#include <iostream> #include "person.h" #include "date.h" #include "time.h" using  namespace std;  class dentalappointment { private:     person pfirstname;     person plastname;     date appointmentmonth;     date appointmentday;     date appointmentyear;     time appointmenthour;     time appointmentminutes;     int duration; public:     dentalappointment();     dentalappointment(person,person,date,date,date,time,time);     dentalappointment(person,person,date,date,date,time,time,int);     void showdentalappointment(); }; 

if put in cpp file? should this???

#include <iostream> #include "person.h" #include "time.h" #include "date.h" #include "dentalappointment.h" using namespace std;  dentalappointment::dentalappointment() {     pfirstname=person.firstname;     plastname=person.lastname;     appointmentmonth=date.month;     appointmentday=date.day;     appointmentyear=date.year;     appointmenthour=time.standardhours;     appointmentminutes=time.standardminutes; } dentalappointment::dentalappointment(person fn,person ln ,date month,date day,date year,time h,time m) {     pfirstname=fn;     plastname=ln;     appointmentmonth=month;     appointmentday=day;     appointmentyear=y;     appointmenthour=h;     appointmentminutes=m; }  dentalappointment::dentalappointment(person fn,person ln ,date month,date      day,date year,time hours,time minutes,int d)  {     pfirstname=fn;     plastname=ln;     appointmentmonth=month;     appointmentday=day;     appointmentyear=year;     appointmenthour=hours;     appointmentminutes=minutes;     duration=d; } 

please tell me if way off, or if im close. because calling private , public variables different classes , putting them different classes confusing me. , putting them in constructors killen me.... please me!!! thank you!!!

i did did "c:\users\ibrahim munaser\documents\c++\dentalappointment\dentalappointment.cpp|9|error: no matching function call 'time::time()'|".... dont know means... im gonna send h , cpp file , see if find anything

date.h

#include <iostream> #include "person.h" #include "date.h" #include "time.h" using  namespace std;  class dentalappointment {     private:     person pfirstname;     person plastname;     date appointmentmonth;     date appointmentday;     date appointmentyear;     time appointmenthour;     time appointmentminutes;     int duration; public:     dentalappointment(person,person,date,date,date,time,time);     dentalappointment(person,person,date,date,date,time,time,int);     void showdentalappointment(); }; 

date.cpp

#include <iostream> #include "person.h" #include "time.h" #include "date.h" #include "dentalappointment.h" using namespace std;   dentalappointment::dentalappointment(person fn,person ln ,date month,date day,date year,time h,time m) {     pfirstname=fn;     plastname=ln;     appointmentmonth=month;     appointmentday=day;     appointmentyear=y;     appointmenthour=h;     appointmentminutes=m; } dentalappointment::dentalappointment(person fn,person ln ,date month,date day,date year,time hours,time minutes,int d) {     pfirstname=fn;     plastname=ln;     appointmentmonth=month;     appointmentday=day;     appointmentyear=year;     appointmenthour=hours;     appointmentminutes=minutes;     duration=d; } 

you want build dentalappointment person, date , time directly. more like:

class dentalappointment {     person person_;     date date_;     time time_; public:     dentalappointment(const person& p, const date& d , const time& t) : person_(p), date_(d), time_(t) {}     // other stuff } 

edit: simplify constructor, start with:

dentalappointment(person p, date d , time t) {      person_ = p;      date_ = d;      time_ = t; } 

this takes objects of person, date , time , assigns them data members. learn more c++ end @ given constructor above. here's place start.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -