Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Some code to use: /* * Structure holds as mentioned in the question. * First name, last name, gender * Setting all marital

In C++image text in transcribed

Some code to use:

/* * Structure holds as mentioned in the question. * First name, last name, gender * Setting all marital status to SINGLE initially. Converting string to char array using(char*) * Setting spouse name initially NULL to all people */ struct people{ char firstName[50]; char lastName[50]; int gender; char *marital_status = (char*)"SINGLE"; char *spouse = NULL; };

/* * Display method receives a pointer to People and size of the people structres. * Itreating. Printing first name, last name. * If marital status is SINGLE printing "is a single " else printing " is married to " * If spouse is null, then single male/female. Else married to the spouse name we set in the below code. */ void displayPeople(people* ppl, int dynCount){ cout > dynCount; //Dynamically allocating array of people people *ppl = new people[dynCount]; cout > ppl[i].firstName; cout> ppl[i].lastName; cout > ppl[i].gender; cout > isMarried; cout > spouseNumber; //Set the spouse names for the current person and selected person. //Setting spouse of tiffany as marquise ppl[spouseNumber].marital_status = (char*)"Married"; ppl[spouseNumber].spouse = ppl[i].firstName; //Setting the spouse of marquise as tiffany ppl[i].marital_status = (char*)"Married"; ppl[i].spouse = ppl[spouseNumber].firstName; } cout Objectives . Learn to create and use a class header file (.h) . Learn to create and use a class implementation file (.cpp) . Learn to include a header file in a separate main file . Learn how to create object from a class e Learn how to initialize object with constructors Learn how to access private attribute of an object by calling public member functions Instructions: 1. Write a Person class that has the following member variables . firstName: a string . lastName : a string . gender: a Gender enum status a Status enum spouse a pointer to a Person object 2. The class should have the following member functions: Default Constructor. A default constructor that sets gender to MALE, status to SINGLE, and spouse to NULL. This should also print to the screen "DEFAULT constructor called from a NAME-LESS person" Constructor. Accepts first name, last name, gender of the person and defaults status to SINGLE and spouse to NULL. This should also print to the screen "OVERLOADED constructor called from a Person object Destructor. A destructor that prints to the screen "DESTRUCTOR CALLED for Person object " e setFirstName. A mutator function for the firstName variable e setLastName. A mutator function for the lastName variable setGender. A mutator function for the gender variable setStatus. A mutator function for the status variable setSpouse. A mutator function for the spouse variable o if the person object is female she should take her husbands last name o Also the person's spo use object should point to the current instance of person . getFirstName. An accessor function for the firstName variable getLastName. An accessor function for the lastName variable. . getGender. An accessor function for the gender variable. getStatus. An accessor function for the status variable isMarried. A member function that returns true if a person is married false otherwise. toString. A member function that converts all of the private attributes into a string describing the person. o A single person with no name should display "NAME-LESS single " o A single person with a name should display " is a single" o A married person should display firstName> is married to spouse's firstName> 3. Write a program that demonstrates the Person class with the following program requirements 1. Statically create a Person object with one of the two constructors 2. Dynamically allocated a Person object with the other person constructor 3. You MUST show each state of your toString function o Note: a single person with no name, a single person with a name and a married person 4. Call each member function at least one time in your program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

More Books

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago