Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exception thrown: read access violation. this was nullptr. Person.h #pragma once #define PERSON_H #include using namespace std; class Person { private: string name; int age;

Exception thrown: read access violation. this was nullptr.

Person.h

#pragma once #define PERSON_H #include

using namespace std;

class Person { private: string name; int age; double weight;

public: Person(string, int, double); Person(); void setName(string); void setAge(int); void setWeight(double); string getName(); int getAge(); double getWeight(); };

Person.cpp

#include "Person.h" #include

Person::Person(string x, int y, double z) { this->name = x; this->age = y; this->weight = z; } Person::Person() { this->name = ""; this->age = 0; this->weight = 0.0; }

void Person::setName(string nameOne) { this->name = nameOne; }

void Person::setAge(int ageOne) { this->age = ageOne; }

void Person::setWeight(double weightOne) { this->weight = weightOne; }

string Person::getName() { return this->name; } int Person::getAge() { return this->age; }

double Person::getWeight() { return this->weight; }

#include #include "Person.h" #include #include

using namespace std;

class PersonData { private: Person tempPerson; Person* personList; int capacity, size;

public: PersonData(Person x) { this->tempPerson = x; this->size = 0; } ~PersonData() { delete[] personList; personList = nullptr; } void resizeArray() { capacity++;

Person* tempArray = new Person[capacity];

for (int counter = 0; counter < this->capacity; counter++) {

tempArray[counter] = this->personList[counter];

}

delete[] this->personList;

this->personList = tempArray; } void addPerson() { this->capacity = 1;

if (this->capacity <= this->size) { resizeArray(); }

this->personList[size] = this->tempPerson;

this->size += 1; }

void listPersons() {

if (size > 0) { for (int i = 0; i < size; i++) {

cout << "Name: " << personList[i].getName() << endl; cout << "Age: " << personList[i].getAge() << endl; cout << "Weight: " << personList[i].getWeight() << endl << endl;

cout << "Capacity of the array: " << capacity << endl; cout << "Records in the array: " << size << endl;

} } else { cout << "Capacity of the array: " << capacity << endl; cout << "Records in the array: " << size << endl; } }

};

int main() { Person personOne("John", 22, 140.6); PersonData person1(personOne); person1.addPerson();

person1.listPersons();

Person personTwo("Mike", 55, 147.6); }

Where is the nullptr, and how can I fix the issue.

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

More Books

Students also viewed these Databases questions

Question

Estimate f (2.1) if f (2) = 1 and f(2) = 3.

Answered: 1 week ago

Question

3. What are potential solutions?

Answered: 1 week ago