Question

In: Computer Science

Here I'm using "person" as an abstract superclass or parent class, and "Student" as a derived/child...

Here I'm using "person" as an abstract superclass or parent class, and "Student" as a derived/child class.

// File name: Person.h
// Person is the base, or parent for chapter11
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Person {
private:
   string fName;
   string lName;
   int areaCode;
   int phone;
public:
   Person();
   Person(string, string);
   void setFirst(string);
   void setLast(string);
   void setPhoneNumber(int, int);
   string getFirstlast();
   string getLastFirst();
   string getPhoneNumber();
};
// Student is the child, or specialization, for class chapter11
#pragma once
#include "Person.h"
class Student : public Person {
private:
   int idNumber;
   string major;
   static int baseForID;
public:
   Student();
   Student(string, string);
   void setMajor(string);
   void printStudent();
};
// File name: Student.cpp
// Student is the child, or specialization, class for chapter11
#include "Student.h"
// initialize the static classs variable to 20200000
// The default constructor initializes all strings to "" (the empty string),
// and sets the id number for the student. The id number for a student is the
// value of the static class variable. Once assigned, the value of the static
// class variable must be incremented by 1
Student::Student()
{
  
}

// The parametrized constructor invokes the parent class' methods to assign
// values to first name and last name.The id number for a student is the
// value of the static class variable. Once assigned, the value of the static
// class variable must be incremented by 1
Student::Student(string, string)
{
}

// set the value of major to that of the parameter
void Student::setMajor(string)
{
}

// prints the student information in the following format
// ID# idnumber lastName, firstName major
void Student::printStudent()
{
}
// Person is the base, or parent, class for chapter11
#include "Student.h"
int main() {
   // create a new student object, student1, using the default constructor

   // assign the following values using the methods for the class
   // first name: Pedro last name: Picapiedra phone: 787-555-5555,
   // major: Computer Science

   // print the information for student1

   // create a new student object, student2, using the parametrized constructor
   // use the following values as arguments:
   // firt name: Pablo last name: Marmol

   // assign the following values using the methods for the class
   // phone: 787-787-8787,
   // major: Electrical Engineering

   // print the information for student2

   // create a new student object, student3, using the parametrized constructor
   // use the following values as arguments:
   // firt name: Senor last name: Rajuela

   // assign the following values using the methods for the class
   // phone: 787-755-5000,
   // major: Computer Engineering

   // print the information for student3

   system("pause");
   return 0;

// File name: Person.cpp
// Person is the base, or parent, class for chapter11
#include "Person.h"
// The default constructor initializes all strings to "" (the empty string),
// and all integers to 0
Person::Person()
{
}
// The parametrized constructor initializes all strings to the values in the parameters,
// and all integers to 0
Person::Person(string, string)
{
}
// Assigns the value of the parameter to fName; NO COUT's!
void Person::setFirst(string)
{
}
// Assigns the value of the parameter to lName; NO COUT's!
void Person::setLast(string)
{
}
// Assigns the values of the parameter to areaCode and phone; NO COUT's!
// must verifiy that the area code value has only 3 digits, and the
// phone number has only 7 digits
void Person::setPhoneNumber(int, int)
{
}
// returns a string in the format firstName lastName
string Person::getFirstlast()
{
   return string();
}
// returns a string in the format lastName, firstName
string Person::getLastFirst()
{
   return string();
}

// returns a string with the phone number
// the phone number should be in the following format
// (area code) xxx-xxxx
string Person::getPhoneNumber()
{
   return string();
}
}

Solutions

Expert Solution

SOURCE CODE

//Person.h

// File name: Person.h

// Person is the base, or parent for chapter11

#pragma once

#include <iostream>

#include <string>

using namespace std;

class Person {

private:

   string fName;

   string lName;

   int areaCode;

   int phone;

public:

   Person();

   Person(string, string);

   void setFirst(string);

   void setLast(string);

   void setPhoneNumber(int, int);

   string getFirstlast();

   string getLastFirst();

   string getPhoneNumber();

};

//Person.cpp

// File name: Person.cpp

// Person is the base, or parent, class for chapter11

#include "Person.h"

// The default constructor initializes all strings to "" (the empty string),

// and all integers to 0

Person::Person()

{

    fName = "";

    lName = "";

    areaCode = 0;

    phone = 0;

}

// The parametrized constructor initializes all strings to the values in the parameters,

// and all integers to 0

Person::Person(string fname, string lname)

{

    fName = fname;

    lName = lname;

    areaCode = 0;

    phone = 0;

}

// Assigns the value of the parameter to fName; NO COUT's!

void Person::setFirst(string s)

{

    fName = s;

}

// Assigns the value of the parameter to lName; NO COUT's!

void Person::setLast(string s)

{

    lName = s;

}

// Assigns the values of the parameter to areaCode and phone; NO COUT's!

// must verifiy that the area code value has only 3 digits, and the

// phone number has only 7 digits

void Person::setPhoneNumber(int areacode, int phno)

{

    if(areacode / 1000 != 0)

        return;

    if(phno / 10000000 != 0)

        return;

    

    areaCode = areacode;

    phone = phno;

}

// returns a string in the format firstName lastName

string Person::getFirstlast()

{

   return string(fName + lName);

}

// returns a string in the format lastName, firstName

string Person::getLastFirst()

{

   return string(lName + ", " + fName);

}

// returns a string with the phone number

// the phone number should be in the following format

// (area code) xxx-xxxx

string Person::getPhoneNumber()

{

   string str = "(";

   str += to_string(areaCode);

   str += ") ";

   str += to_string(phone/10000);

   str += "-";

   str += to_string(phone%10000);

   return str;

}

//Student.h

// Student is the child, or specialization, for class chapter11

#pragma once

#include "Person.h"

class Student : public Person {

private:

   int idNumber;

   string major;

   static int baseForID;

public:

   Student();

   Student(string, string);

   void setMajor(string);

   void printStudent();

};

//Student.cpp

// File name: Student.cpp

// Student is the child, or specialization, class for chapter11

#include "Student.h"

// initialize the static classs variable to 20200000

int Student::baseForID = 20200000;

// The default constructor initializes all strings to "" (the empty string),

// and sets the id number for the student. The id number for a student is the

// value of the static class variable. Once assigned, the value of the static

// class variable must be incremented by 1

Student::Student()

{

    major = "";

    idNumber = baseForID;

    baseForID++;

}

// The parametrized constructor invokes the parent class' methods to assign

// values to first name and last name.The id number for a student is the

// value of the static class variable. Once assigned, the value of the static

// class variable must be incremented by 1

Student::Student(string fname, string lname) : Person(fname, lname)

{

    idNumber = baseForID;

    baseForID++;

}

// set the value of major to that of the parameter

void Student::setMajor(string s)

{

    major = s;

}

// prints the student information in the following format

// ID# idnumber lastName, firstName major

void Student::printStudent()

{

    cout << "ID# " << idNumber << " " << getLastFirst() << " " << major << endl;

}

//main.cpp

#include "Student.h"

int main() {

   // create a new student object, student1, using the default constructor

   Student student1;

   // assign the following values using the methods for the class

   // first name: Pedro last name: Picapiedra phone: 787-555-5555,

   // major: Computer Science

   student1.setFirst("Pedro");

   student1.setLast("Picapiedra");

   student1.setPhoneNumber(787, 5555555);

   student1.setMajor("Computer Science");

   // print the information for student1

   student1.printStudent();

   // create a new student object, student2, using the parametrized constructor

   // use the following values as arguments:

   // firt name: Pablo last name: Marmol

   Student student2("Pablo", "Marmol");

   // assign the following values using the methods for the class

   // phone: 787-787-8787,

   // major: Electrical Engineering

   student2.setPhoneNumber(787, 7878787);

   student2.setMajor("Electrical Engineering");

   // print the information for student2

   student2.printStudent();

   // create a new student object, student3, using the parametrized constructor

   // use the following values as arguments:

   // firt name: Senor last name: Rajuela

   Student student3("Senor", "Rajuela");

   // assign the following values using the methods for the class

   // phone: 787-755-5000,

   // major: Computer Engineering

   student3.setPhoneNumber(787, 7555000);

   student3.setMajor("Computer Engineering");

   // print the information for student3

   student3.printStudent();

   system("pause");

   return 0;

}

OUTPUT


Related Solutions

C++ Code Vehicle Class The vehicle class is the parent class of a derived class: locomotive....
C++ Code Vehicle Class The vehicle class is the parent class of a derived class: locomotive. Their inheritance will be public inheritance so reflect that appropriately in their .h files. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +setName(s:string):void +getName():string +getMap():char** +getSize():int +setMap(s: string):void +getMapAt(x:int, y:int):char +~vehicle() +operator−−():void +determineRouteStatistics()=0:void The class variables are as follows: • map: A 2D array of chars, it will represent the...
C++ Code Vehicle Class The vehicle class is the parent class of the derived class: dieselLocomotive....
C++ Code Vehicle Class The vehicle class is the parent class of the derived class: dieselLocomotive. Their inheritance will be public inheritance so reect that appropriately in their .h les. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +getSize():int +setName(s:string):void +getName():string +getMap():char** +setMap(s: string):void +getMapAt(x:int, y:int):char +~vehicle() +operator--():void +determineRouteStatistics()=0:void The class variables are as follows: map: A 2D array of chars, it will represent the map...
CS Using the following UML outline, create the following abstract parent class along with the 4...
CS Using the following UML outline, create the following abstract parent class along with the 4 subclasses and Driver class. Implement the Classes, listed attributes and methods along with any additional things that you may need. Add a driver class that utilizes the methods/attributes in the classes to output the following based on the vehicle type (therefore, you must create an instance for all 4 subclasses in your driver): 1. Vehicle Type (i.e., Car, Airplane, etc.) 2. Transportation method (wheels,...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent...
Implement the Shape hierarchy -- create an abstract class called Shape, which will be the parent class to TwoDimensionalShape and ThreeDimensionalShape. The classes Circle, Square, and Triangle should inherit from TwoDimensionalShape, while Sphere, Cube, and Tetrahedron should inherit from ThreeDimensionalShape. Each TwoDimensionalShape should have the methods getArea() and getPerimeter(), which calculate the area and perimeter of the shape, respectively. Every ThreeDimensionalShape should have the methods getArea() and getVolume(), which respectively calculate the surface area and volume of the shape. Every...
C++ Code Required to Show The constructor of parent class executes before child class
C++ Code Required to Show The constructor of parent class executes before child class
Design You will need to have at least four classes: a parent class, a child class,...
Design You will need to have at least four classes: a parent class, a child class, a component class, and an unrelated class. The component object can be included as a field in any of the other three classes. Think about what each of the classes will represent. What added or modified methods will the child class have? What added fields will the child class have? Where does the component belong? How will the unrelated class interact with the others?...
Using Classes This problem relates to the pre-loaded class Person. Using the Person class, write a...
Using Classes This problem relates to the pre-loaded class Person. Using the Person class, write a function print_friend_info(person) which accepts a single argument, of type Person, and: prints out their name prints out their age if the person has any friends, prints 'Friends with {name}' Write a function create_fry() which returns a Person instance representing Fry. Fry is 25 and his full name is 'Philip J. Fry' Write a function make_friends(person_one, person_two) which sets each argument as the friend of...
Here is a C++ class definition for an abstract data type LinkedList of string objects. Implement...
Here is a C++ class definition for an abstract data type LinkedList of string objects. Implement each member function in the class below. Some of the functions we may have already done in the lecture, that's fine, try to do those first without looking at your notes. You may add whatever private data members or private member functions you want to this class. #include #include typedef std::string ItemType; struct Node { ItemType value; Node *next; }; class LinkedList { private:...
IN JAVA: Write a parent class, Device, which implements ageneric computer device.Create two child...
IN JAVA: Write a parent class, Device, which implements a generic computer device.Create two child classes, Disk and Printer, which specialize a Device with added functionality.Device Task:We are only interested in three things for the time being: the name of the device, an ID number identifying the device, and a flag indicating whether or not it is enabled. Thus, three fields are necessary, a String for the name, a int for the ID, and a boolean for the enabled status.Any...
Refactor the following classes so they are both derived from a base class called Person. Write...
Refactor the following classes so they are both derived from a base class called Person. Write the code for the new base class as well. Try to avoid repeating code as much as possible. Write the classes so that any common methods can be invoked through a pointer or reference to the base class. #include <string> #include <cmath> using namespace std; class Student { private: string name;    int age;    int studyYear; public:    Student(string,int,int); void study();    void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT