Design a personType class with the following attributes (variables), and behaviors (methods/functions).
Private
Public
Create a driver program that creates 5 different people. After creating the 5 different people, neatly print them.
For this assignment, you will be dynamically creating an array of personType's from our previous assignments. For now, this will only be able to deal with the base class and not any derived classes.
1. Prompt the user for the number of people to create, then create an array of personTypes to hold them.
2. Loop through the array, prompting the user to enter the data as necessary using the corresponding setters.
3. Finally, loop through the array again and call the print method for each person.
4. Deallocate the array and quit.
Run your program for 5 people. Upload the .cpp, .h files along with a screenshot. Ensure to fill out all the data for each person.
am i able to upload my cpp files that i already have for the previous assignment?
Please find the code below:
I have created 3 files, header file for class, .cpp file for the implemetation and driver (main.cpp) file
I have mentioned all the details in the comments.
personType.h
#ifndef _PERSON_TYPE
#define _PERSON_TPE
#include<string>
using namespace std;
//define class
class personType{
//public members of the class
public:
personType();
void setFname(string fname);
void setLname(string lname);
void setAddress(string address);
void setHeight(double value);
void setDOB(string dob);
void setGender(char g);
string getFname();
string getLname();
string getAddress();
double getHeight();
string getDOB();
char getGender();
void print();
bool equals(personType p);
//private members of the class
private:
string fName;
string lName;
string address;
double height;
string DOB;
char gender;
};
#endif
personType.cpp
//include header file
#include "personType.h"
#include<iostream>
#include<string>
using namespace std;
//default constructor
personType::personType(){
fName = "";
}
//set methods for all variables
void personType::setFname(string name){
fName = name;
}
void personType::setLname(string name){
lName = name;
}
void personType::setAddress(string value){
address = value;
}
void personType::setHeight(double value){
height = value;
}
void personType::setDOB(string dob){
DOB = dob;
}
void personType::setGender(char g){
gender = g;
}
//getter methods for all variables
string personType::getFname(){
return fName;
}
string personType::getLname(){
return lName;
}
string personType::getAddress(){
return address;
}
double personType::getHeight(){
return height;
}
string personType::getDOB(){
return DOB;
}
char personType::getGender(){
return gender;
}
//print method
void personType::print(){
cout<<"First Name:"<<fName<<endl;
cout<<"Last Name :"<<lName<<endl;
cout<<"Address :"<<address<<endl;
cout<<"Height :"<<height<<endl;
cout<<"DOB :"<<DOB<<endl;
cout<<"Gender :"<<gender<<endl<<endl;
}
//equals to check equality between objects
bool personType::equals(personType p){
if((fName==p.fName) && (lName==p.lName) &&
(address==p.address) && (height==p.height) &&
(DOB==p.DOB) && (gender==p.gender)){
return true;
}
return false;
}
main.cpp
#include<iostream>
#include "personType.cpp"
using namespace std;
int main(){
//get the number from the user
int n;
cout<<"Enter Number of people to be created: ";
cin>>n;
//dynamically create array of size n
personType **arr;
arr = (personType**)malloc(n*sizeof(personType*));
//variables
int i;
string val;
double h;
char c;
//loop to ask values from user
for(i=0;i<n;i++){
arr[i]= new personType();
cout<<"Please Enter First Name for person
"<<(i+1)<<" :";
cin>>val;
arr[i]->setFname(val);
cout<<"Please Enter Last Name for person
"<<(i+1)<<" :";
cin>>val;
arr[i]->setLname(val);
cout<<"Please Enter Address for person
"<<(i+1)<<" :";
cin>>val;
arr[i]->setAddress(val);
cout<<"Please Enter Height for person
"<<(i+1)<<" :";
cin>>h;
arr[i]->setHeight(h);
cout<<"Please Enter DOB for person "<<(i+1)<<"
:";
cin>>val;
arr[i]->setDOB(val);
cout<<"Please Enter Gender for person
"<<(i+1)<<" :";
cin>>c;
arr[i]->setGender(c);
}
//loop to print values
for(i=0;i<n;i++){
arr[i]->print();
}
//loop to deallocate array
for (int i=0; i<n; i++)
free (arr[i]);
//deallocate pointer of the array
free (arr);
return 0;
}
Output:

Design a personType class with the following attributes (variables), and behaviors (methods/functions). Private Variables string fName;...
c++ only Design a class representing an Employee. The employee would have at least these private fields (Variables): name: string (char array) ID: string (char array) salary: float Type: string (char array) All the variables except for the salary should have their respective setters and getters, and the class should have two constructors, one is the default constructor and the other constructor initializes the name,ID and type of employee with valid user input. The class should have the following additional...
This lab will exercise your understanding of some of the concepts covered in Chapter 12: virtual functions (think about compile-time and run-time binding) 1. We will be treating the PersonType object as a base class that may be inherited by multiple objects. We will treat the personType getAddress and setAddress as pure virtual because we wish to have all inherited objects to code these functions but do not need them in the base class. Using the code for person type...
C++ There is a class called Person which has name and age as private variables. Another class called Student, which is derived from person with gpa and id as variables. name is a string, age and id are integers and gpa is a double... All of them are private variables. age, gpa and id should be generated randomly when the object is created with the following ranges: age 20 to 32 gpa 0.0 to 4.0 // this one is tricky...
FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that...
Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...
Create the class Book which has the following members: 1. private members: 1. title as String 2. isbn as String 3. author as String 4. price as double 2. public members: 1. default constructor which initializes all data members to their default values. 2. non-default constructor which initializes all data members to parameters values. 3. toString which returns a representing String of the Book. 4. add all the setters and getters. Create the class EBook which is a subclass of...
I need some help with programming this assignment.
Programming Assignment 6: A Python Class, Attributes, Methods, and Objects Obiectives .Be able to write a Python class Be able to define class attributes Be able to define class methods .Be able to process input from a text file .Be able to write an application using objects The goal of this programming assignment is to develop a simple image processing application. The application will import a class that creates image objects with...
in C++, please help. Not only do we need to create an ADT but create a main file as well to implement everything. For this program you will be creating a stack ADT to allow the client program to pick up treasures for a Star Wars scavenger game to get everyone ready for the opening of Galaxy’s Edge in 2020. Each treasure should have a (a) name, (b) description, (c) category, (d) what it is used for, and (e)if this...
Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...
Need help please!.. C++ programDesign a bank account class named Account that has the following private member variables: accountNumber of type int ownerName of type string balance of type double transactionHistory of type pointer to Transaction structure (structure is defined below) numberTransactions of type int totalNetDeposits of type static double.The totalNetDeposits is the cumulative sum of all deposits (at account creation and at deposits) minus the cumulative sum of all withdrawals. numberAccounts of type static intand the following public member...