Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ I'm getting a runtime error for some reason can you locate the problem and solve it Note:After you've compiled the file once, you'll need

C++

I'm getting a runtime error for some reason can you locate the problem and solve it

image text in transcribed

Note:After you've compiled the file once, you'll need to rename it. Change test122.bin to something else, for example. You must do this because the first time you tried to compile the code, it crashed.

I'm getting the output (above) that I want to see but it crashes afterwards which is a huge problem I need you to locate the problem and solve it for the code below:

#include #include #include using namespace std;

struct Person { int dateOfBirth {0}; string firstName; string lastName; string phoneNumber; }; class BinaryData { private: int dateOfBirth {0}; string firstName; string lastName; string phoneNumber; public: //ctor BinaryData () { this->dateOfBirth = getDateOfBirth(); this->firstName = getFirst(); this->lastName = getLast(); this->phoneNumber = getPhone(); } //destruct ~BinaryData () {} int getDateOfBirth(){ int dateOfBirth2 {0}; cout >dateOfBirth2; return dateOfBirth2; } string getFirst(){ string strFirst2; cout >strFirst2; return strFirst2; } string getLast(){ string strLast2; cout >strLast2; return strLast2; } string getPhone(){ string strPhone2; cout > strPhone2; return strPhone2; } void Save(ofstream &of){ of.write((char*)&dateOfBirth, sizeof(dateOfBirth)); of.write((char*)&firstName, sizeof(firstName)); of.write((char*)&lastName, sizeof(lastName)); of.write((char*)&phoneNumber, sizeof(phoneNumber)); } void WriteBinaryFile(string strFile){ ofstream fs; fs.open(strFile, ios::out | ios ::binary | ios::app); if(!fs){ cerr Save(fs); } fs.close(); } void ReadBinaryFile(string strFile) { ifstream binaryFile; //opening the file normally binaryFile.open(strFile, ios::in | ios ::binary); if(binaryFile.is_open()) { Person p; //going to the end binaryFile.seekg(0, ios::end); //getting the size of the file streampos size = binaryFile.tellg(); //going back to the begining binaryFile.seekg(0, ios::beg); while (binaryFile.tellg()

int main() { BinaryData *bd = new BinaryData;

bd->WriteBinaryFile("test122.bin"); bd->ReadBinaryFile("test122.bin"); delete bd; bd=nullptr; }

Date of birth: 1485 First name: Jake Last Name:Drave Phone number:456-784-45 Date of birth: 1485 First name: Jake Last name: Drave : Phone number: 456-784-45

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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions