У меня проблемы с получением правильного вывода для моего задания.
МОИ КОДЫ:
The Book.h
#ifndef BOOK_H
#define BOOK_H
namespace sict {
#define MAX_NAME_SIZE 16
#define MAX_TITLE_SIZE 32
#define MIN_ISBN_VALUE 1000000000000
#define MAX_ISBN_VALUE 9999999999999
class Book {
char m_authorfamilyname[MAX_NAME_SIZE];
char m_authorgivenname[MAX_NAME_SIZE];
char m_title[MAX_TITLE_SIZE];
unsigned long long m_ISBN;
public:
void set(const char authorfamilyname[], const char authorgivenname[], const char title[], unsigned long long ISBN );
void display() const;
bool isEmpty() const;
};
}
#endif
Book.cpp
#define _CRT_SECURE_NO_WARNINGS
#include "Book.h
#include <iostream>
#include <cstring>
using namespace std;
namespace sict {
void Book::set(const char authorfamilyname[], const char authorgivenname[], const char title[], unsigned long long ISBN)
m_authorfamilyname[0] = '\0';
m_authorgivenname[0] = '\0';
m_title[0] = '\0';
m_ISBN = 0;
strcpy(m_authorfamilyname, authorfamilyname);
strcpy(m_authorgivenname, authorgivenname);
strcpy(m_title, title);
m_ISBN = ISBN;
}
void Book::display() const {
if (isEmpty() && m_authorfamilyname[0] != '\0' && m_authorgivenname[0] != '\0' && m_title[0] != '\0' &&
m_ISBN >= MIN_ISBN_VALUE && m_ISBN <= MAX_ISBN_VALUE) {
cout << "Author: " << m_authorgivenname << ", " << m_authorfamilyname << endl;
cout << "Title: " << m_title << endl;
cout << "ISBN-13: " << m_ISBN << endl;
}
else {
cout << "The book object is empty!" << endl;
}
}
bool Book::isEmpty() const {
bool Empty;
Empty = true;
return Empty;
И основной исходный файл из моей школы
#include <iostream>
#include "Book.h"
#include "Book.h"
using namespace std;
using namespace sict;
int main()
{
cout << "Book Management App" << endl;
cout << "===================" << endl;
Book aBook;
cout << "Testing that validation and display are correct:" << endl;
cout << "------------------------------------------------" << endl;
aBook.set("Frank", "Herbert", "Dune", 91780441172719LL);
aBook.display();
cout << "The Book::isEmpty() should return true --> "
<< (aBook.isEmpty() ? "correct" : "incorrect") << endl;
aBook.set("Frank", "Herbert", "Dune", 980441172719LL);
aBook.display();
cout << "The Book::isEmpty() should return true --> "
<< (aBook.isEmpty() ? "correct" : "incorrect") << endl;
aBook.set("Frank", "Herbert", "Dune", 9780441172719LL);
aBook.display();
cout << "The Book::isEmpty() should return false --> "
<< (aBook.isEmpty() ? "incorrect" : "correct") << endl;
return 0;
}
ВЫХОД:
The book object is empty!
The Book::isEmpty() should return true --> correct
The book object is empty!
The Book::isEmpty() should return true --> correct
Author: Herbert, Frank
Title: Dune
ISBN-13: 9780441172719
The Book::isEmpty() should return false --> *incorrect*<= the problem
Последняя строкавывод должен быть «правильным», а не «неправильным».
Есть ли способ отделить последнюю строку, чтобы она была «правильной»?
Я пытался, если еще, и это не такработа.