malloc: *** error for object 0x10ee008c0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Abort trap: 6
Or I get it when I try to print everything
Segmentation fault: 11
I'm doing my homework for the OOP class, and now I'm stuck in a good hour. I get this error as soon as I used the keyboard enough. I am not the one who is upset at all, and here I am very upset by this. Here are the files:
This is a class book. I am sure it is very respectable. But for reference only:
//--------------- BOOK.CPP --------------- // The class definition for Book. // #include <iostream> #include "book.h" using namespace std; Book::Book() // { strcpy(title, " "); strcpy(author, " "); type = FICTION; price = 0; } void Book::Set(const char* t, const char* a, Genre g, double p) { strcpy(title, t); strcpy(author, a); type = g; price = p; } const char* Book::GetTitle() const { return title; } const char* Book::GetAuthor() const { return author; } double Book::GetPrice() const { return price; } Genre Book::GetGenre() const { return type; } void Book::Display() const { int i; cout << GetTitle(); for (i = strlen(title) + 1; i < 32; i++) cout << (' '); cout << GetAuthor(); for (i = strlen(author) + 1; i < 22; i++) cout << (' '); switch (GetGenre()) { case FICTION: cout << "Fiction "; break; case MYSTERY: cout << "Mystery "; break; case SCIFI: cout << "SciFi "; break; case COMPUTER: cout << "Computer "; break; } cout << "$"; if (GetPrice() < 1000) cout << " "; if (GetPrice() < 100) cout << " "; if (GetPrice() < 10) cout << " "; /* printf("%.2f", GetPrice());*/ cout << '\n'; }
This is a storage class that deals with array and dynamic allocation. This worked well without input commands, but just using its functions, it worked like a champion.
//--------------- STORE.CPP --------------- // The class definition for Store. //
Now this is the guy who needs some work. Some things may be empty, so ignore this. It controls all the input that I consider.
#include <iostream>
Please, any help you can offer is awesome. Thanks.
jordaninternets
source share