Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. The parity of a number is whether it is even or odd. Consider performing arit

ID: 3849322 • Letter: 1

Question

1. The parity of a number is whether it is even or odd. Consider performing arithmetic on numbers where only the parity of the resultis important. For the class definition pragma once include using namespace std; class Parity bool is Even Stores whether the number is even or not public: Default constructor initializes the parity as false Parity(); Parity (bool even); Accepts whether the number is even or not bool get Parity(); Returns whether the number is even or not Parity operator (Parity RHS); Returns a Parity instance with the parity of LHS RHS Parity operator (int RHS); Returns a Parity instance with the parity of LHS RHS Parity operator (Parity RHS Returns a Parity instance with the parity of LHS RHS Parity operator (int RHS Returns a Parity instance with the parity of LHS RHS ostream operator

Explanation / Answer

Answer for Question:

C++ Source code for Parity Class with function implantations

#include<iostream>
using namespace std;

class Parity
{
   bool isEven;
public:
   Parity();
   Parity(bool even);
   bool getParity();
   Parity operator+(Parity RHS);
   Parity operator+(int RHS);
   Parity operator*(Parity RHS);
   Parity operator*(int RHS);
   friend ostream operator<<(ostream LHS, Parity RHS);
};

Parity::Parity()
{
   isEven = false;
}

Parity::Parity(bool even)
{
   isEven = even;
}

bool Parity::getParity()
{
   return isEven;
}

Parity Parity::operator+(Parity RHS)
{
   Parity temp;
   temp.isEven = isEven+RHS.isEven;
   return temp;
}

Parity Parity::operator+(int RHS)
{
   Parity temp;
   temp.isEven + =RHS;
   return temp;
}

Parity Parity::operator*(Parity RHS)
{
   Parity temp;
   temp.isEven = isEven*RHS.isEven;
   return temp;
}

Parity Parity::operator*(int RHS)
{
   Parity temp;
   temp.isEven = isEven*RHS;
   return temp;
}

ostream operator<<(ostream LHS, Parity RHS)
{
   LHS<<RHS.isEven;
}


int main()
{
   Parity val1(true),val2(false);
   cout<<(val1+4); //*3 + val2*7;
   return 0;
}


C++ Code for Person and Child class

#include<iostream>
using namespace std;

class Person
{
   string firstName,lastName;
public:
   Person();
   Person(string first,string last);
   string getLastName();
   void marries(Person husbend);
   void display();  
};

Person::Person()
{
   firstName = NULL;
   lastName = NULL;
}

Person::Person(string first,string last)
{
   strcpy(firstName,first);
   strcpy(lastName,last);
}

string Person::getLastName()
{
   return lastName;
}

void Person::display()
{
   cout<<firstName<<endl;
   cout<<lastName<<endl;
}

class Child:public Person
{
public:
   Child();
   Child(string first,Person father);
};

Child::Child(string first,Person father):Person(first,father)
{
}


C++ code for Point class with main method

#include<iostream>
using namespace std;

int main()
{
   Point p1(3,2);
// Object Pointers with dynamic allocation
Point * ptrP3, * ptrP4; // Declare two Point pointers
ptrP3 = new Point(); // Dynamically allocate storage via new
// with default constructor
                         
                       // Array of Objects - Static Memory Allocation
Point ptsArray1[2]; // Array of Point objects
// Use default constructor for all elements of the array
ptsArray1[0].display(); // Point @ (0,0)
cout << endl;
ptsArray1[1].setVals(11, 11);
(ptsArray1 + 1)->display(); // Point @ (11,11)
// same as ptsArray1[1].print()
cout << endl;

//Point ptsArray2[3] = {Point(21, 21), Point(22, 22), Point()};
return 0;

}