Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8470829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:37:43+00:00 2026-06-10T16:37:43+00:00

I’m doing a homework and I’m trying to follow a class diagram. In Book.cpp

  • 0

I’m doing a homework and I’m trying to follow a class diagram. In Book.cpp file wherever the commented text it will cause error saying: Unhandled exception at 0x00CE3F1B in Lab 1.exe: 0xC0000005: Access violation reading location 0xCCCCCD1C.

In following code I don’t know what I should be doing with pointers, I don’t know how I should pass this objects variables into this constructor or what I should be doing with it. I’m so confused with c++. I attached class diagram at the end of this post.

Book::Book(string title, Author *pAuthor, Publisher *pPublisher, double price)
{
    setTitle(title);
    setPrice(price);
}

Book.cpp file:

#include <iostream>
#include <sstream>
using namespace std;

#include "Book.h"

Book::Book()
{
}

Book::Book(string title, Author *pAuthor, Publisher *pPublisher, double price)
{
    setTitle(title);
    setPrice(price);
}

void Book::setTitle(string  title)
{
    this->title = title;
}

void Book::setAuthorName(string first, string last)
{
    //pAuthor->setFirstName(first);
    //pAuthor->setLastName(last);
}

void Book::setPublisher(string name, string address, string city)
{
    //pPublisher->setName(name);
    //pPublisher->setAddress(address);
    //pPublisher->setCity(city);
}

void Book::setPrice(double price)
{
    this->price = price;
}

string Book::convertDoubleToString(double number)
{
    return static_cast<ostringstream*>( &(ostringstream() << number) ) -> str();
}

string Book::getBookInfo()
{
    return "0"; //title + "\n" + pAuthor->getFullName() + "\n" + pPublisher->getPublisherInfo() + "\n" + "$" + convertDoubleToString(price);
}

Book.h file

#include "Publisher.h"
#include "Author.h"

class Book
{
    public:
        Book();
        Book(string title, Author *pAuthor, Publisher *pPublisher, double price);
        ~Book();
        void setTitle(string title);
        void setAuthorName(string first, string last);
        void setPublisher(string name, string address, string city);
        void setPrice(double price);
        string convertDoubleToString(double number);
        string getBookInfo();

    private:
        string title;
        double price;
        Author *pAuthor;
        Publisher *pPublisher;
};

This is what I have in main.cpp

#include <iostream>
#include <string>
using namespace std;

#include "Book.h"

int main()
{
    system("cls");

    cout << "Book 1" << endl;

    Author *pAuthor = new Author("John", "Doe");
    Publisher *pPublisher = new Publisher("Wrox", "10475 Crosspoint Blvd.", "Indianapolis");
    Book *pBook = new Book("Memory Management", pAuthor, pPublisher, 39.99);

    cout << pBook->getBookInfo() << endl;

    cout << endl << "Book 2" << endl;

    Book book;

    book.setTitle("Advanced C++ Programming");
    book.setAuthorName("Linda", "Smith");
    book.setPublisher("Microsoft Press", "One Microsoft Way", "Redmond");
    book.setPrice(49.99);

    cout << book.getBookInfo() << endl << endl;

    system("pause");

    return 0;
};

Author.cpp

#include <iostream>
#include <string>
using namespace std;

#include "Author.h"

Author::Author()
{
}

Author::Author(string first, string last)
{
    setFirstName(first);
    setLastName(last);
}

string Author::getFullName()
{
    return firstName + " " + lastName;
}

void Author::setFirstName(string first)
{
    this->firstName = first;
}

void Author::setLastName(string last)
{
    this->lastName = last;
}

Publisher.cpp

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

#include "Publisher.h"

Publisher::Publisher()
{
}

Publisher::Publisher(string name, string address, string city)
{
    setName(name);
    setAddress(address);
    setCity(city);
}

string Publisher::getPublisherInfo()
{
    return string(name + "\n" + address + "\n" + city);
}

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

void Publisher::setAddress(string address)
{
    this->address =  address;
}

void Publisher::setCity(string city)
{
    this->city = city;
}

Class Diagram because I’m so lost. I believe I did the structure right and some of passing variables is good. But I just don’t know how to do it with pointers.

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:37:44+00:00Added an answer on June 10, 2026 at 4:37 pm

    It looks like your class object has two pointers, one to the publisher and another to the author that are never been initialized. When you try to call the member functions on those objects you are causing undefined behavior and in particular your application crashes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.