Question

In: Computer Science

// File name: Person.h // Person class declaration. Person is the base class. #pragma once #include...

// File name: Person.h

// Person class declaration. Person is the base class.

#pragma once

#include <iostream>

using namespace std;

class Person {

private:

        string fName;

        string lName;

        int birthYear;

        int birthMonth;

        int birthDay;

public:

        Person();

        void setName(string, string);

        void setBirthDate(int, int, int);

        string getFullName();

        string getBirthDate();

};

// File name: Person.cpp
// Person class definition. Person is the base class.
#include "Person.h"
Person::Person() {
        fName = "";
        lName = "";
        birthYear = 0;
        birthMonth = 0;
        birthDay = 0;
}
void Person::setName(string first, string last) {
        fName = first;
        lName = last;
}
void Person::setBirthDate(int year, int month, int day) {
        birthYear = year;
        birthMonth = month;
        birthDay = day;
}
string Person::getFullName() {
        return fName + lName;
}
 
// This method creates a string with the birth date 
// using the following format: month/day/year
// where month and day are 2-digit values
// and year is a 4-digit value
string Person::getBirthDate() {
        // define the method
}

// File name: Student.h

// Student class declaration. Student inherits from Person

#pragma once

// make sure to indicate the inheritance

class Student {

private:

        string idNumber;

        string major;

        static string masterIdNumber;

public:

        Student();

        Student(string, string);

        Student(string, string, string);

        void setMajor(string);

        void printStudent();

};

// File name: Student.cpp
// Student class definition. Student inherits from Person
#include "Student.h"
string Student::masterIdNumber = "20200000";
 
// the defaul constrcuctor initializes major to the empty string
// It adds 1 to the masterIdNumber, and assigns the resulting value 
// to idNumber
Student::Student() {
 
}
 
// This constructor takes the first and last names of the student as parameters
// and invokes the parent class' methods to store the values
// It adds 1 to the masterIdNumber, and assigns the resulting value 
// to idNumber
Student::Student(string, string) {
 
}
 
// This constructor receives the student's first name, last name, and major as parameters
// and invokes the parent class' methods to store the values
// It adds 1 to the masterIdNumber, and assigns the resulting value 
// to idNumber
Student::Student(string, string, string) {
 
}
 
// This methods receives a string as parameter
// and assigns the value to the major field
void Student::setMajor(string) {
 
}
 
// This method will print the students information ín a table-like manner
// The format to be printed is: 
// ID Number Name Major Date of Birth
// Make sure to allow enough space for each column
void Student::printStudent() {
 
}
// File name: chapter10.cpp
// Follow the instructions to implement the class
 
int main() {
        // declare a student, named s1, using the default constructor
 
        // asign the name Vilma Picapiedra, date of birth May 10, 1998, and major Computer Science
 
        // declare a student, named s2, using Betty Marmol as parameters
 
        // asign date of birth June 11, 1999, and major Computer Engineering
 
        // declare a student, named s3, using Pablo Marmol and Electrical Engineering as parameters
 
        // assign date of birth December 9, 1990
 
        // delcare a stydent, named s4, using any of the constructors
        // this student has the following information:
        // Name: Pedro Picapiedra, date of birth January 10, 1995, major Computer Engineering
 
        // print a table with all students
        // the table headers are: Student ID, Name, Major, Date of Birth
 
        system("pause");
        return 0;
}

Solutions

Expert Solution

//C++ Code

/*========Person.h================*/
#pragma once
#include <iostream>
#include<iomanip>
using namespace std;

class Person {

private:

string fName;

string lName;

int birthYear;

int birthMonth;

int birthDay;

public:

Person();

void setName(string, string);

void setBirthDate(int, int, int);

string getFullName();

string getBirthDate();

};

// File name: Person.cpp
// Person class definition. Person is the base class.
#include "Person.h"
#include <sstream>
Person::Person() {
fName = "";
lName = "";
birthYear = 0;
birthMonth = 0;
birthDay = 0;
}
void Person::setName(string first, string last) {
fName = first;
lName = last;
}
void Person::setBirthDate(int year, int month, int day) {
birthYear = year;
birthMonth = month;
birthDay = day;
}
string Person::getFullName() {
return fName +" "+ lName;
}


// This method creates a string with the birth date
// using the following format: month/day/year
// where month and day are 2-digit values
// and year is a 4-digit value
string Person::getBirthDate() {
// define the method
ostringstream s1;
s1 << setw(2) << setfill('0') << birthMonth << "/" << setw(2) << setfill('0') << birthDay << "/" << setw(4) << setfill('0') << birthYear;
return s1.str();
}

// File name: Student.h

// Student class declaration. Student inherits from Person

#pragma once
#include"Person.h"
// make sure to indicate the inheritance

class Student :public Person{

private:

string idNumber;

string major;

static long int masterIdNumber;

public:

Student();

Student(string, string);

Student(string, string, string);

void setMajor(string);

void printStudent();

};

// File name: Student.cpp
// Student class definition. Student inherits from Person
#include "Student.h"
#include<string>
long int Student::masterIdNumber = 20200000;


// the defaul constrcuctor initializes major to the empty string
// It adds 1 to the masterIdNumber, and assigns the resulting value
// to idNumber
Student::Student() :Person(){
   major = "";
   masterIdNumber += 1;
   idNumber = to_string(masterIdNumber);

}


// This constructor takes the first and last names of the student as parameters
// and invokes the parent class' methods to store the values
// It adds 1 to the masterIdNumber, and assigns the resulting value
// to idNumber
Student::Student(string first, string last) {
   Person::setName(first, last);
   masterIdNumber +=1;
   idNumber = to_string(masterIdNumber);

}


// This constructor receives the student's first name, last name, and major as parameters
// and invokes the parent class' methods to store the values
// It adds 1 to the masterIdNumber, and assigns the resulting value
// to idNumber
Student::Student(string first, string last , string m) {
   Person::setName(first, last);
   major = m;
   masterIdNumber += 1;
   idNumber = to_string(masterIdNumber);

}


// This methods receives a string as parameter
// and assigns the value to the major field
void Student::setMajor(string m) {
   major = m;

}


// This method will print the students information ín a table-like manner
// The format to be printed is:
// ID Number Name Major Date of Birth
// Make sure to allow enough space for each column
void Student::printStudent() {
   cout << left << setw(10) << idNumber<<left<<setw(20)<<getFullName() << left << setw(30) << major << right << setw(10) << getBirthDate()
       << endl;

}

// File name: chapter10.cpp
// Follow the instructions to implement the class


#include"Student.h"
int main() {
// declare a student, named s1, using the default constructor
Student s1;

// asign the name Vilma Picapiedra, date of birth May 10, 1998, and major Computer Science
s1.setName("Vilma", "Picapiedra");
s1.setBirthDate(1998,5,10);
s1.setMajor("Computer Science");
// declare a student, named s2, using Betty Marmol as parameters
Student s2("Betty", "Marmol");

// asign date of birth June 11, 1999, and major Computer Engineering
s2.setBirthDate(1999,6,11);
s2.setMajor("Computer Engineering");
// declare a student, named s3, using Pablo Marmol and Electrical Engineering as parameters
Student s3("Pablo", "Marmol", "Electrical Engineering");

// assign date of birth December 9, 1990
s3.setBirthDate(1990,12,9);

// delcare a stydent, named s4, using any of the constructors
Student s4;
// this student has the following information:
// Name: Pedro Picapiedra, date of birth January 10, 1995, major Computer Engineering
s4.setName("Pedro", "Picapiedra");
s4.setBirthDate( 1995,1,10);
s4.setMajor("Computer Engineering");

// print a table with all students
// the table headers are: Student ID, Name, Major, Date of Birth
//header
cout << left << setw(15) << "ID Number" << left << setw(25) << "Name"
<< left << setw(20) << "Major" << right << setw(10) << "Birth Date"
<< endl;
cout << "=======================================================================" << endl;
s1.printStudent();
s2.printStudent();
s3.printStudent();
s4.printStudent();

system("pause");
return 0;
}

//Output

//If you need any help regarding this solution...... please,.... leave a comment..... thanks


Related Solutions

Tower of Hanoi problem please use this code #pragma once #include #include #include #include using namespace...
Tower of Hanoi problem please use this code #pragma once #include #include #include #include using namespace std; class TowersOfHanoi { friend ostream& operator<<(ostream& sink, const TowersOfHanoi& towers); public: //constructor TowersOfHanoi(); //custom methods unsigned move(unsigned new_n_disks = 6, ostream& new_sink = cout); private: //custom methods void move_aux(ostream& sink, unsigned n_disks, unsigned srce, unsigned dest, unsigned aux); //temporary variable unsigned _n_moves; //data const unsigned _n_towers; stack* _tower; }; #include "TowersOfHanoi.h" // ostream& operator<<(ostream& sink, const TowersOfHanoi& hanoi) { for (unsigned index =...
Tower of Hanoi problem complete the problems please use this code #pragma once #include <iostream> #include...
Tower of Hanoi problem complete the problems please use this code #pragma once #include <iostream> #include <stack> #include <string> #include <vector> using namespace std; class TowersOfHanoi { friend ostream& operator<<(ostream& sink, const TowersOfHanoi& towers); public: //constructor TowersOfHanoi(); //custom methods unsigned move(unsigned new_n_disks = 6, ostream& new_sink = cout); private: //custom methods void move_aux(ostream& sink, unsigned n_disks, unsigned srce, unsigned dest, unsigned aux); //temporary variable unsigned _n_moves; //data const unsigned _n_towers; stack<unsigned>* _tower; }; #include "TowersOfHanoi.h" // ostream& operator<<(ostream& sink, const...
Create a Namespaces.h header file containing a namespace declaration yourname. The declaration should include: a method...
Create a Namespaces.h header file containing a namespace declaration yourname. The declaration should include: a method with the signature void message (string, ostream &) that prints a string to the output stream. a method with the signature void message (double, ostream &) that prints a double to the output stream. Create a testNamespaces.cpp that uses the yourname namespace, and invokes the message() string method with a message of your choice and cout as input parameters, and invokes the message double...
Consider the following incomplete declaration of a Name class for 2a-2c. public class Name something missing...
Consider the following incomplete declaration of a Name class for 2a-2c. public class Name something missing {    private String first;    private String last;    public Name(String firstName, String lastName)    {       first = firstName;      last = lastName;    }    //additional methods } 2a) In the first two parts, you will modify the Name class so that it implements the Comparable interface. Show here what should go in place of something missing in the first line...
public class Person { private String name; public Person() { name = "No name yet"; }...
public class Person { private String name; public Person() { name = "No name yet"; } public Person(String initialName) { name = initialName; } public void setName(String newName) { name = newName; } public String getName() { return name; } public void writeOutput() { System.out.println("Name: " + name); } public boolean hasSameName(Person otherPerson) { return this.name.equalsIgnoreCase(otherPerson.name); } } 2- Write a Program Patient. Java Class that extends Person to include  Social security Gender  Appropriate construtors, accessors, and mutators....
Consider the following class: class Person {         String name;         int age;        ...
Consider the following class: class Person {         String name;         int age;         Person(String name, int age){                this.name = name;                this.age = age;         } } Write a java program with two classes “Teacher” and “Student” that inherit the above class “Person”. Each class has three components: extra variable, constructor, and a method to print the student or the teacher info. The output may look like the following (Hint: you may need to use “super”...
create class diagram of the following case. Case: Once a month, the person in charge of...
create class diagram of the following case. Case: Once a month, the person in charge of the human resources area of ​​the organization prepares the payroll to be paid. Once the calculation is made, the manager accesses and authorizes the payment of the information generated for payment, which is updated in the database to be sent to the Bank. The person in charge of the payroll, in turn, is in charge of making the entry and / or withdrawal of...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
In C++ Define a base class called Person. The class should have two data members to...
In C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and...
This class should include .cpp file, .h file and driver.cpp (using the language c++)! Overview of...
This class should include .cpp file, .h file and driver.cpp (using the language c++)! Overview of complex Class The complex class presents the complex number X+Yi, where X and Y are real numbers and i^2 is -1. Typically, X is called a real part and Y is an imaginary part of the complex number. For instance, complex(4.0, 3.0) means 4.0+3.0i. The complex class you will design should have the following features. Constructor Only one constructor with default value for Real...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT