Question
In C++ Some code to use: /* * Structure holds as mentioned in the question. * First name, last name, gender * Setting all marital
In C++
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started