Please implement the following problem in basic C++ code and include detailed comments so that I am able to understand the processes for the solution. Thanks in advance.
// personType.h
#include <string>
using namespace std; class personType { public: virtual void print() const; void setName(string first, string last); string getFirstName() const; string getLastName() const; personType(string first = "", string last = ""); protected: string firstName; string lastName; };
// personTypeImp.cpp
#include <iostream> #include <string> #include "personType.h" using namespace std; void personType::print() const { cout << firstName << " " << lastName; } void personType::setName(string first, string last) { firstName = first; lastName = last; } string personType::getFirstName() const { return firstName; } string personType::getLastName() const { return lastName; } //constructor personType::personType(string first, string last) { firstName = first; lastName = last; }
// main.cpp
#include "extPersonType.h" #include <iostream> int main() { extPersonType myPerson = extPersonType("John", "Denver", 3 , addressType(" 42 W Warren Ave", "Wayne", "MI", "48202")); myPerson.print(); system("pause"); }
Please be sure that the answer matches the shown sample output!
--------------------------------------------personType.h--------------------------------------------
#ifndef PERSON_TYPE
#define PERSON_TYPE
#include<iostream>
#include <cstring>
using namespace std;
// create namespace
namespace myPerson
{
class personType
{
public:
void print();
void setName(string first, string last);
string getFirstName() const;
string getLastName() const;
personType(string first = "", string last = "");
protected:
string firstName;
string lastName;
};
}
#endif
-----------------------------------------------personTypeImp.cpp--------------------------------------
#include "personType.h"
using namespace myPerson;
void personType::print()
{
cout << firstName << " " << lastName;
}
void personType::setName(string first, string last)
{
firstName = first;
lastName = last;
}
string personType::getFirstName() const
{
return firstName;
}
string personType::getLastName() const
{
return lastName;
}
//constructor
personType::personType(string first, string last)
{
firstName = first;
lastName = last;
}
-----------------------------------------------------------addressType.h--------------------------------------
#ifndef ADDRESS_TYPE
#define ADDRESS_TYPE
#include "personTypeImp.cpp"
namespace myAddressType
{
class addressType
{
string street_address;
string city;
string state;
string zip;
public:
addressType(string, string, string, string);
// getter methods
string getStreetAddress();
string getCity();
string getState();
string getZIP();
void printAddress();
// setter methods
void setStreetAddress(string);
void setCity(string);
void setState(string);
void setZIP(string);
};
}
#endif
-------------------------------------------------------addressType.cpp------------------------------------------------
#include "addressType.h"
using namespace myAddressType;
addressType::addressType(string street_address, string city, string state, string zip)
{
setStreetAddress(street_address);
setCity(city);
setState(state);
setZIP(zip);
}
// setter methods
void addressType::setStreetAddress(string street_address)
{
this->street_address = street_address;
}
void addressType::setCity(string city)
{
this->city = city;
}
void addressType::setState(string state)
{
this->state = state;
}
void addressType::setZIP(string zip)
{
this->zip = zip;
}
// getter methods
string addressType::getStreetAddress()
{
return this->street_address;
}
string addressType::getCity()
{
return this->city;
}
string addressType::getState()
{
return this->state;
}
string addressType::getZIP()
{
return this->zip;
}
void addressType::printAddress()
{
cout<<this->street_address<<", "<<this->city<<", "<<this->state<<" "<<this->zip<<" ";
}
--------------------------------------------------------extPersonType.h--------------------------------------------
#ifndef EXT_PERSON_TYPE
#define EXT_PERSON_TYPE
#include "addressType.cpp"
namespace myExtPersonType
{
class extPersonType : public personType
{
int relation;
addressType *ob;
public:
extPersonType(string firstname, string lastname, int relation, addressType add);
void printDetails();
};
}
#endif
------------------------------------------------------------extPersonType.cpp----------------------------------------------
#include "extPersonType.h"
using namespace myExtPersonType;
// constructor
extPersonType::extPersonType(string firstname, string lastname, int relation, addressType add)
{
// set the name of the person
setName(firstname, lastname);
this->relation = relation;
ob = new addressType(add.getStreetAddress(), add.getCity(), add.getState(), add.getZIP());
}
void extPersonType::printDetails()
{
print();
cout<<" is a ";
if(relation == 1)
cout<<"family member ";
else if(relation == 2)
cout<<"friend ";
else
cout<<"business associate ";
cout<<"who lives at ";
ob->printAddress();
cout<<endl;
//cout<<ob->getStreetAddress()<<", "<<ob->getCity()<<", "<<ob->getState()<<" "<<ob->getZIP()<<" ";
}
------------------------------------------main.cpp---------------------------------------------
#include "extPersonType.cpp"
#include <iostream>
int main()
{
extPersonType myPerson = extPersonType("John", "Denver", 3 , addressType(" 42 W Warren Ave", "Wayne", "MI", "48202"));
myPerson.printDetails();
system("pause");
}
Sample Output:
Please implement the following problem in basic C++ code and include detailed comments so that I...
In c++ redefine the class personType to take advantage of the new features of object-oriented design that you have learned, such as operator overloading, and then derive the class customerType. personType: #include <string> using namespace std; class personType { public: void print() const; //Function to output the first name and last name //in the form firstName lastName. void setName(string first, string last); //Function to set firstName and lastName according to the //parameters. //Postcondition: firstName = first; lastName = last...
A hard c++ problem ◎Write a c++ program”Student.h”include Private data member, string firstName; string lastName; double GPA(=(4.0*NumberOfAs+3.0*NumberOfBs+2.0*NumberOfCs+1.0*NumberOfDs)/( As+Bs+Cs+Ds+Fs)); Public data member, void setFirstName(string name); string getFirstName() const; void printFirstName() const; void getLastName(string name); string getLastName() const; void printLastName() const; void computeGPA(int NumberOfAs,int NumberOfBs,int NumberOfCs,int NumberOfDs,int NumberOfFs); double getGPA() const; double printGPA() const; A destructor and an explicit default constructor initializing GPA=0.0 and checking if GPA>=0.0 by try{}catch{}. Add member function, bool operator<(const Student); The comparison in this function based on...
"Function does not take 0 arguments". I keep getting this error for my last line of code: cout << "First Name: " << employee1.getfirstName() << endl; I do not understand why. I am trying to put the name "Mike" into the firstName string. Why is my constructor not working? In main it should be set to string firstName, string lastName, int salary. Yet nothing is being put into the string. #include<iostream> #include<string> using namespace std; class Employee { int...
C++ edit: You start with the code given and then modify it so that it does what the following asks for. Create an EmployeeException class whose constructor receives a String that consists of an employee’s ID and pay rate. Modify the Employee class so that it has two more fields, idNum and hourlyWage. The Employee constructor requires values for both fields. Upon construction, throw an EmployeeException if the hourlyWage is less than $6.00 or over $50.00. Write a program that...
The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...
C++ implement and use the methods for a class called Seller that represents information about a salesperson. The Seller class Use the following class definition: class Seller { public: Seller(); Seller( const char [], const char[], const char [], double ); void print(); void setFirstName( const char [] ); void setLastName( const char [] ); void setID( const char [] ); void setSalesTotal( double ); double getSalesTotal(); private: char firstName[20]; char lastName[30]; char ID[7]; double salesTotal; }; Data Members The...
Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...
This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...
using C++ language!! please help me out with this homework In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...
I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student { private String firstName; private String lastName; private String id; private boolean tuitionPaid; public Student(String firstName, String lastName, String id, boolean tuitionPaid) { this.firstName=firstName; this.lastName=lastName; this.id=id; this.tuitionPaid=tuitionPaid; } ...